### Question:
ExternalLinkController { @RequestMapping(value = "/links/save", method = RequestMethod.POST) @ResponseBody public JsonResponse saveLink(@Valid @RequestBody ExternalLink link, BindingResult result) { if (result.hasErrors()) { return new JsonResponse(JsonResponseStatus.FAIL, result.getAllErrors()); } Component component = componentService.getComponentOfForum(); service.saveLink(link, component); return new JsonResponse(JsonResponseStatus.SUCCESS, link); } @Autowired  ExternalLinkController(ExternalLinkService service, ComponentService componentService); @RequestMapping(value = "/links/save", method = RequestMethod.POST) @ResponseBody JsonResponse saveLink(@Valid @RequestBody ExternalLink link, BindingResult result); @RequestMapping(value = "/links/delete/{id}", method = RequestMethod.DELETE) @ResponseBody JsonResponse deleteLink(@PathVariable Long id);  }### Answer:
@Test public void savingLinkShouldPassIfNoValidationErrorsFound() throws Exception { when(bindingResult.hasErrors()).thenReturn(false); JsonResponse expected = controller.saveLink(link(), bindingResult); assertEquals(expected.getStatus(), JsonResponseStatus.SUCCESS); verify(service).saveLink(any(ExternalLink.class), any(Component.class)); }
@Test public void testFailValidationSaveLink() throws Exception { when(bindingResult.hasErrors()).thenReturn(true); JsonResponse expected = controller.saveLink(link(), bindingResult); assertEquals(expected.getStatus(), JsonResponseStatus.FAIL); }