ApiExceptionHandler.java

1
package com.edtech.controller;
2
3
import com.edtech.dto.ErrorResponse;
4
import com.edtech.service.DuplicateEmailException;
5
import com.edtech.service.InvalidCredentialsException;
6
import com.edtech.service.InvalidInstitutionalEmailException;
7
import jakarta.validation.ConstraintViolationException;
8
import org.springframework.http.HttpStatus;
9
import org.springframework.http.ResponseEntity;
10
import org.springframework.web.bind.MethodArgumentNotValidException;
11
import org.springframework.web.bind.annotation.ExceptionHandler;
12
import org.springframework.web.bind.annotation.RestControllerAdvice;
13
14
/** Documentação para ApiExceptionHandler. */
15
@RestControllerAdvice
16
public class ApiExceptionHandler {
17
18
  @ExceptionHandler(DuplicateEmailException.class)
19
  public ResponseEntity<ErrorResponse> handleDuplicateEmail(DuplicateEmailException exception) {
20 1 1. handleDuplicateEmail : replaced return value with null for com/edtech/controller/ApiExceptionHandler::handleDuplicateEmail → KILLED
    return ResponseEntity.status(HttpStatus.CONFLICT)
21
        .body(new ErrorResponse("email_already_registered", exception.getMessage()));
22
  }
23
24
  @ExceptionHandler(InvalidInstitutionalEmailException.class)
25
  public ResponseEntity<ErrorResponse> handleInvalidInstitutionalEmail(
26
      InvalidInstitutionalEmailException exception) {
27 1 1. handleInvalidInstitutionalEmail : replaced return value with null for com/edtech/controller/ApiExceptionHandler::handleInvalidInstitutionalEmail → KILLED
    return ResponseEntity.badRequest()
28
        .body(new ErrorResponse("invalid_institutional_email", exception.getMessage()));
29
  }
30
31
  @ExceptionHandler(InvalidCredentialsException.class)
32
  public ResponseEntity<ErrorResponse> handleInvalidCredentials() {
33 1 1. handleInvalidCredentials : replaced return value with null for com/edtech/controller/ApiExceptionHandler::handleInvalidCredentials → KILLED
    return ResponseEntity.status(HttpStatus.UNAUTHORIZED)
34
        .body(new ErrorResponse("invalid_credentials", "Credenciais inválidas."));
35
  }
36
37
  @ExceptionHandler({MethodArgumentNotValidException.class, ConstraintViolationException.class})
38
  public ResponseEntity<ErrorResponse> handleValidationException(Exception exception) {
39 1 1. handleValidationException : replaced return value with null for com/edtech/controller/ApiExceptionHandler::handleValidationException → KILLED
    return ResponseEntity.badRequest()
40
        .body(new ErrorResponse("invalid_request", "Verifique os dados enviados."));
41
  }
42
43
  /** Javadoc. */
44
  @ExceptionHandler(org.springframework.dao.DataIntegrityViolationException.class)
45
  public ResponseEntity<ErrorResponse> handleDataIntegrityViolation(
46
      org.springframework.dao.DataIntegrityViolationException exception) {
47 1 1. handleDataIntegrityViolation : replaced return value with null for com/edtech/controller/ApiExceptionHandler::handleDataIntegrityViolation → NO_COVERAGE
    return ResponseEntity.status(HttpStatus.CONFLICT)
48
        .body(
49
            new ErrorResponse(
50
                "email_already_registered", "Conflito de dados. Verifique unicidade."));
51
  }
52
}

Mutations

20

1.1
Location : handleDuplicateEmail
Killed by : com.edtech.controller.ApiExceptionHandlerTest.[engine:junit-jupiter]/[class:com.edtech.controller.ApiExceptionHandlerTest]/[method:handleDuplicateEmail_ReturnsConflict()]
replaced return value with null for com/edtech/controller/ApiExceptionHandler::handleDuplicateEmail → KILLED

27

1.1
Location : handleInvalidInstitutionalEmail
Killed by : com.edtech.controller.ApiExceptionHandlerTest.[engine:junit-jupiter]/[class:com.edtech.controller.ApiExceptionHandlerTest]/[method:handleInvalidInstitutionalEmail_ReturnsBadRequest()]
replaced return value with null for com/edtech/controller/ApiExceptionHandler::handleInvalidInstitutionalEmail → KILLED

33

1.1
Location : handleInvalidCredentials
Killed by : com.edtech.controller.ApiExceptionHandlerTest.[engine:junit-jupiter]/[class:com.edtech.controller.ApiExceptionHandlerTest]/[method:handleInvalidCredentials_ReturnsUnauthorized()]
replaced return value with null for com/edtech/controller/ApiExceptionHandler::handleInvalidCredentials → KILLED

39

1.1
Location : handleValidationException
Killed by : com.edtech.controller.ApiExceptionHandlerTest.[engine:junit-jupiter]/[class:com.edtech.controller.ApiExceptionHandlerTest]/[method:handleValidationException_ReturnsBadRequest()]
replaced return value with null for com/edtech/controller/ApiExceptionHandler::handleValidationException → KILLED

47

1.1
Location : handleDataIntegrityViolation
Killed by : none
replaced return value with null for com/edtech/controller/ApiExceptionHandler::handleDataIntegrityViolation → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.16.1