@Test public void onException() { // Mock: request HttpServletRequest request = mock(HttpServletRequest.class); // Mock: error handler when(errorHandler.handleError( any(HttpServletRequest.class), any(Locale.class), any(Exception.class))) .thenReturn(new ErrorMessage("xxx", "Error message")); // Call ResponseEntity<String> entity = get.onException(request, Locale.ENGLISH, new ApplicationNotFoundException(APP)); assertNotNull(entity); assertEquals( "An error has occurred.\nMessage: Error message\nReference: xxx", entity.getBody()); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode()); }