InvalidOrderByExceptionHandler implements BaseExceptionHandler<InvalidOrderByException> { @ExceptionHandler(value = { InvalidOrderByException.class }) @ResponseStatus(value = HttpStatus.PRECONDITION_FAILED) @ResponseBody @Override public MessageResource handle(final InvalidOrderByException e) throws Exception { LOGGER.error("Handling Invalid order by exception", e); String message = MessageFormat.format("Failed validation for orderBy field : {0}", e.getValue()); Pair<String, String> pair = new Pair<String, String>("orderBy", "Pattern: " + orderByPattern); List<Pair<String, String>> fields = Arrays.asList(pair); MessageResource messageResource = new ValidationMessageResource(MessageType.ERROR, message, fields); return messageResource; }  @ExceptionHandler(value = { InvalidOrderByException.class }) @ResponseStatus(value = HttpStatus.PRECONDITION_FAILED) @ResponseBody @Override MessageResource handle(final InvalidOrderByException e);  }
@Test public void test() throws Exception { String msg = "msg"; InvalidOrderByException e = new InvalidOrderByException(msg); String orderByPattern = null; String message = MessageFormat.format("Failed validation for orderBy field : {0}", e.getValue()); Pair<String, String> pair = new Pair<String, String>("orderBy", "Pattern: " + orderByPattern); List<Pair<String, String>> fields = Arrays.asList(pair); MessageResource expected = new ValidationMessageResource(MessageType.ERROR, message, fields); MessageResource actual = unit.handle(e); assertEquals(expected, actual); }