diff options
author | 2020-02-27 09:56:08 +0100 | |
---|---|---|
committer | 2020-02-27 11:27:46 +0100 | |
commit | 5b1830d2eec4eddbeaeea9b4076404fbdb78e5e2 (patch) | |
tree | edee4ec658596157dbd149df23e76b9dd72c0f02 /certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientTest.java | |
parent | 628ed81f0e56f7163b08b57a8d54833b646239d5 (diff) |
Replacement of RuntimeException with Exception class
Clean up in tests and run method.
Issue-ID: AAF-996
Signed-off-by: kjaniak <kornel.janiak@nokia.com>
Change-Id: I2abbfa9af4a77960cb65e9b9ecfcb058eb69cf12
Diffstat (limited to 'certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientTest.java')
-rw-r--r-- | certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientTest.java | 38 |
1 files changed, 8 insertions, 30 deletions
diff --git a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientTest.java b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientTest.java index 22baab50..9e733017 100644 --- a/certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientTest.java +++ b/certServiceClient/src/test/java/org/onap/aaf/certservice/client/CertServiceClientTest.java @@ -22,48 +22,26 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; -import org.onap.aaf.certservice.client.certification.KeyPairFactory; -import java.security.KeyPair; -import java.util.Optional; - -import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import static org.onap.aaf.certservice.client.certification.EncryptionAlgorithmConstants.KEY_SIZE; -import static org.onap.aaf.certservice.client.certification.EncryptionAlgorithmConstants.RSA_ENCRYPTION_ALGORITHM; +import static org.onap.aaf.certservice.client.api.ExitCode.CLIENT_CONFIGURATION_EXCEPTION; +import static org.onap.aaf.certservice.client.api.ExitCode.SUCCESS_EXIT_CODE; @ExtendWith(MockitoExtension.class) class CertServiceClientTest { - private static final int DUMMY_EXIT_CODE = 888; @Spy AppExitHandler appExitHandler = new AppExitHandler(); - - @Test - public void shouldExitWithDefinedExitCode_onGenerateKeyPairCallWhereExitableExceptionIsThrown() { - // given - KeyPairFactory keyPairFactory = mock(KeyPairFactory.class); - when(keyPairFactory.create()).thenThrow(new DummyExitableException()); - doNothing().when(appExitHandler).exit(DUMMY_EXIT_CODE); - CertServiceClient certServiceClient = new CertServiceClient(appExitHandler); - // when - Optional<KeyPair> keyPair = certServiceClient.generateKeyPair(keyPairFactory); - // then - verify(appExitHandler).exit(DUMMY_EXIT_CODE); - assertThat(keyPair).isEmpty(); - } - @Test - public void shouldReturnKeyPair_onGenerateKeyPairCall() { + public void shouldExitWithDefinedExitCode_onRunCallWhenNoEnvsPresent() { // given - KeyPairFactory keyPairFactory = new KeyPairFactory(RSA_ENCRYPTION_ALGORITHM, KEY_SIZE); + doNothing().when(appExitHandler).exit(CLIENT_CONFIGURATION_EXCEPTION.getValue()); + doNothing().when(appExitHandler).exit(SUCCESS_EXIT_CODE.getValue()); CertServiceClient certServiceClient = new CertServiceClient(appExitHandler); // when - Optional<KeyPair> keyPair = certServiceClient.generateKeyPair(keyPairFactory); + certServiceClient.run(); // then - assertThat(keyPair).hasValueSatisfying(value -> assertThat(value).isInstanceOf(KeyPair.class)); + verify(appExitHandler).exit(CLIENT_CONFIGURATION_EXCEPTION.getValue()); + verify(appExitHandler).exit(SUCCESS_EXIT_CODE.getValue()); } - }
\ No newline at end of file |