HttpClients { public static void safeShutdown(final HttpClient httpClient) { new Thread(new Runnable() { @Override public void run() { if (httpClient != null && httpClient.getConnectionManager() != null) { httpClient.getConnectionManager().shutdown(); } } }).start(); }  static void safeShutdown(final HttpClient httpClient);  }
@Test public void safeShutdown_shouldShutdownHttpClient() throws Exception { HttpClients.safeShutdown(httpClient); ThreadUtils.pause(HTTP_CLIENT_SHUTDOWN_TIME); verify(clientConnectionManager).shutdown(); }
@Test public void safeShutdown_withNullHttpClient_shouldNotBlowUp() throws Exception { HttpClients.safeShutdown(null); ThreadUtils.pause(HTTP_CLIENT_SHUTDOWN_TIME); verify(clientConnectionManager, never()).shutdown(); }
@Test public void safeShutdown_withNullConnectionManager_shouldNotBlowUp() throws Exception { stub(httpClient.getConnectionManager()).toReturn(null); HttpClients.safeShutdown(httpClient); ThreadUtils.pause(HTTP_CLIENT_SHUTDOWN_TIME); verify(clientConnectionManager, never()).shutdown(); }