@Test
    public void readResource_4xx_inputStreamClosed() throws IOException {
        HttpURLConnection mockUrlConn = mock(HttpURLConnection.class);
        when(mockUrlConn.getResponseCode()).thenReturn(404);
        TestInputStream is = new TestInputStream();
        when(mockUrlConn.getErrorStream()).thenReturn(is);
        when(mockConnection.connectToEndpoint(eq(endpoint), any(Map.class), eq("GET"))).thenReturn(mockUrlConn);

        try {
            new DefaultEC2ResourceFetcher(mockConnection).readResource(endpoint, customRetryPolicy,
                    Collections.<String, String>emptyMap());
        } catch (Exception ignored) {
        } finally {
            assertTrue(is.closed);
        }
    }
When readResource is called with custom retry policy
and additional headers, the SDK User-Agent should be
added.
aws-java-sdk-core/src/test/java/com/amazonaws/internal/EC2ResourceFetcherTest.java