@Test void canHandleConstraintViolationExceptions() { final ConstraintViolationException exception = new ConstraintViolationException("cve", null); final ResponseEntity<GeniePreconditionException> response = this.mapper.handleConstraintViolation(exception); Assertions.assertThat(response.getStatusCode()).isEqualByComparingTo(HttpStatus.PRECONDITION_FAILED); Mockito .verify(this.registry, Mockito.times(1)) .counter( GenieExceptionMapper.CONTROLLER_EXCEPTION_COUNTER_NAME, Sets.newHashSet( Tag.of(MetricsConstants.TagKeys.EXCEPTION_CLASS, exception.getClass().getCanonicalName()) ) ); Mockito .verify(this.counter, Mockito.times(1)) .increment(); }
@ExceptionHandler(ConstraintViolationException.class) public ResponseEntity<GeniePreconditionException> handleConstraintViolation( final ConstraintViolationException cve ) { this.countExceptionAndLog(cve); return new ResponseEntity<>( new GeniePreconditionException(cve.getMessage(), cve), HttpStatus.PRECONDITION_FAILED ); }
GenieExceptionMapper { @ExceptionHandler(ConstraintViolationException.class) public ResponseEntity<GeniePreconditionException> handleConstraintViolation( final ConstraintViolationException cve ) { this.countExceptionAndLog(cve); return new ResponseEntity<>( new GeniePreconditionException(cve.getMessage(), cve), HttpStatus.PRECONDITION_FAILED ); } }
GenieExceptionMapper { @ExceptionHandler(ConstraintViolationException.class) public ResponseEntity<GeniePreconditionException> handleConstraintViolation( final ConstraintViolationException cve ) { this.countExceptionAndLog(cve); return new ResponseEntity<>( new GeniePreconditionException(cve.getMessage(), cve), HttpStatus.PRECONDITION_FAILED ); } @Autowired  GenieExceptionMapper(final MeterRegistry registry); }
GenieExceptionMapper { @ExceptionHandler(ConstraintViolationException.class) public ResponseEntity<GeniePreconditionException> handleConstraintViolation( final ConstraintViolationException cve ) { this.countExceptionAndLog(cve); return new ResponseEntity<>( new GeniePreconditionException(cve.getMessage(), cve), HttpStatus.PRECONDITION_FAILED ); } @Autowired  GenieExceptionMapper(final MeterRegistry registry); @ExceptionHandler(GenieException.class) ResponseEntity<GenieException> handleGenieException(final GenieException e); @ExceptionHandler(GenieRuntimeException.class) ResponseEntity<GenieRuntimeException> handleGenieRuntimeException(final GenieRuntimeException e); @ExceptionHandler(GenieCheckedException.class) ResponseEntity<GenieCheckedException> handleGenieCheckedException(final GenieCheckedException e); @ExceptionHandler(ConstraintViolationException.class) ResponseEntity<GeniePreconditionException> handleConstraintViolation(
        final ConstraintViolationException cve
    ); @ExceptionHandler(MethodArgumentNotValidException.class) ResponseEntity<GeniePreconditionException> handleMethodArgumentNotValidException(
        final MethodArgumentNotValidException e
    ); }
GenieExceptionMapper { @ExceptionHandler(ConstraintViolationException.class) public ResponseEntity<GeniePreconditionException> handleConstraintViolation( final ConstraintViolationException cve ) { this.countExceptionAndLog(cve); return new ResponseEntity<>( new GeniePreconditionException(cve.getMessage(), cve), HttpStatus.PRECONDITION_FAILED ); } @Autowired  GenieExceptionMapper(final MeterRegistry registry); @ExceptionHandler(GenieException.class) ResponseEntity<GenieException> handleGenieException(final GenieException e); @ExceptionHandler(GenieRuntimeException.class) ResponseEntity<GenieRuntimeException> handleGenieRuntimeException(final GenieRuntimeException e); @ExceptionHandler(GenieCheckedException.class) ResponseEntity<GenieCheckedException> handleGenieCheckedException(final GenieCheckedException e); @ExceptionHandler(ConstraintViolationException.class) ResponseEntity<GeniePreconditionException> handleConstraintViolation(
        final ConstraintViolationException cve
    ); @ExceptionHandler(MethodArgumentNotValidException.class) ResponseEntity<GeniePreconditionException> handleMethodArgumentNotValidException(
        final MethodArgumentNotValidException e
    );  }