UsersController.java

1
package edu.ucsb.cs156.happiercows.controllers;
2
3
import com.fasterxml.jackson.core.JsonProcessingException;
4
import com.fasterxml.jackson.databind.ObjectMapper;
5
6
import org.springframework.beans.factory.annotation.Autowired;
7
import org.springframework.http.ResponseEntity;
8
import org.springframework.security.access.prepost.PreAuthorize;
9
import org.springframework.web.bind.annotation.GetMapping;
10
import org.springframework.web.bind.annotation.RequestMapping;
11
import org.springframework.web.bind.annotation.RestController;
12
13
import edu.ucsb.cs156.happiercows.entities.User;
14
import edu.ucsb.cs156.happiercows.repositories.UserRepository;
15
import io.swagger.v3.oas.annotations.tags.Tag;
16
import io.swagger.v3.oas.annotations.Operation;
17
18
@Tag(name="User information (admin only)")
19
@RequestMapping("/api/admin/users")
20
@RestController
21
public class UsersController extends ApiController {
22
    @Autowired
23
    UserRepository userRepository;
24
25
    @Autowired
26
    ObjectMapper mapper;
27
28
    @Operation(summary = "Get a list of all users")
29
    @PreAuthorize("hasRole('ROLE_ADMIN')")
30
    @GetMapping("")
31
    public ResponseEntity<String> users()
32
            throws JsonProcessingException {
33
        Iterable<User> users = userRepository.findAll();
34
        String body = mapper.writeValueAsString(users);
35 1 1. users : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/UsersController::users → KILLED
        return ResponseEntity.ok().body(body);
36
    }
37
}

Mutations

35

1.1
Location : users
Killed by : edu.ucsb.cs156.happiercows.controllers.UsersControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.UsersControllerTests]/[method:users__admin_logged_in()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/UsersController::users → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3