ApiController.java

1
package edu.ucsb.cs156.organic.controllers;
2
3
import org.springframework.beans.factory.annotation.Autowired;
4
5
import edu.ucsb.cs156.organic.errors.EntityNotFoundException;
6
import edu.ucsb.cs156.organic.models.CurrentUser;
7
import edu.ucsb.cs156.organic.services.CurrentUserService;
8
import lombok.extern.slf4j.Slf4j;
9
10
import org.springframework.http.HttpStatus;
11
import org.springframework.security.access.AccessDeniedException;
12
import org.springframework.web.bind.annotation.ExceptionHandler;
13
import org.springframework.web.bind.annotation.ResponseStatus;
14
15
import com.fasterxml.jackson.databind.ObjectMapper;
16
import com.fasterxml.jackson.databind.introspect.AnnotatedMember;
17
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
18
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
19
import java.util.Map;
20
21
@Slf4j
22
public abstract class ApiController {
23
    @Autowired
24
    private CurrentUserService currentUserService;
25
26
    protected CurrentUser getCurrentUser() {
27 1 1. getCurrentUser : replaced return value with null for edu/ucsb/cs156/organic/controllers/ApiController::getCurrentUser → KILLED
        return currentUserService.getCurrentUser();
28
    }
29
30
    @ExceptionHandler({ IllegalArgumentException.class })
31
    @ResponseStatus(HttpStatus.BAD_REQUEST)
32
    public Object handleIllegalArgumentException(Throwable e) {
33
        Map<String, String> map = Map.of(
34
                "type", e.getClass().getSimpleName(),
35
                "message", e.getMessage());
36
        log.error("Exception thrown: {}", map);
37 1 1. handleIllegalArgumentException : replaced return value with null for edu/ucsb/cs156/organic/controllers/ApiController::handleIllegalArgumentException → KILLED
        return map;
38
    }
39
40
    @ExceptionHandler({ EntityNotFoundException.class })
41
    @ResponseStatus(HttpStatus.NOT_FOUND)
42
    public Object handleGenericException(Throwable e) {
43 1 1. handleGenericException : replaced return value with null for edu/ucsb/cs156/organic/controllers/ApiController::handleGenericException → KILLED
        return Map.of(
44
                "type", e.getClass().getSimpleName(),
45
                "message", e.getMessage());
46
    }
47
48
    @ExceptionHandler({ AccessDeniedException.class })
49
    @ResponseStatus(HttpStatus.FORBIDDEN)
50
    public Object handleAccessDeniedException(Throwable e) {
51 1 1. handleAccessDeniedException : replaced return value with null for edu/ucsb/cs156/organic/controllers/ApiController::handleAccessDeniedException → KILLED
        return Map.of(
52
                "type", e.getClass().getSimpleName(),
53
                "message", e.getMessage());
54
    }
55
56
    private ObjectMapper mapper;
57
58
    /**
59
     * Special ObjectMapper that ignores Mockito mocks
60
     * 
61
     * @return ObjectMapper mapper
62
     */
63
    public ObjectMapper getMapper() {
64 1 1. getMapper : replaced return value with null for edu/ucsb/cs156/organic/controllers/ApiController::getMapper → KILLED
        return mapper;
65
    }
66
67
    public ApiController() {
68
        mapper = mapperThatIgnoresMockitoMocks();
69
    }
70
71
    public static ObjectMapper mapperThatIgnoresMockitoMocks() {
72
        ObjectMapper mapper = new ObjectMapper();
73
        mapper.registerModule(new JavaTimeModule());
74
        mapper.setAnnotationIntrospector(new JacksonAnnotationIntrospector() {
75
            @Override
76
            public boolean hasIgnoreMarker(final AnnotatedMember m) {
77 3 1. hasIgnoreMarker : negated conditional → KILLED
2. hasIgnoreMarker : negated conditional → KILLED
3. hasIgnoreMarker : replaced boolean return with true for edu/ucsb/cs156/organic/controllers/ApiController$1::hasIgnoreMarker → KILLED
                return super.hasIgnoreMarker(m) || m.getName().contains("Mockito");
78
            }
79
        });
80 1 1. mapperThatIgnoresMockitoMocks : replaced return value with null for edu/ucsb/cs156/organic/controllers/ApiController::mapperThatIgnoresMockitoMocks → KILLED
        return mapper;
81
    }
82
83
    protected Object genericMessage(String message) {
84 1 1. genericMessage : replaced return value with null for edu/ucsb/cs156/organic/controllers/ApiController::genericMessage → KILLED
        return Map.of("message", message);
85
    }
86
}

Mutations

27

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

37

1.1
Location : handleIllegalArgumentException
Killed by : edu.ucsb.cs156.organic.controllers.JobsControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.organic.controllers.JobsControllerTests]/[method:admin_launch_test_job_with_invalid_parameter_60001()]
replaced return value with null for edu/ucsb/cs156/organic/controllers/ApiController::handleIllegalArgumentException → KILLED

43

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

51

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

64

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

77

1.1
Location : hasIgnoreMarker
Killed by : edu.ucsb.cs156.organic.controllers.UserInfoControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.organic.controllers.UserInfoControllerTests]/[method:currentUser__logged_in()]
negated conditional → KILLED

2.2
Location : hasIgnoreMarker
Killed by : edu.ucsb.cs156.organic.controllers.UserInfoControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.organic.controllers.UserInfoControllerTests]/[method:currentUser__logged_in()]
negated conditional → KILLED

3.3
Location : hasIgnoreMarker
Killed by : edu.ucsb.cs156.organic.controllers.UserInfoControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.organic.controllers.UserInfoControllerTests]/[method:currentUser__logged_in()]
replaced boolean return with true for edu/ucsb/cs156/organic/controllers/ApiController$1::hasIgnoreMarker → KILLED

80

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

84

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

Active mutators

Tests examined


Report generated by PIT 1.7.3