ApiController.java

1
package edu.ucsb.cs156.dining.controllers;
2
3
import edu.ucsb.cs156.dining.errors.EntityNotFoundException;
4
import edu.ucsb.cs156.dining.models.CurrentUser;
5
import edu.ucsb.cs156.dining.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/dining/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/dining/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/dining/controllers/ApiController::handleGenericException → KILLED
    return Map.of(
47
        "type", e.getClass().getSimpleName(),
48
        "message", e.getMessage());
49
  }
50
51
  /**
52
   * This method handles the UnsupportedOperationException for forbidden operations.
53
   *
54
   * @param e the exception
55
   * @return a map with the message of the exception
56
   */
57
  @ExceptionHandler({UnsupportedOperationException.class})
58
  @ResponseStatus(HttpStatus.FORBIDDEN)
59
  public Object handleUnsupportedOperationException(Throwable e) {
60 1 1. handleUnsupportedOperationException : replaced return value with null for edu/ucsb/cs156/dining/controllers/ApiController::handleUnsupportedOperationException → KILLED
    return Map.of("message", e.getMessage());
61
  }
62
}

Mutations

24

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

34

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

46

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

60

1.1
Location : handleUnsupportedOperationException
Killed by : edu.ucsb.cs156.dining.controllers.AdminsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.dining.controllers.AdminsControllerTests]/[method:admin_cannot_delete_admin_from_admin_emails_list()]
replaced return value with null for edu/ucsb/cs156/dining/controllers/ApiController::handleUnsupportedOperationException → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0