ApiController.java

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

Mutations

31

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

40

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

51

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

65

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

Active mutators

Tests examined


Report generated by PIT 1.17.0