@Test public void testNoOpResponse() throws IOException { FastByteArrayOutputStream out = new FastByteArrayOutputStream(STREAM_DEFAULT_SIZE); HttpServletResponse response = mock(HttpServletResponse.class); when(response.getOutputStream()).thenReturn(new OutputStreamAdapter(out)); ImageServletResponseImpl imageResponse = new ImageServletResponseImpl(request, response, context); fakeResponse(request, imageResponse); // TODO: Is there a way we can avoid calling flush? // Flush image to wrapped response imageResponse.flush(); assertTrue("Content has no data", out.size() > 0); // Test that image data is untouched assertTrue("Data differs", Arrays.equals(FileUtil.read(getClass().getResourceAsStream(IMAGE_NAME_PNG)), out.toByteArray())); verify(response).setContentType(CONTENT_TYPE_PNG); verify(response).getOutputStream(); }
@Test public void testNoOpResponse() throws IOException { FastByteArrayOutputStream out = new FastByteArrayOutputStream(STREAM_DEFAULT_SIZE); HttpServletResponse response = mock(HttpServletResponse.class); when(response.getOutputStream()).thenReturn(new OutputStreamAdapter(out)); ImageServletResponseImpl imageResponse = new ImageServletResponseImpl(request, response, context); fakeResponse(request, imageResponse); // TODO: Is there a way we can avoid calling flush? // Flush image to wrapped response imageResponse.flush(); assertTrue("Content has no data", out.size() > 0); // Test that image data is untouched assertTrue("Data differs", Arrays.equals(FileUtil.read(getClass().getResourceAsStream(IMAGE_NAME_PNG)), out.toByteArray())); verify(response).setContentType(CONTENT_TYPE_PNG); verify(response).getOutputStream(); }