### Question:
VerifyCodeController { @GetMapping("/generate") public void imageCode(@RequestHeader HttpHeaders headers, HttpServletRequest request, HttpServletResponse response) throws IOException { OutputStream os = response.getOutputStream(); Map<String, Object> map = verifyCodeService.getImageCode(60, 20, os, request, response, headers); String simpleCaptcha = "simpleCaptcha"; request.getSession().setAttribute(simpleCaptcha, map.get("strEnsure").toString().toLowerCase()); request.getSession().setAttribute("codeTime", System.currentTimeMillis()); try { ImageIO.write((BufferedImage) map.get("image"), "JPEG", os); } catch (IOException e) { String error = "Can't generate verification code"; os.write(error.getBytes()); } }  @GetMapping("/generate") void imageCode(@RequestHeader HttpHeaders headers,
                          HttpServletRequest request,
                          HttpServletResponse response); @GetMapping(value = "/verify/{verifyCode}") boolean verifyCode(@PathVariable String verifyCode, HttpServletRequest request,
                              HttpServletResponse response, @RequestHeader HttpHeaders headers);  }### Answer:
@Test public void testImageCode() throws Exception { Map<String, Object> map = new HashMap<>(); BufferedImage image = new BufferedImage(60, 20, BufferedImage.TYPE_INT_RGB); map.put("strEnsure", "XYZ8"); map.put("image", image); Mockito.when(verifyCodeService.getImageCode(Mockito.anyInt(), Mockito.anyInt(), Mockito.any(OutputStream.class), Mockito.any(HttpServletRequest.class), Mockito.any(HttpServletResponse.class), Mockito.any(HttpHeaders.class))).thenReturn(map); mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/verifycode/generate")).andReturn(); Mockito.verify(verifyCodeService, Mockito.times(1)).getImageCode(Mockito.anyInt(), Mockito.anyInt(), Mockito.any(OutputStream.class), Mockito.any(HttpServletRequest.class), Mockito.any(HttpServletResponse.class), Mockito.any(HttpHeaders.class)); }