UpdateUserService.java

1
package edu.ucsb.cs156.frontiers.services;
2
3
import edu.ucsb.cs156.frontiers.entities.CourseStaff;
4
import edu.ucsb.cs156.frontiers.entities.RosterStudent;
5
import edu.ucsb.cs156.frontiers.entities.User;
6
import edu.ucsb.cs156.frontiers.repositories.CourseStaffRepository;
7
import edu.ucsb.cs156.frontiers.repositories.RosterStudentRepository;
8
import edu.ucsb.cs156.frontiers.repositories.UserRepository;
9
import java.util.List;
10
import java.util.Optional;
11
import java.util.Set;
12
import org.springframework.beans.factory.annotation.Autowired;
13
import org.springframework.stereotype.Service;
14
15
@Service
16
public class UpdateUserService {
17
18
  @Autowired private UserRepository userRepository;
19
20
  @Autowired private RosterStudentRepository rosterStudentRepository;
21
  @Autowired private CourseStaffRepository courseStaffRepository;
22
23
  /**
24
   * This method attaches the RosterStudents to the User based on their email.
25
   *
26
   * @param user The user to whom the RosterStudents will be attached
27
   */
28
  public void attachRosterStudents(User user) {
29
    List<RosterStudent> matchedStudents = rosterStudentRepository.findAllByEmail(user.getEmail());
30 2 1. attachRosterStudents : negated conditional → KILLED
2. attachRosterStudents : changed conditional boundary → KILLED
    for (int i = 0; i < matchedStudents.size(); i++) {
31
      RosterStudent matchedStudent = matchedStudents.get(i);
32 1 1. attachRosterStudents : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setUser → KILLED
      matchedStudent.setUser(user);
33
    }
34
    rosterStudentRepository.saveAll(matchedStudents);
35
  }
36
37
  /**
38
   * This method attaches the CourseStaff to the User based on their email.
39
   *
40
   * @param user The user to whom the CourseStaff will be attached
41
   */
42
  public void attachCourseStaff(User user) {
43
    List<CourseStaff> matchedStaff = courseStaffRepository.findAllByEmail(user.getEmail());
44
    for (CourseStaff matched : matchedStaff) {
45 1 1. attachCourseStaff : removed call to edu/ucsb/cs156/frontiers/entities/CourseStaff::setUser → KILLED
      matched.setUser(user);
46
    }
47
    courseStaffRepository.saveAll(matchedStaff);
48
  }
49
50
  /** attach roster students for all Users */
51
  public void attachRosterStudentsAllUsers() {
52
    Iterable<User> allUsers = userRepository.findAll();
53
    for (User user : allUsers) {
54 1 1. attachRosterStudentsAllUsers : removed call to edu/ucsb/cs156/frontiers/services/UpdateUserService::attachRosterStudents → KILLED
      attachRosterStudents(user);
55
    }
56
  }
57
58
  /** This method attaches a SingleRoster student to the User based on their email. */
59
  public void attachUserToRosterStudent(RosterStudent rosterStudent) {
60
    String email = rosterStudent.getEmail();
61
    Optional<User> optionalUser = userRepository.findByEmail(email);
62 1 1. attachUserToRosterStudent : negated conditional → KILLED
    if (optionalUser.isPresent()) {
63
      User matchedUser = optionalUser.get();
64 1 1. attachUserToRosterStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setUser → KILLED
      rosterStudent.setUser(matchedUser);
65
      rosterStudentRepository.save(rosterStudent);
66
    }
67
  }
68
69
  /** This method attaches a SingleRoster student to the User based on their email. */
70
  public void attachUsersToRosterStudents(Set<RosterStudent> rosterStudents) {
71
    for (RosterStudent matchedStudent : rosterStudents) {
72 1 1. attachUsersToRosterStudents : removed call to edu/ucsb/cs156/frontiers/services/UpdateUserService::attachUserToRosterStudent → KILLED
      attachUserToRosterStudent(matchedStudent);
73
    }
74
  }
75
76
  /** This method attaches a Single Course Staff member to the User based on their email. */
77
  public void attachUserToCourseStaff(CourseStaff courseStaff) {
78
    String email = courseStaff.getEmail();
79
    Optional<User> optionalUser = userRepository.findByEmail(email);
80 1 1. attachUserToCourseStaff : negated conditional → KILLED
    if (optionalUser.isPresent()) {
81
      User matchedUser = optionalUser.get();
82 1 1. attachUserToCourseStaff : removed call to edu/ucsb/cs156/frontiers/entities/CourseStaff::setUser → KILLED
      courseStaff.setUser(matchedUser);
83
      courseStaffRepository.save(courseStaff);
84
    }
85
  }
86
}

Mutations

30

1.1
Location : attachRosterStudents
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testAttachRosterStudents()]
negated conditional → KILLED

2.2
Location : attachRosterStudents
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testAttachRosterStudents()]
changed conditional boundary → KILLED

32

1.1
Location : attachRosterStudents
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testAttachRosterStudents()]
removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setUser → KILLED

45

1.1
Location : attachCourseStaff
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testAttachCourseStaff()]
removed call to edu/ucsb/cs156/frontiers/entities/CourseStaff::setUser → KILLED

54

1.1
Location : attachRosterStudentsAllUsers
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testAttachRosterStudentsAllUsers()]
removed call to edu/ucsb/cs156/frontiers/services/UpdateUserService::attachRosterStudents → KILLED

62

1.1
Location : attachUserToRosterStudent
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testAttachUserToRosterStudent_userExists()]
negated conditional → KILLED

64

1.1
Location : attachUserToRosterStudent
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testAttachUserToRosterStudent_userExists()]
removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setUser → KILLED

72

1.1
Location : attachUsersToRosterStudents
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testAttachUsesrToRosterStudents_userExists()]
removed call to edu/ucsb/cs156/frontiers/services/UpdateUserService::attachUserToRosterStudent → KILLED

80

1.1
Location : attachUserToCourseStaff
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testAttachUserToCourseStaff_userDoesNotExist()]
negated conditional → KILLED

82

1.1
Location : attachUserToCourseStaff
Killed by : edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.UpdateUserServiceTests]/[method:testAttachUserToCourseStaff_userExists()]
removed call to edu/ucsb/cs156/frontiers/entities/CourseStaff::setUser → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0