public void testHandleRequestToCaptchaImage() throws Exception {
HttpServletResponse response = mock(HttpServletResponse.class);
session = mock(HttpSession.class);
request.setSession(session);
ServletOutputStream out = mock(ServletOutputStream.class);
Producer captchaProducer = mock(Producer.class);
int imageType = 1;
when(response.getOutputStream()).thenReturn(out);
when(service.getCaptchaProducer()).thenReturn(captchaProducer);
when(captchaProducer.createText()).thenReturn(GENERATED_CAPTCHA_TEXT);
when(captchaProducer.createImage(GENERATED_CAPTCHA_TEXT)).
thenReturn(new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, imageType));
service.refreshCaptchaImage(request, response);
verify(response).setContentType("image/jpeg");