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

Mutations

32

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

41

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

52

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

66

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

79

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