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
10 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.oom.truststoremerger;
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.truststoremerger.api.ExitStatus.ALIAS_CONFLICT_EXCEPTION;
27 import static org.onap.oom.truststoremerger.api.ExitStatus.SUCCESS;
28 import static org.onap.oom.truststoremerger.api.ExitStatus.UNEXPECTED_EXCEPTION;
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.truststoremerger.merger.exception.AliasConflictException;
37 @ExtendWith(MockitoExtension.class)
38 public class AppExecutorTest {
43 AppExitHandler exitHandler;
45 AppExecutor executor = new AppExecutor();
48 void shouldExitWithUnexpectedException() {
49 doThrow(new NullPointerException()).when(logic).run();
50 doNothing().when(exitHandler).exit(UNEXPECTED_EXCEPTION);
52 executor.execute(logic);
54 verify(exitHandler).exit(UNEXPECTED_EXCEPTION);
58 void shouldExitWithKnownException() {
59 doThrow(new AliasConflictException("")).when(logic).run();
60 doNothing().when(exitHandler).exit(ALIAS_CONFLICT_EXCEPTION);
62 executor.execute(logic);
64 verify(exitHandler).exit(ALIAS_CONFLICT_EXCEPTION);
68 void shouldExitWithSuccess() {
69 doNothing().when(logic).run();
70 doNothing().when(exitHandler).exit(SUCCESS);
72 executor.execute(logic);
74 verify(exitHandler).exit(SUCCESS);