ParticipationGradeCSVHelper.java

1
package edu.ucsb.cs156.happiercows.helpers;
2
3
import java.io.ByteArrayInputStream;
4
import java.io.ByteArrayOutputStream;
5
import java.io.IOException;
6
import java.io.PrintWriter;
7
import java.util.Arrays;
8
import java.util.List;
9
import org.apache.commons.csv.CSVFormat;
10
import org.apache.commons.csv.CSVPrinter;
11
import edu.ucsb.cs156.happiercows.models.ParticipationGrade;
12
13
/*
14
 * Serves up a CSV file of computed participation grades, one row per
15
 * student, for upload into a gradebook. See ReportCSVHelper/
16
 * GameStatsCSVHelper for the pattern this follows.
17
 */
18
19
public class ParticipationGradeCSVHelper {
20
21
  private ParticipationGradeCSVHelper() {}
22
23
  /**
24
   * This method is a hack to avoid a pitest issue; it isn't possible to
25
   * exclude an individual method call from jacoco coverage, but we can
26
   * exclude the entire method by name in the pom.xml
27
   * @param out
28
   */
29
30
  public static void flush_and_close_noPitest(ByteArrayOutputStream out, CSVPrinter csvPrinter) throws IOException {
31
    csvPrinter.flush();
32
    csvPrinter.close();
33
    out.flush();
34
    out.close();
35
  }
36
37
  public static ByteArrayInputStream toCSV(Iterable<ParticipationGrade> grades) throws IOException {
38
    final CSVFormat format = CSVFormat.DEFAULT;
39
40
    List<String> headers = Arrays.asList(
41
        "perm",
42
        "lastName",
43
        "firstMiddleName",
44
        "interactedAtLeastOnce",
45
        "daysInteracted",
46
        "ownedAndCheckedInOnACow",
47
        "criterion1PointsEarned",
48
        "criterion2PointsEarned",
49
        "criterion3PointsEarned",
50
        "totalPointsEarned");
51
52
    ByteArrayOutputStream out = new ByteArrayOutputStream();
53
    CSVPrinter csvPrinter = new CSVPrinter(new PrintWriter(out), format);
54
55 1 1. toCSV : removed call to org/apache/commons/csv/CSVPrinter::printRecord → KILLED
    csvPrinter.printRecord(headers);
56
    for (ParticipationGrade grade : grades) {
57
      List<String> data = Arrays.asList(
58
          grade.getPerm(),
59
          grade.getLastName(),
60
          grade.getFirstMiddleName(),
61
          String.valueOf(grade.isInteractedAtLeastOnce()),
62
          String.valueOf(grade.getDaysInteracted()),
63
          String.valueOf(grade.isOwnedAndCheckedInOnACow()),
64
          String.valueOf(grade.getCriterion1PointsEarned()),
65
          String.valueOf(grade.getCriterion2PointsEarned()),
66
          String.valueOf(grade.getCriterion3PointsEarned()),
67
          String.valueOf(grade.getTotalPointsEarned()));
68 1 1. toCSV : removed call to org/apache/commons/csv/CSVPrinter::printRecord → KILLED
      csvPrinter.printRecord(data);
69
    }
70
71 1 1. toCSV : removed call to edu/ucsb/cs156/happiercows/helpers/ParticipationGradeCSVHelper::flush_and_close_noPitest → KILLED
    flush_and_close_noPitest(out, csvPrinter);
72 1 1. toCSV : replaced return value with null for edu/ucsb/cs156/happiercows/helpers/ParticipationGradeCSVHelper::toCSV → KILLED
    return new ByteArrayInputStream(out.toByteArray());
73
  }
74
}

Mutations

55

1.1
Location : toCSV
Killed by : edu.ucsb.cs156.happiercows.controllers.ParticipationGradeControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.ParticipationGradeControllerTests]/[method:admin_can_download_grades_as_csv()]
removed call to org/apache/commons/csv/CSVPrinter::printRecord → KILLED

68

1.1
Location : toCSV
Killed by : edu.ucsb.cs156.happiercows.controllers.ParticipationGradeControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.ParticipationGradeControllerTests]/[method:admin_can_download_grades_as_csv()]
removed call to org/apache/commons/csv/CSVPrinter::printRecord → KILLED

71

1.1
Location : toCSV
Killed by : edu.ucsb.cs156.happiercows.controllers.ParticipationGradeControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.ParticipationGradeControllerTests]/[method:admin_can_download_grades_as_csv()]
removed call to edu/ucsb/cs156/happiercows/helpers/ParticipationGradeCSVHelper::flush_and_close_noPitest → KILLED

72

1.1
Location : toCSV
Killed by : edu.ucsb.cs156.happiercows.controllers.ParticipationGradeControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.ParticipationGradeControllerTests]/[method:admin_can_download_grades_as_csv()]
replaced return value with null for edu/ucsb/cs156/happiercows/helpers/ParticipationGradeCSVHelper::toCSV → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1