Fix request handler class error
[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-2018 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  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.appc.exceptions;
25
26 import org.junit.Assert;
27 import org.junit.Test;
28 import org.powermock.reflect.Whitebox;
29
30
31 public class APPCExceptionTest {
32
33     @Test
34     public void testConstructorNoArgument() throws Exception {
35         APPCException appcException = new APPCException();
36         Assert.assertTrue(appcException.getCause() == null);
37         Assert.assertTrue(appcException.getLocalizedMessage() == null);
38         Assert.assertTrue(appcException.getMessage() == null);
39     }
40
41     @Test
42     public void testConstructorWithMessaqge() throws Exception {
43         String message = "testing message";
44         APPCException appcException = new APPCException(message);
45         Assert.assertTrue(appcException.getCause() == null);
46         Assert.assertEquals(message, appcException.getLocalizedMessage());
47         Assert.assertEquals(message, appcException.getMessage());
48     }
49
50     @Test
51     public void testConstructorWithThrowable() throws Exception {
52         String message = "testing message";
53         Throwable throwable = new Throwable(message);
54         APPCException appcException = new APPCException(throwable);
55         Assert.assertEquals(throwable, appcException.getCause());
56         Assert.assertTrue(appcException.getLocalizedMessage().contains(message));
57         Assert.assertTrue(appcException.getMessage().contains(message));
58     }
59
60     @Test
61     public void testConstructorWithMessageAndThrowable() throws Exception {
62         String message = "testing message";
63         String tMessage = "throwable message";
64         Throwable throwable = new Throwable(tMessage);
65         APPCException appcException = new APPCException(message, throwable);
66         Assert.assertEquals(throwable, appcException.getCause());
67         Assert.assertTrue(appcException.getLocalizedMessage().contains(message));
68         Assert.assertTrue(appcException.getMessage().contains(message));
69     }
70
71     @Test
72     public void testConstructorWithFourArguments() throws Exception {
73         String message = "testing message";
74         String tMessage = "throwable message";
75         Throwable throwable = new Throwable(tMessage);
76         APPCException appcException = new APPCException(message, throwable, true, true);
77         Assert.assertEquals(throwable, appcException.getCause());
78         Assert.assertTrue(appcException.getLocalizedMessage().contains(message));
79         Assert.assertTrue(appcException.getMessage().contains(message));
80
81         Assert.assertTrue(Whitebox.getInternalState(appcException, "stackTrace") != null);
82         Assert.assertTrue(Whitebox.getInternalState(appcException, "suppressedExceptions") != null);
83
84         appcException = new APPCException(message, throwable, false, false);
85         Assert.assertTrue(Whitebox.getInternalState(appcException, "stackTrace") == null);
86         Assert.assertTrue(Whitebox.getInternalState(appcException, "suppressedExceptions") == null);
87     }
88 }