School.java

1
package edu.ucsb.cs156.happiercows.enums;
2
3
import com.fasterxml.jackson.annotation.JsonCreator;
4
import com.fasterxml.jackson.annotation.JsonFormat;
5
import com.fasterxml.jackson.databind.JsonNode;
6
import lombok.Getter;
7
8
/**
9
 * The schools that a Course can belong to. Only schools with
10
 * {@code active = true} are offered in the Course create/edit dropdown (see
11
 * {@code CourseController#getActiveSchools}); the others (e.g. CHICO_STATE)
12
 * are kept here, together with a matching {@link edu.ucsb.cs156.happiercows.helpers.StudentCsvFormat}
13
 * entry, purely as a worked example of how to onboard a new school and its
14
 * own roster CSV format later.
15
 */
16
@Getter
17
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
18
public enum School {
19
    UCSB("UCSB", true),
20
    CHICO_STATE("Chico State", false),
21
    OTHER("Other", true);
22
23
    private final String displayName;
24
    private final boolean active;
25
    private final String key = this.name();
26
27
    School(String displayName, boolean active) {
28
        this.displayName = displayName;
29
        this.active = active;
30
    }
31
32
    /**
33
     * Accepts either a plain string (the enum's key, e.g. what a frontend
34
     * <select> submits) or the {@code {"key": "..."}} object shape
35
     * this enum itself serializes to.
36
     */
37
    @JsonCreator
38
    public static School fromKey(JsonNode node) {
39 1 1. fromKey : negated conditional → KILLED
        if (node == null) {
40
            return null;
41
        }
42 1 1. fromKey : negated conditional → KILLED
        if (node.isTextual()) {
43 1 1. fromKey : replaced return value with null for edu/ucsb/cs156/happiercows/enums/School::fromKey → KILLED
            return School.valueOf(node.asText().toUpperCase());
44
        }
45 1 1. fromKey : negated conditional → KILLED
        if (node.has("key")) {
46 1 1. fromKey : replaced return value with null for edu/ucsb/cs156/happiercows/enums/School::fromKey → KILLED
            return School.valueOf(node.get("key").asText().toUpperCase());
47
        }
48
        throw new IllegalArgumentException("Invalid JSON node for School enum");
49
    }
50
}

Mutations

39

1.1
Location : fromKey
Killed by : edu.ucsb.cs156.happiercows.enums.SchoolTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.enums.SchoolTests]/[method:fromKey_accepts_a_plain_text_node()]
negated conditional → KILLED

42

1.1
Location : fromKey
Killed by : edu.ucsb.cs156.happiercows.enums.SchoolTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.enums.SchoolTests]/[method:fromKey_accepts_a_plain_text_node()]
negated conditional → KILLED

43

1.1
Location : fromKey
Killed by : edu.ucsb.cs156.happiercows.enums.SchoolTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.enums.SchoolTests]/[method:fromKey_accepts_a_plain_text_node()]
replaced return value with null for edu/ucsb/cs156/happiercows/enums/School::fromKey → KILLED

45

1.1
Location : fromKey
Killed by : edu.ucsb.cs156.happiercows.enums.SchoolTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.enums.SchoolTests]/[method:fromKey_throws_for_a_node_that_is_neither_text_nor_has_a_key()]
negated conditional → KILLED

46

1.1
Location : fromKey
Killed by : edu.ucsb.cs156.happiercows.enums.SchoolTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.enums.SchoolTests]/[method:fromKey_accepts_the_object_shape_it_serializes_to()]
replaced return value with null for edu/ucsb/cs156/happiercows/enums/School::fromKey → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0