ApiController.java

1
package edu.ucsb.cs156.happiercows.controllers;
2
3
import edu.ucsb.cs156.happiercows.errors.EntityNotFoundException;
4
import edu.ucsb.cs156.happiercows.errors.NoCowsException;
5
import edu.ucsb.cs156.happiercows.errors.NotEnoughMoneyException;
6
import org.springframework.beans.factory.annotation.Autowired;
7
8
import edu.ucsb.cs156.happiercows.models.CurrentUser;
9
import edu.ucsb.cs156.happiercows.services.CurrentUserService;
10
import org.springframework.http.HttpStatus;
11
import org.springframework.web.bind.annotation.ExceptionHandler;
12
import org.springframework.web.bind.annotation.ResponseStatus;
13
14
import java.util.Map;
15
16
public abstract class ApiController {
17
  @Autowired
18
  private CurrentUserService currentUserService;
19
20
  protected CurrentUser getCurrentUser() {
21 1 1. getCurrentUser : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ApiController::getCurrentUser → KILLED
    return currentUserService.getCurrentUser();
22
  }
23
  
24
  protected Object genericMessage(String message) {
25 1 1. genericMessage : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ApiController::genericMessage → KILLED
    return Map.of("message", message);
26
  }
27
28
  @ExceptionHandler({ EntityNotFoundException.class })
29
  @ResponseStatus(HttpStatus.NOT_FOUND)
30
  public Object handleGenericException(Throwable e) {
31 1 1. handleGenericException : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ApiController::handleGenericException → KILLED
    return Map.of(
32
      "type", e.getClass().getSimpleName(),
33
      "message", e.getMessage()
34
    );
35
  }
36
37
  @ExceptionHandler({ NoCowsException.class, NotEnoughMoneyException.class})
38
  @ResponseStatus(HttpStatus.BAD_REQUEST)
39
  public Object handleBadRequest(Throwable e) {
40 1 1. handleBadRequest : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ApiController::handleBadRequest → KILLED
    return Map.of(
41
      "type", e.getClass().getSimpleName(),
42
      "message", e.getMessage()
43
    );
44
  }
45
}

Mutations

21

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

25

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

31

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

40

1.1
Location : handleBadRequest
Killed by : edu.ucsb.cs156.happiercows.controllers.UserCommonsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.UserCommonsControllerTests]/[method:test_SellCow_commons_exists_no_cow_to_sell()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/ApiController::handleBadRequest → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3