Coverage Summary for Class: ConstraintViolation (com.app.SuperMarketSystem.exception)

Class Class, % Method, % Line, %
ConstraintViolation 100% (1/1) 50% (1/2) 50% (1/2)


1 package com.app.SuperMarketSystem.exception; 2  3 import org.hibernate.exception.ConstraintViolationException; 4 import org.springframework.http.HttpStatus; 5 import org.springframework.http.ResponseEntity; 6 import org.springframework.web.bind.annotation.ControllerAdvice; 7 import org.springframework.web.bind.annotation.ExceptionHandler; 8  9 @ControllerAdvice 10 public class ConstraintViolation { 11  12  @ExceptionHandler(ConstraintViolationException.class) 13  public ResponseEntity<Object> constraintViolation(Exception e) { 14  return new ResponseEntity<>(e.getLocalizedMessage(), HttpStatus.BAD_REQUEST); 15  } 16 }