HttpUtils { public HttpClient getHttpClient() { HttpClient httpClient = null; try { httpClient = HttpClientBuilder.create().setSSLHostnameVerifier( NoopHostnameVerifier.INSTANCE). setSSLContext( new SSLContextBuilder().loadTrustMaterial(null,new TrustStrategy() { @Override public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { return true; } }).build() ).setRedirectStrategy(new LaxRedirectStrategy()).build(); } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e1) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "getHttpClient"). put(LogMessage.MESSAGE, "Failed to initialize httpClient"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); } return httpClient; } HttpUtils(); HttpClient getHttpClient();  }
@Test public void test_getHttpClient() { when(HttpClientBuilder.create()).thenReturn(httpClientBuilder); when(httpClientBuilder.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)).thenReturn(httpClientBuilder); when(httpClientBuilder.setSSLContext(any())).thenReturn(httpClientBuilder); when(httpClientBuilder.setRedirectStrategy(any())).thenReturn(httpClientBuilder); when(httpClientBuilder.build()).thenReturn(httpClient); HttpClient httpClientActual = httpUtils.getHttpClient(); assertNotNull(httpClientActual); }