### Question:
ComponentResource { @GET @Path("/{componentId}/icon") @Produces("image/jpeg") public Response getComponentIcon(@PathParam("componentId") String componentId) { return Response.ok(componentService.getComponentIcon(componentId)).build(); } @Inject  ComponentResource(ComponentService componentService); @GET @Produces(MediaType.APPLICATION_JSON) Collection<Component> listComponents(@QueryParam("visibility") 
            @DefaultValue(Framework.VISIBILITY_ALL) String visibility); @GET @Path("/{componentId}") @Produces(MediaType.APPLICATION_JSON) Component getComponent(@PathParam("componentId") String componentId); @GET @Path("/{componentId}/config") @Produces(MediaType.APPLICATION_JSON) ComponentConfig getComponentConfig(@PathParam("componentId") String componentId); @GET @Path("/{componentId}/icon") @Produces("image/jpeg") Response getComponentIcon(@PathParam("componentId") String componentId);  }### Answer:
@Test public void getComponentIcon() { final String mockedComponentId = "COMPONENT_TO_GET"; try { final byte[] mockedIconData = IOUtils.toByteArray(Thread.currentThread() .getContextClassLoader().getResourceAsStream("component/icons/sample-icon.png")); when(componentServiceMock.getComponentIcon(anyString())).then(new Answer<byte[]>() { @Override public byte[] answer(InvocationOnMock invocation) throws Throwable { String argComponentId = (String) invocation.getArguments()[0]; assertEquals("Service component ID should match mocked component ID", argComponentId, mockedComponentId); return mockedIconData; } }); byte[] responseIconData = resource() .path("/api/components/" + mockedComponentId + "/icon") .accept("image/jpeg").get(byte[].class); assertTrue("Binary icon content should match mocked icon content", Arrays.equals(responseIconData, mockedIconData)); verify(componentServiceMock).getComponentIcon(anyString()); } catch (Exception ex) { fail("Unable to load sample icon for test: " + ex.getMessage()); } }