2 * ============LICENSE_START=======================================================
3 * ONAP Policy Engine - Common Modules
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.common.utils.properties.exception;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertThat;
26 import org.hamcrest.CoreMatchers;
29 * Superclass used to test subclasses of {@link PropertyException}.
31 public class BasicPropertyExceptionTester {
34 * The "message" that's passed each time an exception is constructed.
36 protected static final String MESSAGE = "some error";
39 * The "throwable" that's passed each time an exception is constructed.
41 protected static final Throwable THROWABLE = new Throwable();
44 * Name of the "property" to be passed each time an exception is constructed.
46 protected static final String PROPERTY = "myName";
49 * Name of the "property" field.
51 protected static final String FIELD = "PROPERTY";
54 * Methods to perform various tests on the except subclass.
57 protected void doTestPropertyExceptionStringField_AllPopulated(PropertyException ex) {
61 protected void doTestPropertyExceptionStringField_NullProperty(PropertyException ex) {
62 assertEquals(null, ex.getPropertyName());
63 assertEquals(FIELD, ex.getFieldName());
64 assertNotNull(ex.getMessage());
65 assertNotNull(ex.toString());
68 protected void doTestPropertyExceptionStringField_NullField(PropertyException ex) {
69 assertEquals(PROPERTY, ex.getPropertyName());
70 assertEquals(null, ex.getFieldName());
71 assertNotNull(ex.getMessage());
72 assertNotNull(ex.toString());
75 protected void doTestPropertyExceptionStringField_BothNull(PropertyException ex) {
76 assertEquals(null, ex.getPropertyName());
77 assertEquals(null, ex.getFieldName());
78 assertNotNull(ex.getMessage());
79 assertNotNull(ex.toString());
82 protected void doTestPropertyExceptionStringFieldString(PropertyException ex) {
84 standardMessageTests(ex);
87 protected void doTestPropertyExceptionStringFieldThrowable(PropertyException ex) {
89 standardThrowableTests(ex);
92 protected void doTestPropertyExceptionStringFieldStringThrowable(PropertyException ex) {
94 standardMessageTests(ex);
95 standardThrowableTests(ex);
99 * Performs standard tests that should apply to all subclasses.
101 * @param ex exception to test
103 protected void standardTests(PropertyException ex) {
104 assertEquals(PROPERTY, ex.getPropertyName());
105 assertEquals(FIELD, ex.getFieldName());
106 assertNotNull(ex.getMessage());
107 assertNotNull(ex.toString());
111 * Performs standard tests for exceptions that were provided a message in their
114 * @param ex exception to test
116 protected void standardMessageTests(PropertyException ex) {
117 assertThat(ex.getMessage(), CoreMatchers.endsWith(MESSAGE));
121 * Performs standard tests for exceptions that were provided a throwable in their
124 * @param ex exception to test
126 protected void standardThrowableTests(PropertyException ex) {
127 assertEquals(THROWABLE, ex.getCause());