MethodArgumentNotValidExceptionHandler implements RestExceptionHandler<MethodArgumentNotValidException> { @Override public Object errorMessage(MethodArgumentNotValidException exception, HttpServletRequest request) { BindingResult bindingResult = exception.getBindingResult(); int errorCount = bindingResult.getErrorCount(); return String.join("", bindingResult.getObjectName(), " has ", String.valueOf(errorCount), " validation error", errorCount > 1 ? "s" : ""); }  @Override Object errorMessage(MethodArgumentNotValidException exception, HttpServletRequest request); @Override Map<String, Object> additionalInfo(MethodArgumentNotValidException exception, HttpServletRequest request);  }
@Test public void errorMessage() throws Exception { BindingResult error = new BeanPropertyBindingResult("bean", "message"); MethodArgumentNotValidException exception = new MethodArgumentNotValidException(null, error); Object o = handler.errorMessage(exception, MOCK_REQUEST); }