@Test
public void testGetBusinessObjectDataDownloadCredentialAssertThrowIOExceptionWhenClosingHttpClientThrowsIOException() 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
    {
        CloseableHttpClient closeableHttpClient = mock(CloseableHttpClient.class);
        when(mockHttpClientHelper.createHttpClient(any(), any())).thenReturn(closeableHttpClient);
        doThrow(IOException.class).when(closeableHttpClient).close();
        CloseableHttpResponse closeableHttpResponse = mock(CloseableHttpResponse.class);
        when(mockHttpClientOperations.execute(any(), any())).thenReturn(closeableHttpResponse);
        when(closeableHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "SUCCESS"));
        when(closeableHttpResponse.getEntity()).thenReturn(new StringEntity(xmlHelper.objectToXml(new StorageUnitDownloadCredential())));
        DownloaderInputManifestDto downloaderInputManifestDto = new DownloaderInputManifestDto();
        String storageName = "storageName";
        try
        {
            downloaderWebClient.getStorageUnitDownloadCredential(downloaderInputManifestDto, storageName);
            verify(closeableHttpClient).close();
            fail();
        }
        catch (Exception e)
        {
            assertEquals(IOException.class, e.getClass());
        }
    }
    finally
    {
        ReflectionTestUtils.setField(downloaderWebClient, "httpClientHelper", originalHttpClientHelper);
        ReflectionTestUtils.setField(downloaderWebClient, "httpClientOperations", originalHttpClientOperations);
    }
}