### Question:
ClientFactory implements RestClientFactory { public Client buildFrom(final ServerConfig config) { final ClientBuilder clientBuilder = ClientBuilder.newBuilder(); final long pollInterval = new IntervalPropertyHelper(config.getProperties()).partyInfoInterval(); final long timeout = Math.round(Math.ceil(pollInterval * 0.75)); clientBuilder.connectTimeout(timeout, TimeUnit.MILLISECONDS); clientBuilder.readTimeout(timeout, TimeUnit.MILLISECONDS); clientBuilder.register(VersionHeaderDecorator.class); if (config.isUnixSocket()) { Configuration clientConfig = createUnixServerSocketConfig(); URI unixfile = config.getServerUri(); return ClientBuilder.newClient(clientConfig).property("unixfile", unixfile); } else if (config.isSsl()) { final SSLContext sslContext = sslContextFactory.from(config.getServerUri().toString(), config.getSslConfig()); return clientBuilder.sslContext(sslContext).build(); } else { return clientBuilder.build(); } } ClientFactory(final SSLContextFactory sslContextFactory);  ClientFactory(); Client buildFrom(final ServerConfig config);  }### Answer:
@Test public void testBuildInsecureClient() { ServerConfig serverConfig = mock(ServerConfig.class); when(serverConfig.isSsl()).thenReturn(false); when(serverConfig.getProperties()).thenReturn(Collections.emptyMap()); Client client = factory.buildFrom(serverConfig); assertThat(client).isNotNull(); }
@Test public void testBuildSecureClientCAMode() throws URISyntaxException { ServerConfig serverConfig = mock(ServerConfig.class); SslConfig sslConfig = mock(SslConfig.class); when(serverConfig.isSsl()).thenReturn(true); when(serverConfig.getServerUri()).thenReturn(new URI("https: when(serverConfig.getSslConfig()).thenReturn(sslConfig); Map<String, String> props = new HashMap<>(); props.put("partyInfoInterval", "20000"); when(serverConfig.getProperties()).thenReturn(props); SSLContext sslContext = mock(SSLContext.class); when(sslContextFactory.from(serverConfig.getServerUri().toString(), sslConfig)).thenReturn(sslContext); Client client = factory.buildFrom(serverConfig); assertThat(client).isNotNull(); Map clientProperties = client.target(serverConfig.getServerUri()).getConfiguration().getProperties(); assertThat(clientProperties.get(ClientProperties.READ_TIMEOUT)).isEqualTo(15000); assertThat(clientProperties.get(ClientProperties.CONNECT_TIMEOUT)).isEqualTo(15000); verify(sslContextFactory).from(serverConfig.getServerUri().toString(), sslConfig); }
@Test public void createUnixSocketClient() { ServerConfig serverConfig = new ServerConfig(); serverConfig.setServerAddress("unix:/tmp/bogus.socket"); serverConfig.setApp(AppType.Q2T); serverConfig.setCommunicationType(CommunicationType.REST); org.glassfish.jersey.client.JerseyClient result = (org.glassfish.jersey.client.JerseyClient) factory.buildFrom(serverConfig); assertThat(result.getConfiguration().getProperty("unixfile")).isNotNull().isInstanceOf(URI.class); assertThat(result.getConfiguration().getProperty("unixfile").toString()).isEqualTo("unix:/tmp/bogus.socket"); assertThat(result.getConfiguration().getConnectorProvider()) .isInstanceOf(JerseyUnixSocketConnectorProvider.class); }