CourseOverTimeController.java

1
package edu.ucsb.cs156.courses.controllers;
2
3
import com.fasterxml.jackson.core.JsonProcessingException;
4
import com.fasterxml.jackson.databind.ObjectMapper;
5
import edu.ucsb.cs156.courses.collections.ConvertedSectionCollection;
6
import edu.ucsb.cs156.courses.documents.ConvertedSection;
7
import io.swagger.v3.oas.annotations.Operation;
8
import io.swagger.v3.oas.annotations.Parameter;
9
import java.util.List;
10
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.http.ResponseEntity;
12
import org.springframework.web.bind.annotation.GetMapping;
13
import org.springframework.web.bind.annotation.RequestMapping;
14
import org.springframework.web.bind.annotation.RequestParam;
15
import org.springframework.web.bind.annotation.RestController;
16
17
@RestController
18
@RequestMapping("/api/public/courseovertime")
19
public class CourseOverTimeController {
20
21
  private ObjectMapper mapper = new ObjectMapper();
22
23
  @Autowired ConvertedSectionCollection convertedSectionCollection;
24
25
  @Operation(summary = "Get a list of courses over time")
26
  @GetMapping(value = "/search", produces = "application/json")
27
  public ResponseEntity<String> search(
28
      @Parameter(
29
              name = "startQtr",
30
              description =
31
                  "starting quarter in yyyyq format, e.g. 20231 for W23, 20232 for S23, etc. (1=Winter, 2=Spring, 3=Summer, 4=Fall)",
32
              example = "20231",
33
              required = true)
34
          @RequestParam
35
          String startQtr,
36
      @Parameter(
37
              name = "endQtr",
38
              description =
39
                  "ending quarter in yyyyq format, e.g. 20231 for W23, 20232 for S23, etc. (1=Winter, 2=Spring, 3=Summer, 4=Fall)",
40
              example = "20231",
41
              required = true)
42
          @RequestParam
43
          String endQtr,
44
      @Parameter(
45
              name = "subjectArea",
46
              description = "simplified area name, e.g. CMPSC for computer science",
47
              example = "CMPSC",
48
              required = true)
49
          @RequestParam
50
          String subjectArea,
51
      @Parameter(
52
              name = "courseNumber",
53
              description = "the specific course number, e.g. 130A for CS130A",
54
              example = "130A",
55
              required = true)
56
          @RequestParam
57
          String courseNumber)
58
      throws JsonProcessingException {
59
    List<ConvertedSection> courseResults =
60
        convertedSectionCollection.findByQuarterRangeAndCourseId(
61
            startQtr, endQtr, makeFormattedCourseId(subjectArea, courseNumber));
62
    String body = mapper.writeValueAsString(courseResults);
63 1 1. search : replaced return value with null for edu/ucsb/cs156/courses/controllers/CourseOverTimeController::search → KILLED
    return ResponseEntity.ok().body(body);
64
  }
65
66
  String makeFormattedCourseId(String subjectArea, String courseNumber) {
67
    String[] nums = courseNumber.split("[a-zA-Z]+");
68
    String[] suffs = courseNumber.split("[0-9]+");
69 2 1. makeFormattedCourseId : changed conditional boundary → KILLED
2. makeFormattedCourseId : negated conditional → KILLED
    if (suffs.length < 2) { // no suffix
70 1 1. makeFormattedCourseId : replaced return value with "" for edu/ucsb/cs156/courses/controllers/CourseOverTimeController::makeFormattedCourseId → KILLED
      return String.format("%-8s", subjectArea) // 'CMPSC   '
71
          + String.format("%3s", nums[0]) // '  8'
72
      ;
73
    }
74 1 1. makeFormattedCourseId : replaced return value with "" for edu/ucsb/cs156/courses/controllers/CourseOverTimeController::makeFormattedCourseId → KILLED
    return String.format("%-8s", subjectArea) // 'CMPSC   '
75
        + String.format("%3s", nums[0]) // '  8'
76
        + String.format("%-2s", suffs[1]) // 'A '
77
    ;
78
  }
79
}

Mutations

63

1.1
Location : search
Killed by : edu.ucsb.cs156.courses.controllers.CourseOverTimeControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.CourseOverTimeControllerTests]/[method:test_search_emptyRequest()]
replaced return value with null for edu/ucsb/cs156/courses/controllers/CourseOverTimeController::search → KILLED

69

1.1
Location : makeFormattedCourseId
Killed by : edu.ucsb.cs156.courses.controllers.CourseOverTimeControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.CourseOverTimeControllerTests]/[method:test_search_validRequestWithSuffix()]
changed conditional boundary → KILLED

2.2
Location : makeFormattedCourseId
Killed by : edu.ucsb.cs156.courses.controllers.CourseOverTimeControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.CourseOverTimeControllerTests]/[method:test_search_validRequestWithoutSuffix()]
negated conditional → KILLED

70

1.1
Location : makeFormattedCourseId
Killed by : edu.ucsb.cs156.courses.controllers.CourseOverTimeControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.CourseOverTimeControllerTests]/[method:test_search_validRequestWithoutSuffix()]
replaced return value with "" for edu/ucsb/cs156/courses/controllers/CourseOverTimeController::makeFormattedCourseId → KILLED

74

1.1
Location : makeFormattedCourseId
Killed by : edu.ucsb.cs156.courses.controllers.CourseOverTimeControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.courses.controllers.CourseOverTimeControllerTests]/[method:test_search_validRequestWithSuffix()]
replaced return value with "" for edu/ucsb/cs156/courses/controllers/CourseOverTimeController::makeFormattedCourseId → KILLED

Active mutators

Tests examined


Report generated by PIT 1.7.3