ApiController.java

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

Mutations

29

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

38

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

49

1.1
Location : handleGenericException
Killed by : edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.UCSBOrganizationControllerTests]/[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/example/controllers/ApiController::handleGenericException → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0