### Question:
AttachmentContentDownloader { public InputStream download(AttachmentContent attachmentContent, Duration timeout) throws IOException { int millisTimeout = ((Number) timeout.toMillis()).intValue(); URL remoteURL = new URL(attachmentContent.getRemoteUrl()); URLConnection urlConnection = remoteURL.openConnection(); urlConnection.setConnectTimeout(millisTimeout); urlConnection.setReadTimeout(millisTimeout); InputStream downloadStream = urlConnection.getInputStream(); return new BufferedInputStream(downloadStream); }  InputStream download(AttachmentContent attachmentContent, Duration timeout);  }### Answer:
@Test public void testTheCouchDbUrl() throws Exception { AttachmentContent attachmentContent = mock(AttachmentContent.class); when(attachmentContent.getRemoteUrl()).thenReturn(DatabaseTestProperties.getCouchDbUrl()); try (InputStream download = attachmentContentDownloader.download(attachmentContent, downloadTimeout)) { String read = CharStreams.toString(new InputStreamReader(download)); assertThat(read, is(not(nullOrEmpty()))); assertThat(read, containsString("couchdb")); } }
@Test public void testABlackHoleUrl() throws Exception { assumeThat(getAvailableNetworkInterface(), isAvailable()); Callable<String> downloadAttempt = () -> { AttachmentContent attachmentContent = mock(AttachmentContent.class); when(attachmentContent.getRemoteUrl()).thenReturn("http: try (InputStream download = attachmentContentDownloader .download(attachmentContent, downloadTimeout)) { return CharStreams.toString(new InputStreamReader(download)); } }; ExecutorService executor = newSingleThreadExecutor(); try { Future<String> future = executor.submit(downloadAttempt); try { try { String read = future.get(1, TimeUnit.MINUTES); fail("downloader managed to escape with '" + read + "' from the black hole! " + "Try this test again with a more massive black hole"); } catch (ExecutionException e) { Throwable futureException = e.getCause(); assertThat(futureException, is(notNullValue())); assertTrue(futureException instanceof IOException); } } catch (TimeoutException e) { fail("downloader got stuck on a black hole"); throw e; } } finally { executor.shutdown(); executor.awaitTermination(1, TimeUnit.MINUTES); } }