@Test
public void testGetBusinessObjectDataDownloadCredentialAssertHttpClientClosedWhenIOException() throws Exception
{

    HttpClientHelper mockHttpClientHelper = mock(HttpClientHelper.class);
    HttpClientHelper originalHttpClientHelper = (HttpClientHelper) ReflectionTestUtils.getField(downloaderWebClient, "httpClientHelper");
    ReflectionTestUtils.setField(downloaderWebClient, "httpClientHelper", mockHttpClientHelper);
    HttpClientOperations mockHttpClientOperations = mock(HttpClientOperations.class);
    HttpClientOperations originalHttpClientOperations = (HttpClientOperations) ReflectionTestUtils.getField(downloaderWebClient, "httpClientOperations");
    ReflectionTestUtils.setField(downloaderWebClient, "httpClientOperations", mockHttpClientOperations);
    try
    {
        IOException expectedException = new IOException();
        CloseableHttpClient closeableHttpClient = mock(CloseableHttpClient.class);
        when(mockHttpClientHelper.createHttpClient(any(), any())).thenReturn(closeableHttpClient);
        when(mockHttpClientOperations.execute(any(), any())).thenThrow(expectedException);
        DownloaderInputManifestDto downloaderInputManifestDto = new DownloaderInputManifestDto();
        String storageName = "storageName";
        try
        {
            downloaderWebClient.getStorageUnitDownloadCredential(downloaderInputManifestDto, storageName);
            verify(closeableHttpClient).close();
            fail();
        }
        catch (Exception e)
        {
            assertEquals(expectedException, e);
        }
    }
    finally
    {
        ReflectionTestUtils.setField(downloaderWebClient, "httpClientHelper", originalHttpClientHelper);
        ReflectionTestUtils.setField(downloaderWebClient, "httpClientOperations", originalHttpClientOperations);
    }
}