@Test public void test_handleBindException_returns_errors() throws Exception { BindException be = mock(BindException.class); ObjectError fakeError1 = new ObjectError("orgEnrollmentConfig", "fakeErrorMessage1"); ObjectError fakeError2 = new ObjectError("orgEnrollmentConfig", "fakeErrorMessage2"); when(be.getAllErrors()).thenReturn(Arrays.asList(fakeError1, fakeError2)); HttpServletResponse response = mock(HttpServletResponse.class); ResponseEntity<List<ObjectError>> errors = autoEnrollmentController.handleBindException(be, response); assertTrue(errors.getBody() != null && errors.getBody().size() == 2); assertTrue(errors.getStatusCode() == HttpStatus.BAD_REQUEST); }
@ExceptionHandler({ BindException.class }) public ResponseEntity<List<ObjectError>> handleBindException(BindException be, HttpServletResponse response) { return new ResponseEntity<List<ObjectError>>(be.getAllErrors(), HttpStatus.BAD_REQUEST); }
AutoEnrollmentController { @ExceptionHandler({ BindException.class }) public ResponseEntity<List<ObjectError>> handleBindException(BindException be, HttpServletResponse response) { return new ResponseEntity<List<ObjectError>>(be.getAllErrors(), HttpStatus.BAD_REQUEST); } }
AutoEnrollmentController { @ExceptionHandler({ BindException.class }) public ResponseEntity<List<ObjectError>> handleBindException(BindException be, HttpServletResponse response) { return new ResponseEntity<List<ObjectError>>(be.getAllErrors(), HttpStatus.BAD_REQUEST); }  }
AutoEnrollmentController { @ExceptionHandler({ BindException.class }) public ResponseEntity<List<ObjectError>> handleBindException(BindException be, HttpServletResponse response) { return new ResponseEntity<List<ObjectError>>(be.getAllErrors(), HttpStatus.BAD_REQUEST); }  @RequestMapping(method = RequestMethod.GET, value = "/{organizationId}") ResponseEntity<OrgEnrollmentConfig> getEnrolledOrganization(
            @PathVariable String organizationId); @RequestMapping(method = RequestMethod.DELETE, value = "/{organizationId}") ResponseEntity<OrgEnrollmentConfig> deleteOrganization(
            @PathVariable String organizationId); @RequestMapping(method = RequestMethod.PUT, value = "{organizationId}") ResponseEntity<OrgEnrollmentConfig> enrolOrganization(
            @PathVariable String organizationId,
            @Valid @RequestBody OrgEnrollmentConfigRequest orgEnrollerConfigRequest,
            BindingResult result); @InitBinder void initBinder(WebDataBinder binder); @ExceptionHandler({ CloudFoundryException.class }) ResponseEntity<Object> handleCloudFoundryException(CloudFoundryException cfe,
            HttpServletResponse response); @ExceptionHandler({ BindException.class }) ResponseEntity<List<ObjectError>> handleBindException(BindException be,
            HttpServletResponse response); }
AutoEnrollmentController { @ExceptionHandler({ BindException.class }) public ResponseEntity<List<ObjectError>> handleBindException(BindException be, HttpServletResponse response) { return new ResponseEntity<List<ObjectError>>(be.getAllErrors(), HttpStatus.BAD_REQUEST); }  @RequestMapping(method = RequestMethod.GET, value = "/{organizationId}") ResponseEntity<OrgEnrollmentConfig> getEnrolledOrganization(
            @PathVariable String organizationId); @RequestMapping(method = RequestMethod.DELETE, value = "/{organizationId}") ResponseEntity<OrgEnrollmentConfig> deleteOrganization(
            @PathVariable String organizationId); @RequestMapping(method = RequestMethod.PUT, value = "{organizationId}") ResponseEntity<OrgEnrollmentConfig> enrolOrganization(
            @PathVariable String organizationId,
            @Valid @RequestBody OrgEnrollmentConfigRequest orgEnrollerConfigRequest,
            BindingResult result); @InitBinder void initBinder(WebDataBinder binder); @ExceptionHandler({ CloudFoundryException.class }) ResponseEntity<Object> handleCloudFoundryException(CloudFoundryException cfe,
            HttpServletResponse response); @ExceptionHandler({ BindException.class }) ResponseEntity<List<ObjectError>> handleBindException(BindException be,
            HttpServletResponse response);  }