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;
27 import org.hamcrest.CoreMatchers;
30 * Superclass used to test subclasses of {@link PropertyException}.
32 public class BasicPropertyExceptionTester {
35 * The "message" that's passed each time an exception is constructed.
37 protected static final String MESSAGE = "some error";
40 * The "throwable" that's passed each time an exception is constructed.
42 protected static final Throwable THROWABLE = new Throwable();
45 * Name of the "property" to be passed each time an exception is constructed.
47 protected static final String PROPERTY = "myName";
50 * Name of the "property" field.
52 protected static final String FIELD = "PROPERTY";
55 * Methods to perform various tests on the except subclass.
58 protected void doTestPropertyExceptionStringField_AllPopulated(PropertyException ex) {
62 protected void doTestPropertyExceptionStringField_NullProperty(PropertyException ex) {
63 assertEquals(null, ex.getPropertyName());
64 assertEquals(FIELD, ex.getFieldName());
65 assertNotNull(ex.getMessage());
66 assertNotNull(ex.toString());
69 protected void doTestPropertyExceptionStringField_NullField(PropertyException ex) {
70 assertEquals(PROPERTY, ex.getPropertyName());
71 assertEquals(null, ex.getFieldName());
72 assertNotNull(ex.getMessage());
73 assertNotNull(ex.toString());
76 protected void doTestPropertyExceptionStringField_BothNull(PropertyException ex) {
77 assertEquals(null, ex.getPropertyName());
78 assertEquals(null, ex.getFieldName());
79 assertNotNull(ex.getMessage());
80 assertNotNull(ex.toString());
83 protected void doTestPropertyExceptionStringFieldString(PropertyException ex) {
85 standardMessageTests(ex);
88 protected void doTestPropertyExceptionStringFieldThrowable(PropertyException ex) {
90 standardThrowableTests(ex);
93 protected void doTestPropertyExceptionStringFieldStringThrowable(PropertyException ex) {
95 standardMessageTests(ex);
96 standardThrowableTests(ex);
100 * Performs standard tests that should apply to all subclasses.
102 * @param ex exception to test
104 protected void standardTests(PropertyException ex) {
105 assertEquals(PROPERTY, ex.getPropertyName());
106 assertEquals(FIELD, ex.getFieldName());
107 assertNotNull(ex.getMessage());
108 assertNotNull(ex.toString());
112 * Performs standard tests for exceptions that were provided a message in their
115 * @param ex exception to test
117 protected void standardMessageTests(PropertyException ex) {
118 assertThat(ex.getMessage(), CoreMatchers.endsWith(MESSAGE));
122 * Performs standard tests for exceptions that were provided a throwable in their
125 * @param ex exception to test
127 protected void standardThrowableTests(PropertyException ex) {
128 assertEquals(THROWABLE, ex.getCause());