SW360ConnectionConfigurationFactory { public SW360Connection createConnection(Getter<String> getConfigValue, HttpClient httpClient, ObjectMapper mapper) { String restUrl = getConfigValue.apply(REST_SERVER_URL_KEY); String authUrl = getConfigValue.apply(AUTH_SERVER_URL_KEY); String user = getConfigValue.apply(USERNAME_KEY); String password = getConfigValue.apply(PASSWORD_KEY); String clientId = getConfigValue.apply(CLIENT_USER_KEY); String clientPassword = getConfigValue.apply(CLIENT_PASSWORD_KEY); String token = getConfigValue.apply(TOKEN_KEY); SW360ClientConfig clientConfig = SW360ClientConfig.createConfig(restUrl, authUrl, user, password, clientId, clientPassword, token, httpClient, mapper); return connectionFactory.newConnection(clientConfig); } SW360ConnectionConfigurationFactory();   SW360ConnectionConfigurationFactory(SW360ConnectionFactory connectionFactory); SW360Connection createConnection(Getter<String> getConfigValue, HttpClient httpClient,
                                            ObjectMapper mapper); static final String REST_SERVER_URL_KEY; static final String AUTH_SERVER_URL_KEY; static final String USERNAME_KEY; static final String PASSWORD_KEY; static final String CLIENT_USER_KEY; static final String CLIENT_PASSWORD_KEY; static final String TOKEN_KEY; }
@Test public void testConnectionCreation() { HttpClient httpClient = mock(HttpClient.class); ObjectMapper mapper = mock(ObjectMapper.class); SW360ConnectionFactory connectionFactory = mock(SW360ConnectionFactory.class); SW360Connection connection = mock(SW360Connection.class); when(connectionFactory.newConnection(any())).thenReturn(connection); SW360ConnectionConfigurationFactory factory = new SW360ConnectionConfigurationFactory(connectionFactory); SW360Connection actualConnection = factory.createConnection(stringConfigGetter(), httpClient, mapper); assertThat(actualConnection).isEqualTo(connection); ArgumentCaptor<SW360ClientConfig> captSW360Config = ArgumentCaptor.forClass(SW360ClientConfig.class); verify(connectionFactory).newConnection(captSW360Config.capture()); SW360ClientConfig sw360ClientConfig = captSW360Config.getValue(); assertThat(sw360ClientConfig.getRestURL()).isEqualTo(REST_URL); assertThat(sw360ClientConfig.getAuthURL()).isEqualTo(AUTH_URL); assertThat(sw360ClientConfig.getUser()).isEqualTo(USER); assertThat(sw360ClientConfig.getPassword()).isEqualTo(PASSWORD); assertThat(sw360ClientConfig.getClientId()).isEqualTo(CLIENT_ID); assertThat(sw360ClientConfig.getClientPassword()).isEqualTo(CLIENT_SECRET); assertThat(sw360ClientConfig.getHttpClient()).isEqualTo(httpClient); assertThat(sw360ClientConfig.getObjectMapper()).isEqualTo(mapper); }