[OOM-CPMv2] Fix sonar issue
[oom/platform/cert-service.git] / trustStoreMerger / src / test / java / org / onap / oom / certservice / postprocessor / AppExecutorTest.java
1 /*============LICENSE_START=======================================================
2  * oom-truststore-merger
3  * ================================================================================
4  * Copyright (C) 2020 Nokia. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  * ============LICENSE_END=========================================================
18  */
19
20
21 package org.onap.oom.certservice.postprocessor;
22
23 import static org.mockito.Mockito.doNothing;
24 import static org.mockito.Mockito.doThrow;
25 import static org.mockito.Mockito.verify;
26 import static org.onap.oom.certservice.postprocessor.api.ExitStatus.ALIAS_CONFLICT_EXCEPTION;
27 import static org.onap.oom.certservice.postprocessor.api.ExitStatus.SUCCESS;
28 import static org.onap.oom.certservice.postprocessor.api.ExitStatus.UNEXPECTED_EXCEPTION;
29
30 import org.junit.jupiter.api.Test;
31 import org.junit.jupiter.api.extension.ExtendWith;
32 import org.mockito.InjectMocks;
33 import org.mockito.Mock;
34 import org.mockito.junit.jupiter.MockitoExtension;
35 import org.onap.oom.certservice.postprocessor.merger.exception.AliasConflictException;
36
37 @ExtendWith(MockitoExtension.class)
38 class AppExecutorTest {
39
40     @Mock
41     Runnable logic;
42     @Mock
43     AppExitHandler exitHandler;
44     @InjectMocks
45     AppExecutor executor = new AppExecutor();
46
47     @Test
48     void shouldExitWithUnexpectedException() {
49         doThrow(new NullPointerException()).when(logic).run();
50         doNothing().when(exitHandler).exit(UNEXPECTED_EXCEPTION);
51
52         executor.execute(logic);
53
54         verify(exitHandler).exit(UNEXPECTED_EXCEPTION);
55     }
56
57     @Test
58     void shouldExitWithKnownException() {
59         doThrow(new AliasConflictException("")).when(logic).run();
60         doNothing().when(exitHandler).exit(ALIAS_CONFLICT_EXCEPTION);
61
62         executor.execute(logic);
63
64         verify(exitHandler).exit(ALIAS_CONFLICT_EXCEPTION);
65     }
66
67     @Test
68     void shouldExitWithSuccess() {
69         doNothing().when(logic).run();
70         doNothing().when(exitHandler).exit(SUCCESS);
71
72         executor.execute(logic);
73
74         verify(exitHandler).exit(SUCCESS);
75     }
76 }