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
import org.springframework.http.ResponseEntity;
11
12
import edu.ucsb.cs156.frontiers.errors.EntityNotFoundException;
13
import edu.ucsb.cs156.frontiers.models.CurrentUser;
14
import edu.ucsb.cs156.frontiers.services.CurrentUserService;
15
16
import java.util.Map;
17
18
19
/**
20
 * This is an abstract class that provides common functionality for all API controllers.
21
 */
22
23
@Slf4j
24
public abstract class ApiController {
25
  @Autowired
26
  private CurrentUserService currentUserService;
27
28
  /**
29
   * This method returns the current user.
30
   * @return the current user
31
   */
32
  protected CurrentUser getCurrentUser() {
33 1 1. getCurrentUser : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/ApiController::getCurrentUser → KILLED
    return currentUserService.getCurrentUser();
34
  }
35
36
  /**
37
   * This method returns a generic message.
38
   * @param message the message
39
   * @return a map with the message
40
   */
41
  protected Object genericMessage(String message) {
42 1 1. genericMessage : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/ApiController::genericMessage → KILLED
    return Map.of("message", message);
43
  }
44
45
  /**
46
   * This method handles the EntityNotFoundException.
47
   * @param e the exception
48
   * @return a map with the type and message of the exception
49
   */
50
  @ExceptionHandler({ EntityNotFoundException.class })
51
  @ResponseStatus(HttpStatus.NOT_FOUND)
52
  public Object handleEntityNotFoundException(Throwable e) {
53 1 1. handleEntityNotFoundException : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/ApiController::handleEntityNotFoundException → KILLED
    return Map.of(
54
      "type", e.getClass().getSimpleName(),
55
      "message", e.getMessage()
56
    );
57
  }
58
59
  /**
60
   * This method handles the NoLinkedOrganizationException.
61
   * @param e the exception
62
   * @return a map with the type and message of the exception
63
   */
64
  @ExceptionHandler({ NoLinkedOrganizationException.class })
65
  @ResponseStatus(HttpStatus.BAD_REQUEST)
66
  public Object handleNoLinkedOrgException(Throwable e) {
67 1 1. handleNoLinkedOrgException : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/ApiController::handleNoLinkedOrgException → KILLED
    return Map.of(
68
            "type", e.getClass().getSimpleName(),
69
            "message", e.getMessage()
70
    );
71
  }
72
73
  /**
74
   * This method handles the UnsupportedOperationException.
75
   * @param e the exception
76
   * @return a map with the message of the exception
77
   */
78
  @ExceptionHandler(UnsupportedOperationException.class)
79
  public ResponseEntity<Map<String, String>> handleUnsupportedOperation(UnsupportedOperationException e) {
80 1 1. handleUnsupportedOperation : replaced return value with null for edu/ucsb/cs156/frontiers/controllers/ApiController::handleUnsupportedOperation → KILLED
      return ResponseEntity.status(HttpStatus.FORBIDDEN)
81
              .body(Map.of("message", e.getMessage()));
82
  }
83
}

Mutations

33

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

42

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

53

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

67

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

80

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

Active mutators

Tests examined


Report generated by PIT 1.17.0