### Question:
HashicorpKeyVaultServiceFactoryUtil { SslConfiguration configureSsl(KeyVaultConfig keyVaultConfig, EnvironmentVariableProvider envProvider) { if(keyVaultConfig.hasProperty("tlsKeyStorePath","tlsTrustStorePath")) { Path tlsKeyStorePath = keyVaultConfig.getProperty("tlsKeyStorePath").map(Paths::get).get(); Path tlsTrustStorePath = keyVaultConfig.getProperty("tlsTrustStorePath").map(Paths::get).get(); Resource clientKeyStore = new FileSystemResource(tlsKeyStorePath.toFile()); Resource clientTrustStore = new FileSystemResource(tlsTrustStorePath.toFile()); SslConfiguration.KeyStoreConfiguration keyStoreConfiguration = SslConfiguration.KeyStoreConfiguration.of( clientKeyStore, envProvider.getEnvAsCharArray(HASHICORP_CLIENT_KEYSTORE_PWD) ); SslConfiguration.KeyStoreConfiguration trustStoreConfiguration = SslConfiguration.KeyStoreConfiguration.of( clientTrustStore, envProvider.getEnvAsCharArray(HASHICORP_CLIENT_TRUSTSTORE_PWD) ); return new SslConfiguration(keyStoreConfiguration, trustStoreConfiguration); } else if (keyVaultConfig.hasProperty("tlsTrustStorePath")) { Path tlsTrustStorePath = keyVaultConfig.getProperty("tlsTrustStorePath").map(Paths::get).get(); Resource clientTrustStore = new FileSystemResource(tlsTrustStorePath.toFile()); return SslConfiguration.forTrustStore(clientTrustStore, envProvider.getEnvAsCharArray(HASHICORP_CLIENT_TRUSTSTORE_PWD)); } else { return SslConfiguration.unconfigured(); } }    }### Answer:
@Test public void configureSslUsesKeyStoreAndTrustStoreIfBothProvided() throws Exception { KeyVaultConfig keyVaultConfig = mock(KeyVaultConfig.class); EnvironmentVariableProvider envProvider = mock(EnvironmentVariableProvider.class); Path path = Files.createTempFile(UUID.randomUUID().toString(), ".tmp"); path.toFile().deleteOnExit(); when(keyVaultConfig.hasProperty("tlsKeyStorePath","tlsTrustStorePath")).thenReturn(true); when(keyVaultConfig.getProperty("tlsKeyStorePath")).thenReturn(Optional.of(path.toString())); when(keyVaultConfig.getProperty("tlsTrustStorePath")).thenReturn(Optional.of(path.toString())); SslConfiguration result = util.configureSsl(keyVaultConfig, envProvider); assertThat(result.getKeyStoreConfiguration().isPresent()).isTrue(); assertThat(result.getTrustStoreConfiguration().isPresent()).isTrue(); }
@Test public void configureSslUsesTrustStoreOnlyIfProvided() throws Exception { KeyVaultConfig keyVaultConfig = mock(KeyVaultConfig.class); EnvironmentVariableProvider envProvider = mock(EnvironmentVariableProvider.class); Path path = Files.createTempFile(UUID.randomUUID().toString(), ".tmp"); path.toFile().deleteOnExit(); when(keyVaultConfig.hasProperty("tlsTrustStorePath")).thenReturn(true); when(keyVaultConfig.hasProperty("tlsKeyStorePath")).thenReturn(false); when(keyVaultConfig.getProperty("tlsKeyStorePath")).thenReturn(Optional.empty()); when(keyVaultConfig.getProperty("tlsTrustStorePath")).thenReturn(Optional.of(path.toString())); SslConfiguration result = util.configureSsl(keyVaultConfig, envProvider); assertThat(result.getKeyStoreConfiguration().isPresent()).isFalse(); assertThat(result.getTrustStoreConfiguration().isPresent()).isTrue(); }
@Test public void configureSslUsesNoKeyStoresIfNoneProvided() { KeyVaultConfig keyVaultConfig = mock(KeyVaultConfig.class); EnvironmentVariableProvider envProvider = mock(EnvironmentVariableProvider.class); when(keyVaultConfig.getProperty("tlsKeyStorePath")).thenReturn(Optional.empty()); when(keyVaultConfig.getProperty("tlsTrustStorePath")).thenReturn(Optional.empty()); SslConfiguration result = util.configureSsl(keyVaultConfig, envProvider); assertThat(result.getKeyStoreConfiguration().isPresent()).isFalse(); assertThat(result.getTrustStoreConfiguration().isPresent()).isFalse(); }