EntityNotFoundExceptionHandler implements BaseExceptionHandler<EntityNotFoundException> { @Override @ResponseBody @ResponseStatus(value = HttpStatus.NOT_FOUND) @ExceptionHandler(value = { EntityNotFoundException.class }) public MessageResource handle(final EntityNotFoundException e) { LOGGER.error("Handling not found exception", e); MessageResource message = new MessageResource(); message.setMessageType(MessageType.ERROR); message.setMessage(e.getMessage()); message.setCause(MessageFormat.format("{0} : {1}", e.getClz().getSimpleName(), e.getIdentifier())); return message; }  @Override @ResponseBody @ResponseStatus(value = HttpStatus.NOT_FOUND) @ExceptionHandler(value = { EntityNotFoundException.class }) MessageResource handle(final EntityNotFoundException e);  }
@Test public void testHandle() throws Exception { String msg = "No entity found"; EntityNotFoundException e = new EntityNotFoundException(msg, Person.class, 1L); MessageResource expected = new MessageResource(); expected.setMessageType(MessageType.ERROR); expected.setMessage(e.getMessage()); expected.setCause(MessageFormat.format("{0} : {1}", e.getClz().getSimpleName(), e.getIdentifier())); MessageResource actual = unit.handle(e); assertEquals(expected, actual); }