StudentDropService.java

1
package edu.ucsb.cs156.frontiers.services;
2
3
import edu.ucsb.cs156.frontiers.entities.RosterStudent;
4
import edu.ucsb.cs156.frontiers.entities.TeamMember;
5
import edu.ucsb.cs156.frontiers.repositories.TeamMemberRepository;
6
import jakarta.persistence.EntityManager;
7
import java.util.ArrayList;
8
import java.util.List;
9
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.stereotype.Service;
11
import org.springframework.transaction.annotation.Transactional;
12
13
@Service
14
public class StudentDropService {
15
16
  @Autowired private TeamMemberRepository teamMemberRepository;
17
18
  @Autowired private EntityManager entityManager;
19
20
  /** Handles cleanup when a student drops the course or is deleted from the roster. */
21
  @Transactional
22
  public void dropStudent(RosterStudent rosterStudent) {
23 2 1. dropStudent : negated conditional → KILLED
2. dropStudent : negated conditional → KILLED
    if (rosterStudent.getTeamMembers() == null || rosterStudent.getTeamMembers().isEmpty()) {
24
      return;
25
    }
26
    List<TeamMember> teamMembers = new ArrayList<>(rosterStudent.getTeamMembers());
27
    for (TeamMember teamMember : teamMembers) {
28
      teamMember.getTeam().getTeamMembers().remove(teamMember);
29
    }
30 1 1. dropStudent : removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setTeamMembers → KILLED
    rosterStudent.setTeamMembers(new ArrayList<>());
31
    // Keep the required team reference intact until the membership row is deleted.
32 1 1. dropStudent : removed call to edu/ucsb/cs156/frontiers/repositories/TeamMemberRepository::deleteAllInBatch → KILLED
    teamMemberRepository.deleteAllInBatch(teamMembers);
33
    // Bulk deletion leaves these entities managed; detach them before deleting the student.
34 1 1. dropStudent : removed call to java/util/List::forEach → KILLED
    teamMembers.forEach(entityManager::detach);
35
  }
36
}

Mutations

23

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

2.2
Location : dropStudent
Killed by : edu.ucsb.cs156.frontiers.services.StudentDropServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.StudentDropServiceTests]/[method:test_dropStudent_withNullTeamMembers()]
negated conditional → KILLED

30

1.1
Location : dropStudent
Killed by : edu.ucsb.cs156.frontiers.services.StudentDropServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.StudentDropServiceTests]/[method:test_dropStudent_removesStudentFromAllTeams()]
removed call to edu/ucsb/cs156/frontiers/entities/RosterStudent::setTeamMembers → KILLED

32

1.1
Location : dropStudent
Killed by : edu.ucsb.cs156.frontiers.services.StudentDropServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.StudentDropServiceTests]/[method:test_dropStudent_removesStudentFromAllTeams()]
removed call to edu/ucsb/cs156/frontiers/repositories/TeamMemberRepository::deleteAllInBatch → KILLED

34

1.1
Location : dropStudent
Killed by : edu.ucsb.cs156.frontiers.services.StudentDropServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.services.StudentDropServiceTests]/[method:test_dropStudent_removesStudentFromAllTeams()]
removed call to java/util/List::forEach → KILLED

Active mutators

Tests examined


Report generated by PIT 1.30.0 support