ApiController.java

1
package edu.ucsb.cs156.gauchoride.controllers;
2
3
import org.springframework.beans.factory.annotation.Autowired;
4
5
import lombok.extern.slf4j.Slf4j;
6
import org.springframework.http.HttpStatus;
7
import org.springframework.web.bind.annotation.ExceptionHandler;
8
import org.springframework.web.bind.annotation.ResponseStatus;
9
10
import edu.ucsb.cs156.gauchoride.errors.EntityNotFoundException;
11
import edu.ucsb.cs156.gauchoride.models.CurrentUser;
12
import edu.ucsb.cs156.gauchoride.services.CurrentUserService;
13
14
import java.util.Map;
15
16
/**
17
 * Base class for all API controllers.
18
 * 
19
 * Provides a method to get the current user as well as common methods for
20
 * error handling.
21
 */
22
23
@Slf4j
24
public abstract class ApiController {
25
  @Autowired
26
  private CurrentUserService currentUserService;
27
28
  /**
29
   * Get the current user
30
   * @return the current user
31
   */
32
33
  protected CurrentUser getCurrentUser() {
34 1 1. getCurrentUser : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/ApiController::getCurrentUser → KILLED
    return currentUserService.getCurrentUser();
35
  }
36
37
38
  /**
39
   * This creates a plain old java object that can be returned as a JSON response
40
   * @return a Map object with a single key/value pair: "message" => message
41
   */
42
43
  protected Object genericMessage(String message) {
44 1 1. genericMessage : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/ApiController::genericMessage → KILLED
    return Map.of("message", message);
45
  }
46
47
   /**
48
   * This catches any EntityNotFoundExceptions and returns a 404 (NOT_FOUND) response
49
   * @return a Map object that can be returned as a JSON response
50
   */
51
  @ExceptionHandler({ EntityNotFoundException.class })
52
  @ResponseStatus(HttpStatus.NOT_FOUND)
53
  public Object handleGenericException(Throwable e) {
54 1 1. handleGenericException : replaced return value with null for edu/ucsb/cs156/gauchoride/controllers/ApiController::handleGenericException → KILLED
    return Map.of(
55
      "type", e.getClass().getSimpleName(),
56
      "message", e.getMessage()
57
    );
58
  }
59
}

Mutations

34

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

44

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

54

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

Active mutators

Tests examined


Report generated by PIT 1.7.3