Third part of onap rename
[appc.git] / appc-common / src / test / java / org / onap / appc / exceptions / APPCExceptionTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.exceptions;
26
27 import org.junit.Assert;
28 import org.junit.Test;
29 import org.powermock.reflect.Whitebox;
30
31
32 public class APPCExceptionTest {
33
34     @Test
35     public void testConstructorNoArgument() throws Exception {
36         APPCException appcException = new APPCException();
37         Assert.assertTrue(appcException.getCause() == null);
38         Assert.assertTrue(appcException.getLocalizedMessage() == null);
39         Assert.assertTrue(appcException.getMessage() == null);
40     }
41
42     @Test
43     public void testConstructorWithMessaqge() throws Exception {
44         String message = "testing message";
45         APPCException appcException = new APPCException(message);
46         Assert.assertTrue(appcException.getCause() == null);
47         Assert.assertEquals(message, appcException.getLocalizedMessage());
48         Assert.assertEquals(message, appcException.getMessage());
49     }
50
51     @Test
52     public void testConstructorWithThrowable() throws Exception {
53         String message = "testing message";
54         Throwable throwable = new Throwable(message);
55         APPCException appcException = new APPCException(throwable);
56         Assert.assertEquals(throwable, appcException.getCause());
57         Assert.assertTrue(appcException.getLocalizedMessage().contains(message));
58         Assert.assertTrue(appcException.getMessage().contains(message));
59     }
60
61     @Test
62     public void testConstructorWithMessageAndThrowable() throws Exception {
63         String message = "testing message";
64         String tMessage = "throwable message";
65         Throwable throwable = new Throwable(tMessage);
66         APPCException appcException = new APPCException(message, throwable);
67         Assert.assertEquals(throwable, appcException.getCause());
68         Assert.assertTrue(appcException.getLocalizedMessage().contains(message));
69         Assert.assertTrue(appcException.getMessage().contains(message));
70     }
71
72     @Test
73     public void testConstructorWithFourArguments() throws Exception {
74         String message = "testing message";
75         String tMessage = "throwable message";
76         Throwable throwable = new Throwable(tMessage);
77         APPCException appcException = new APPCException(message, throwable, true, true);
78         Assert.assertEquals(throwable, appcException.getCause());
79         Assert.assertTrue(appcException.getLocalizedMessage().contains(message));
80         Assert.assertTrue(appcException.getMessage().contains(message));
81
82         Assert.assertTrue(Whitebox.getInternalState(appcException, "stackTrace") != null);
83         Assert.assertTrue(Whitebox.getInternalState(appcException, "suppressedExceptions") != null);
84
85         appcException = new APPCException(message, throwable, false, false);
86         Assert.assertTrue(Whitebox.getInternalState(appcException, "stackTrace") == null);
87         Assert.assertTrue(Whitebox.getInternalState(appcException, "suppressedExceptions") == null);
88     }
89 }