UserInfoController.java

1
package edu.ucsb.cs156.happiercows.controllers;
2
3
import edu.ucsb.cs156.happiercows.entities.User;
4
import edu.ucsb.cs156.happiercows.models.CurrentUser;
5
import edu.ucsb.cs156.happiercows.repositories.UserRepository;
6
import io.swagger.v3.oas.annotations.tags.Tag;
7
import io.swagger.v3.oas.annotations.Operation;
8
9
import java.time.Instant;
10
11
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.http.ResponseEntity;
13
import org.springframework.security.access.prepost.PreAuthorize;
14
import org.springframework.web.bind.annotation.GetMapping;
15
import org.springframework.web.bind.annotation.PostMapping;
16
import org.springframework.web.bind.annotation.RequestMapping;
17
import org.springframework.web.bind.annotation.RestController;
18
19
@Tag(name="Current User Information")
20
@RequestMapping("/api/currentUser")
21
@RestController
22
public class UserInfoController extends ApiController {
23
  @Autowired
24
  private UserRepository userRepository;
25
 
26
  @Operation(summary = "Get information about current user")
27
  @PreAuthorize("hasRole('ROLE_USER')")
28
  @GetMapping("")
29
  public CurrentUser getCurrentUser() {
30 1 1. getCurrentUser : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/UserInfoController::getCurrentUser → KILLED
    return super.getCurrentUser();
31
  }
32
33
  @Operation(summary = "Update user's last online time")
34
  @PreAuthorize("hasRole('ROLE_USER')")
35
  @PostMapping("/last-online")
36
  public ResponseEntity<Instant> updateLastOnline() {
37
    User user = super.getCurrentUser().getUser();
38
    Instant timeNow = Instant.now();
39 1 1. updateLastOnline : removed call to edu/ucsb/cs156/happiercows/entities/User::setLastOnline → KILLED
    user.setLastOnline(timeNow);
40
    userRepository.save(user);
41 1 1. updateLastOnline : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/UserInfoController::updateLastOnline → KILLED
    return ResponseEntity.ok().body(timeNow);
42
  }
43
}
44

Mutations

30

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/UserInfoController::getCurrentUser → KILLED

39

1.1
Location : updateLastOnline
Killed by : edu.ucsb.cs156.happiercows.controllers.UserInfoControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.UserInfoControllerTests]/[method:currentUser__update_last_online()]
removed call to edu/ucsb/cs156/happiercows/entities/User::setLastOnline → KILLED

41

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

Active mutators

Tests examined


Report generated by PIT 1.7.3