CandidateController extends LogicallyDeletableAbstractController<CandidateDTO> { @Override public ResponseEntity saveOrUpdate(@Valid @RequestBody CandidateDTO candidateDTO, BindingResult result, Locale locale) { if (!result.hasErrors()) { Long candidateId = candidateService.saveOrUpdate(candidateDTO); return new ResponseEntity<>(Collections.singletonMap("id", candidateId), HttpStatus.OK); } else { RestResponse restResponse = parseValidationErrors(result.getFieldErrors(), locale); return new ResponseEntity<>(restResponse, HttpStatus.BAD_REQUEST); } } @Autowired  CandidateController(
      CandidateService candidateService,
      MessageKeyResolver messageKeyResolver, CandidateValidatorHelper candidateValidatorHelper); @RequestMapping(method = RequestMethod.GET) PagingResponse<CandidateDTO> loadPage(
      @RequestParam(value = "filter", required = false) String filter,
      @RequestParam(value = "sortName", required = true) String sortName,
      @RequestParam(value = "sortOrder", required = true) String sortOrder,
      @RequestParam(value = "pageSize", required = true) int pageSize,
      @RequestParam(value = "pageNumber", required = true) int pageNumber); @Override ResponseEntity saveOrUpdate(@Valid @RequestBody CandidateDTO candidateDTO,
                                     BindingResult result, Locale locale); @RequestMapping(path = "/validate", method = RequestMethod.POST) ResponseEntity validateCandidate(@Valid @RequestBody CandidateDTO candidateDTO,
                                          BindingResult result,
                                          Locale locale);  }
@Test public void saveOrUpdateShouldRespondWithAnIdWhenPostedDtoIsCorrect() throws Exception { given(candidateService.saveOrUpdate(correctCandidateDto)).willReturn(candidateId); mockMvc.perform(buildJsonPostRequest(REQUEST_URL, correctCandidateDto)) .andExpect(status().isOk()) .andExpect(jsonPath("$.id").exists()) .andExpect(jsonPath("$.id").isNumber()) .andExpect(jsonPath("$.id", equalTo(candidateId.intValue()))); then(candidateService).should().saveOrUpdate(correctCandidateDto); }