ApiController.java

1
package edu.ucsb.cs156.courses.controllers;
2
3
import edu.ucsb.cs156.courses.errors.BadEnrollCdException;
4
import edu.ucsb.cs156.courses.errors.EntityNotFoundException;
5
import edu.ucsb.cs156.courses.models.CurrentUser;
6
import edu.ucsb.cs156.courses.services.CurrentUserService;
7
import java.util.Map;
8
import lombok.extern.slf4j.Slf4j;
9
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.http.HttpStatus;
11
import org.springframework.web.bind.annotation.ExceptionHandler;
12
import org.springframework.web.bind.annotation.ResponseStatus;
13
14
@Slf4j
15
public abstract class ApiController {
16
17
  @Autowired private CurrentUserService currentUserService;
18
19
  protected CurrentUser getCurrentUser() {
20 1 1. getCurrentUser : replaced return value with null for edu/ucsb/cs156/courses/controllers/ApiController::getCurrentUser → KILLED
    return currentUserService.getCurrentUser();
21
  }
22
23
  protected Object genericMessage(String message) {
24 1 1. genericMessage : replaced return value with null for edu/ucsb/cs156/courses/controllers/ApiController::genericMessage → KILLED
    return Map.of("message", message);
25
  }
26
27
  @ExceptionHandler({EntityNotFoundException.class, BadEnrollCdException.class})
28
  @ResponseStatus(HttpStatus.NOT_FOUND)
29
  public Object handleGenericException(Throwable e) {
30 1 1. handleGenericException : replaced return value with null for edu/ucsb/cs156/courses/controllers/ApiController::handleGenericException → KILLED
    return Map.of(
31
        "type", e.getClass().getSimpleName(),
32
        "message", e.getMessage());
33
  }
34
35
  @ExceptionHandler({IllegalArgumentException.class})
36
  @ResponseStatus(HttpStatus.BAD_REQUEST)
37
  public Object handleIllegalArgumentException(Throwable e) {
38 1 1. handleIllegalArgumentException : replaced return value with null for edu/ucsb/cs156/courses/controllers/ApiController::handleIllegalArgumentException → KILLED
    return Map.of(
39
        "type", e.getClass().getSimpleName(),
40
        "message", e.getMessage());
41
  }
42
}

Mutations

20

1.1
Location : getCurrentUser
Killed by : edu.ucsb.cs156.courses.controllers.UserInfoControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.UserInfoControllerTests]/[method:currentUser__logged_in()]
replaced return value with null for edu/ucsb/cs156/courses/controllers/ApiController::getCurrentUser → KILLED

24

1.1
Location : genericMessage
Killed by : edu.ucsb.cs156.courses.controllers.UCSBSubjectsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.UCSBSubjectsControllerTests]/[method:api_todos__admin_logged_in__delete_all()]
replaced return value with null for edu/ucsb/cs156/courses/controllers/ApiController::genericMessage → KILLED

30

1.1
Location : handleGenericException
Killed by : edu.ucsb.cs156.courses.controllers.UCSBSubjectsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.UCSBSubjectsControllerTests]/[method:api_todos__user_logged_in__delete_by_id_that_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/courses/controllers/ApiController::handleGenericException → KILLED

38

1.1
Location : handleIllegalArgumentException
Killed by : edu.ucsb.cs156.courses.controllers.PersonalSchedulesControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.PersonalSchedulesControllerTests]/[method:api_schedules__user_logged_in__cannot_post_long_name()]
replaced return value with null for edu/ucsb/cs156/courses/controllers/ApiController::handleIllegalArgumentException → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0