ApiController.java

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

Mutations

30

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

39

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

50

1.1
Location : handleGenericException
Killed by : edu.ucsb.cs156.rec.controllers.RestaurantsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.rec.controllers.RestaurantsControllerTests]/[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

64

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

Active mutators

Tests examined


Report generated by PIT 1.17.0