CatalogOutputAdapter { @SuppressWarnings("WeakerAccess") public BufferedImage getImage(ResourceResponse resourceResponse) throws IOException { validateArgument(resourceResponse, "resourceResponse"); validateArgument(resourceResponse.getResource(), "resourceResponse.resource"); BufferedImage image = null; try (InputStream resourceStream = resourceResponse.getResource().getInputStream()) { validateObjectState(resourceStream, "resourceResponse.resource.inputStream"); Resource resource = resourceResponse.getResource(); try (InputStream inputStream = resource.getInputStream(); BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream)) { lock.acquire(); try { image = ImageIO.read(bufferedInputStream); } finally { lock.release(); } } catch (InterruptedException e) { LOGGER.debug("Interrupt received while doing image processing.", e); Thread.currentThread().interrupt(); } } return image; } CatalogOutputAdapter(Semaphore lock); @SuppressWarnings("WeakerAccess") BufferedImage getImage(ResourceResponse resourceResponse); @SuppressWarnings("WeakerAccess") BinaryContent getBinaryContent(BufferedImage image); @SuppressWarnings("unused") NitfSegmentsFlow getNitfSegmentsFlow(ResourceResponse resourceResponse); @SuppressWarnings("unused") BinaryContent getNitfBinaryContent(
      BufferedImage chip, NitfSegmentsFlow nitfSegmentsFlow, int sourceX, int sourceY); @SuppressWarnings("unused") void wrapException(Exception exception);  }
@Test(expected = IllegalArgumentException.class) public void testGetImageNullCatalogResponse() throws IOException { catalogOutputAdapter.getImage(null); }
@Test(expected = IllegalArgumentException.class) public void testGetImageNullResource() throws IOException { ResourceResponse resourceResponse = mock(ResourceResponse.class); when(resourceResponse.getResource()).thenReturn(null); catalogOutputAdapter.getImage(resourceResponse); }
@Test(expected = IllegalStateException.class) public void testGetImageNullInputStream() throws IOException { ResourceResponse resourceResponse = mock(ResourceResponse.class); Resource resource = mock(Resource.class); when(resourceResponse.getResource()).thenReturn(resource); when(resource.getInputStream()).thenReturn(null); catalogOutputAdapter.getImage(resourceResponse); }
@Test public void testGetImage() throws IOException, InterruptedException { InputStream is = getInputStream(I_3001A); ResourceResponse resourceResponse = mock(ResourceResponse.class); Resource resource = mock(Resource.class); when(resourceResponse.getResource()).thenReturn(resource); when(resource.getInputStream()).thenReturn(is); BufferedImage image = catalogOutputAdapter.getImage(resourceResponse); assertThat(image, is(notNullValue())); assertThat(image.getWidth(), is(1024)); assertThat(image.getHeight(), is(1024)); verify(lock).acquire(); verify(lock).release(); }