KaptchaController { @GetMapping(value = "images/rand", produces = "image/jpeg") public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { kaptchaExtend.captcha(request, response); }  @GetMapping(value = "images/rand", produces = "image/jpeg") void doGet(HttpServletRequest request, HttpServletResponse response);  }
@Test public void testDoGet() throws Exception { log.info("doGet"); MvcResult result = mockMvc.perform(get("/images/rand.jpg")) .andExpect(content().contentTypeCompatibleWith(MediaType.IMAGE_JPEG)) .andReturn(); HttpSession session = result.getRequest().getSession(false); assertThat(session).describedAs("no session").isNotNull(); MockHttpServletResponse response = result.getResponse(); byte[] body = response.getContentAsByteArray(); assertThat(body).describedAs("body").isNotNull().isNotEmpty(); assertNotEquals("empty body", 0, body.length); assertThat((String) session.getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY)).isNotEmpty(); }