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.assertj.core.api.Assertions.assertThat;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
28 * Superclass used to test subclasses of {@link PropertyException}.
30 public class SupportBasicPropertyExceptionTester {
33 * The "message" that's passed each time an exception is constructed.
35 protected static final String MESSAGE = "some error";
38 * The "throwable" that's passed each time an exception is constructed.
40 protected static final Throwable THROWABLE = new Throwable();
43 * Name of the "property" to be passed each time an exception is constructed.
45 protected static final String PROPERTY = "myName";
48 * Name of the "property" field.
50 protected static final String FIELD = "PROPERTY";
53 * Methods to perform various tests on the except subclass.
56 protected void doTestPropertyExceptionStringField_AllPopulated(PropertyException ex) {
60 protected void doTestPropertyExceptionStringField_NullProperty(PropertyException ex) {
61 assertEquals(null, ex.getPropertyName());
62 assertEquals(FIELD, ex.getFieldName());
63 assertNotNull(ex.getMessage());
64 assertNotNull(ex.toString());
67 protected void doTestPropertyExceptionStringField_NullField(PropertyException ex) {
68 assertEquals(PROPERTY, ex.getPropertyName());
69 assertEquals(null, ex.getFieldName());
70 assertNotNull(ex.getMessage());
71 assertNotNull(ex.toString());
74 protected void doTestPropertyExceptionStringField_BothNull(PropertyException ex) {
75 assertEquals(null, ex.getPropertyName());
76 assertEquals(null, ex.getFieldName());
77 assertNotNull(ex.getMessage());
78 assertNotNull(ex.toString());
81 protected void doTestPropertyExceptionStringFieldString(PropertyException ex) {
83 standardMessageTests(ex);
86 protected void doTestPropertyExceptionStringFieldThrowable(PropertyException ex) {
88 standardThrowableTests(ex);
91 protected void doTestPropertyExceptionStringFieldStringThrowable(PropertyException ex) {
93 standardMessageTests(ex);
94 standardThrowableTests(ex);
98 * Performs standard tests that should apply to all subclasses.
100 * @param ex exception to test
102 protected void standardTests(PropertyException ex) {
103 assertEquals(PROPERTY, ex.getPropertyName());
104 assertEquals(FIELD, ex.getFieldName());
105 assertNotNull(ex.getMessage());
106 assertNotNull(ex.toString());
110 * Performs standard tests for exceptions that were provided a message in their
113 * @param ex exception to test
115 protected void standardMessageTests(PropertyException ex) {
116 assertThat(ex.getMessage()).endsWith(MESSAGE);
120 * Performs standard tests for exceptions that were provided a throwable in their
123 * @param ex exception to test
125 protected void standardThrowableTests(PropertyException ex) {
126 assertEquals(THROWABLE, ex.getCause());