CurrentUserService.java

1
package edu.ucsb.cs156.example.services;
2
3
import edu.ucsb.cs156.example.entities.User;
4
import edu.ucsb.cs156.example.models.CurrentUser;
5
6
import java.util.Collection;
7
import java.util.List;
8
9
import org.springframework.security.core.GrantedAuthority;
10
11
/**
12
 * This is a service that provides information about the current user.
13
 *
14
 * It is an abstract class because we have different implementations for testing
15
 * and production.
16
 * 
17
 */
18
public abstract class CurrentUserService {
19
20
  /**
21
   * This method returns the current user as a User object.
22
   * 
23
   * @return the current user
24
   */
25
  public abstract User getUser();
26
27
  /**
28
   * This method returns the current user as a CurrentUser object
29
   * 
30
   * @return the current user
31
   */
32
  public abstract CurrentUser getCurrentUser();
33
34
  /**
35
   * This method returns the roles of the current user.
36
   * 
37
   * @return a collection of roles
38
   */
39
  public abstract Collection<? extends GrantedAuthority> getRoles();
40
41
  /**
42
   * This method returns whether the current user is logged in.
43
   * 
44
   * @return whether the current user is logged in
45
   */
46
47
  public final boolean isLoggedIn() {
48 2 1. isLoggedIn : negated conditional → KILLED
2. isLoggedIn : replaced boolean return with true for edu/ucsb/cs156/example/services/CurrentUserService::isLoggedIn → KILLED
    return getUser() != null;
49
  }
50
51
52
  /**
53
   * This method returns the roles of the current user as a sorted list of strings.
54
   * 
55
   * @return a collection of roles
56
   */
57
  public  List<String> getRolesSorted() {
58
    Collection<? extends GrantedAuthority> authorities = getRoles();
59
    List<String> roles = authorities.stream()
60
        .map(GrantedAuthority::getAuthority)
61
        .sorted()
62
        .toList();
63 1 1. getRolesSorted : replaced return value with Collections.emptyList for edu/ucsb/cs156/example/services/CurrentUserService::getRolesSorted → KILLED
    return roles;
64
  }
65
}

Mutations

48

1.1
Location : isLoggedIn
Killed by : edu.ucsb.cs156.example.services.CurrentUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.services.CurrentUserServiceTests]/[method:test_isLoggedIn_returns_true()]
negated conditional → KILLED

2.2
Location : isLoggedIn
Killed by : edu.ucsb.cs156.example.controllers.HomepageControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HomepageControllerTests]/[method:test_homepage_not_logged_in()]
replaced boolean return with true for edu/ucsb/cs156/example/services/CurrentUserService::isLoggedIn → KILLED

63

1.1
Location : getRolesSorted
Killed by : edu.ucsb.cs156.example.controllers.HomepageControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.example.controllers.HomepageControllerTests]/[method:test_homepage_admin_logged_in()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/example/services/CurrentUserService::getRolesSorted → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0