CoursePage.java

1
package edu.ucsb.cs156.courses.documents;
2
3
import com.fasterxml.jackson.core.JsonProcessingException;
4
import com.fasterxml.jackson.databind.DeserializationFeature;
5
import com.fasterxml.jackson.databind.ObjectMapper;
6
import java.util.ArrayList;
7
import java.util.List;
8
import lombok.Data;
9
import lombok.NoArgsConstructor;
10
import lombok.extern.slf4j.Slf4j;
11
12
@Data
13
@NoArgsConstructor
14
@Slf4j
15
public class CoursePage {
16
  private int pageNumber;
17
  private int pageSize;
18
  private int total;
19
  private List<Course> classes;
20
21
  /**
22
   * Create a CoursePage object from json representation
23
   *
24
   * @param json String of json returned by API endpoint {@code /classes/search}
25
   * @return a new CoursePage object
26
   * @see <a href=
27
   *     "https://developer.ucsb.edu/content/academic-curriculums">https://developer.ucsb.edu/content/academic-curriculums</a>
28
   */
29
  public static CoursePage fromJSON(String json) {
30
    try {
31
      ObjectMapper objectMapper = new ObjectMapper();
32
      objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
33
34
      CoursePage coursePage = objectMapper.readValue(json, CoursePage.class);
35 1 1. fromJSON : replaced return value with null for edu/ucsb/cs156/courses/documents/CoursePage::fromJSON → KILLED
      return coursePage;
36
    } catch (JsonProcessingException jpe) {
37
      log.error("JsonProcessingException:" + jpe);
38
      return null;
39
    }
40
  }
41
42
  /**
43
   * Create a List of ConvertedSections from json representation
44
   *
45
   * @return a list of converted sections
46
   */
47
  public List<ConvertedSection> convertedSections() {
48
49
    List<ConvertedSection> result = new ArrayList<ConvertedSection>();
50
51
    for (Course c : this.getClasses()) {
52
      for (Section section : c.getClassSections()) {
53 1 1. convertedSections : Replaced integer division with multiplication → KILLED
        int lectureNum = Integer.parseInt(section.getSection()) / 100;
54
        CourseInfo courseInfo =
55
            CourseInfo.builder()
56
                .quarter(c.getQuarter())
57
                .courseId(c.getCourseId() + "-" + Integer.toString(lectureNum))
58
                .title(c.getTitle())
59
                .description(c.getDescription())
60
                .build();
61
        ConvertedSection cs =
62
            ConvertedSection.builder().courseInfo(courseInfo).section(section).build();
63
        result.add(cs);
64
      }
65
    }
66 1 1. convertedSections : replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/documents/CoursePage::convertedSections → KILLED
    return result;
67
  }
68
}

Mutations

35

1.1
Location : fromJSON
Killed by : edu.ucsb.cs156.courses.documents.CoursePageTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.documents.CoursePageTests]/[method:convertsCoursePageToObject()]
replaced return value with null for edu/ucsb/cs156/courses/documents/CoursePage::fromJSON → KILLED

53

1.1
Location : convertedSections
Killed by : edu.ucsb.cs156.courses.documents.CoursePageTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.documents.CoursePageTests]/[method:convertedSectionsConvertsProperly()]
Replaced integer division with multiplication → KILLED

66

1.1
Location : convertedSections
Killed by : edu.ucsb.cs156.courses.jobs.UpdateCourseDataJobsTest.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.jobs.UpdateCourseDataJobsTest]/[method:test_log_output_with_errors()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/courses/documents/CoursePage::convertedSections → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3