GlobalExceptionHandler extends ResponseEntityExceptionHandler { @ExceptionHandler({NotSupportedWithLdapException.class}) public ResponseEntity<Object> handleNotSupportedWithLdapException(Exception exception, WebRequest request) { ApiError apiError = new ApiError(HttpStatus.BAD_REQUEST, "Endpoint is not supported in the current configuration.", exception.getLocalizedMessage()); return new ResponseEntity<>(apiError, new HttpHeaders(), apiError.getStatus()); }  @ExceptionHandler({NotSupportedWithLdapException.class}) ResponseEntity<Object> handleNotSupportedWithLdapException(Exception exception, WebRequest request); @ExceptionHandler({Exception.class}) ResponseEntity<Object> handleAll(Exception exception, WebRequest request);  }
@Test public void handleNotSupportedWithLdapException() throws Exception { mockMvc.perform(get("/notSupportedWithLdapException")) .andExpect(status().isBadRequest()) .andExpect(content().contentType(APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.message").value("Endpoint is not supported in the current configuration.")) .andExpect(jsonPath("$.debugMessage").value("Endpoint is not supported when LDAP authentication is used.")); }