public void testGetImage() throws ServletException, IOException {
final String resource = "picture.png";
when( request.getParameter( RESOURCE_PARAM ) ).thenReturn( resource );
final ServletOutputStream outputStream = mock( ServletOutputStream.class );
final MutableInt fileLength = new MutableInt( 0 );
doAnswer( new Answer<Void>() {
@Override
public Void answer( InvocationOnMock invocation ) throws Throwable {
fileLength.add( (Integer) invocation.getArguments()[2] );
return null;
}
} ).when( outputStream ).write( any( byte[].class ), anyInt(), anyInt() );
when( response.getOutputStream() ).thenReturn( outputStream );
servlet.service( request, response );
verify( response ).setContentType( eq( TEST_MIME_TYPE ) );
final int expected = new Long( new File( PentahoSystem.getApplicationContext()
.getSolutionPath( "system/tmp/" + resource ) ).length() ).intValue();
assertEquals( expected, fileLength.intValue() );
verify( response ).setContentLength( eq( expected ) );
}