ApiController.java

1
package edu.ucsb.cs156.rec.controllers;
2
3
import edu.ucsb.cs156.rec.errors.EntityNotFoundException;
4
import edu.ucsb.cs156.rec.models.CurrentUser;
5
import edu.ucsb.cs156.rec.services.CurrentUserService;
6
import java.util.Map;
7
import lombok.extern.slf4j.Slf4j;
8
import org.springframework.beans.factory.annotation.Autowired;
9
import org.springframework.http.HttpStatus;
10
import org.springframework.web.bind.annotation.ExceptionHandler;
11
import org.springframework.web.bind.annotation.ResponseStatus;
12
13
/** This is an abstract class that provides common functionality for all API controllers. */
14
@Slf4j
15
public abstract class ApiController {
16
  @Autowired private CurrentUserService currentUserService;
17
18
  /**
19
   * This method returns the current user.
20
   *
21
   * @return the current user
22
   */
23
  protected CurrentUser getCurrentUser() {
24 1 1. getCurrentUser : replaced return value with null for edu/ucsb/cs156/rec/controllers/ApiController::getCurrentUser → KILLED
    return currentUserService.getCurrentUser();
25
  }
26
27
  /**
28
   * This method returns a generic message.
29
   *
30
   * @param message the message
31
   * @return a map with the message
32
   */
33
  protected Object genericMessage(String message) {
34 1 1. genericMessage : replaced return value with null for edu/ucsb/cs156/rec/controllers/ApiController::genericMessage → KILLED
    return Map.of("message", message);
35
  }
36
37
  /**
38
   * This method handles the EntityNotFoundException.
39
   *
40
   * @param e the exception
41
   * @return a map with the type and message of the exception
42
   */
43
  @ExceptionHandler({EntityNotFoundException.class})
44
  @ResponseStatus(HttpStatus.NOT_FOUND)
45
  public Object handleGenericException(Throwable e) {
46 1 1. handleGenericException : replaced return value with null for edu/ucsb/cs156/rec/controllers/ApiController::handleGenericException → KILLED
    return Map.of(
47
        "type", e.getClass().getSimpleName(),
48
        "message", e.getMessage());
49
  }
50
51
  /**
52
   * This method handles the IllegalArgumentException.
53
   *
54
   * @param e the exception
55
   * @return a map with the type and message of the exception
56
   */
57
  @ExceptionHandler({IllegalArgumentException.class})
58
  @ResponseStatus(HttpStatus.BAD_REQUEST) // Change status if more appropriate
59
  public Object handleIllegalArgumentException(Throwable e) {
60 1 1. handleIllegalArgumentException : replaced return value with null for edu/ucsb/cs156/rec/controllers/ApiController::handleIllegalArgumentException → KILLED
    return Map.of(
61
        "type", e.getClass().getSimpleName(),
62
        "message", e.getMessage());
63
  }
64
}

Mutations

24

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

34

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

46

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

60

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

Active mutators

Tests examined


Report generated by PIT 1.17.0