CourseDataAvailabilityService.java

1
package edu.ucsb.cs156.courses.services;
2
3
import edu.ucsb.cs156.courses.models.Quarter;
4
import edu.ucsb.cs156.courses.repositories.UCSBSubjectRepository;
5
import java.util.ArrayList;
6
import java.util.List;
7
import lombok.RequiredArgsConstructor;
8
import lombok.extern.slf4j.Slf4j;
9
import org.springframework.stereotype.Service;
10
11
@Service
12
@RequiredArgsConstructor
13
@Slf4j
14
public class CourseDataAvailabilityService {
15
  private final UCSBSubjectRepository subjects;
16
  private final CourseDataLoadService loader;
17
18
  /**
19
   * Missing metadata, not empty search results, triggers a load. Null subject means all subjects.
20
   */
21
  public List<String> warnings(String start, String end, String subject) {
22
    List<String> requestedSubjects = new ArrayList<>();
23 1 1. warnings : negated conditional → KILLED
    if (subject == null) {
24 1 1. warnings : removed call to java/lang/Iterable::forEach → KILLED
      subjects.findAll().forEach(s -> requestedSubjects.add(s.getSubjectCode()));
25
    } else {
26
      requestedSubjects.add(subject.strip().toUpperCase(java.util.Locale.ROOT));
27
    }
28 1 1. warnings : negated conditional → KILLED
    if (requestedSubjects.isEmpty()) {
29
      throw new IllegalStateException("Subject catalog is unavailable");
30
    }
31
    List<String> warnings = new ArrayList<>();
32
    for (Quarter quarter : Quarter.quarterList(start, end)) {
33
      for (String code : requestedSubjects) {
34
        String data = "Course data for " + code + " in quarter " + quarter.getYYYYQ();
35
        try {
36 1 1. warnings : negated conditional → KILLED
          if (!loader.ensureLoaded(code, quarter.getYYYYQ())) {
37
            warnings.add(
38
                data
39
                    + " has not been loaded. A background update is scheduled or already running. Please check back in 5 minutes.");
40
          }
41
        } catch (Exception e) {
42
          log.error("Unable to schedule missing course data for {} {}", code, quarter, e);
43
          warnings.add(
44
              data + " could not be loaded or scheduled. Please try searching again later.");
45
        }
46
      }
47
    }
48 1 1. warnings : replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/services/CourseDataAvailabilityService::warnings → KILLED
    return warnings;
49
  }
50
}

Mutations

23

1.1
Location : warnings
Killed by : edu.ucsb.cs156.courses.services.CourseDataAvailabilityServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.services.CourseDataAvailabilityServiceTests]/[method:missingSubjectCatalogCannotBeTreatedAsCompleteCoverage()]
negated conditional → KILLED

24

1.1
Location : warnings
Killed by : edu.ucsb.cs156.courses.services.CourseDataAvailabilityServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.services.CourseDataAvailabilityServiceTests]/[method:crossSubjectSearchChecksEverySubjectIncludingThoseWithNoMatches()]
removed call to java/lang/Iterable::forEach → KILLED

28

1.1
Location : warnings
Killed by : edu.ucsb.cs156.courses.services.CourseDataAvailabilityServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.services.CourseDataAvailabilityServiceTests]/[method:missingSubjectCatalogCannotBeTreatedAsCompleteCoverage()]
negated conditional → KILLED

36

1.1
Location : warnings
Killed by : edu.ucsb.cs156.courses.services.CourseDataAvailabilityServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.services.CourseDataAvailabilityServiceTests]/[method:loadedDataNeedsNoWarning()]
negated conditional → KILLED

48

1.1
Location : warnings
Killed by : edu.ucsb.cs156.courses.services.CourseDataAvailabilityServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.services.CourseDataAvailabilityServiceTests]/[method:subjectSearchChecksEveryQuarterAndNormalizesSubject()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/services/CourseDataAvailabilityService::warnings → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1