UpdateService.java

1
package edu.ucsb.cs156.courses.services;
2
3
import edu.ucsb.cs156.courses.collections.UpdateCollection;
4
import edu.ucsb.cs156.courses.documents.Update;
5
import java.time.LocalDateTime;
6
import java.util.Optional;
7
import org.springframework.beans.factory.annotation.Autowired;
8
import org.springframework.boot.context.properties.ConfigurationProperties;
9
import org.springframework.data.domain.Page;
10
import org.springframework.data.domain.PageRequest;
11
import org.springframework.data.domain.Sort.Direction;
12
import org.springframework.stereotype.Service;
13
14
@Service("UpdateService")
15
@ConfigurationProperties
16
public class UpdateService {
17
  /**
18
   * Get the last update for a given subject area and quarter
19
   *
20
   * @param updateCollection
21
   * @param subjectArea
22
   * @param quarterYYYYQ
23
   * @return the last update
24
   * @throws Exception
25
   */
26
  @Autowired private UpdateCollection updateCollection;
27
28
  public Optional<LocalDateTime> getLastUpdate(String subjectArea, String quarterYYYYQ)
29
      throws Exception {
30
31
    PageRequest pageRequest_0_1_DESC_lastUpdate =
32
        PageRequest.of(0, 1, Direction.DESC, "lastUpdate");
33
34
    Page<Update> updatePage =
35
        updateCollection.findBySubjectAreaAndQuarter(
36
            subjectArea, quarterYYYYQ, pageRequest_0_1_DESC_lastUpdate);
37 1 1. getLastUpdate : negated conditional → KILLED
    if (updatePage.getTotalElements() == 0) {
38
      return Optional.empty();
39
    }
40
    Update update = updatePage.getContent().get(0);
41 1 1. getLastUpdate : replaced return value with Optional.empty for edu/ucsb/cs156/courses/services/UpdateService::getLastUpdate → KILLED
    return Optional.of(update.getLastUpdate());
42
  }
43
}

Mutations

37

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

41

1.1
Location : getLastUpdate
Killed by : edu.ucsb.cs156.courses.services.UpdateServiceTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.services.UpdateServiceTests]/[method:test_getLastUpdate_nonEmpty()]
replaced return value with Optional.empty for edu/ucsb/cs156/courses/services/UpdateService::getLastUpdate → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0