DeltaEntry.java

1
package org.egothor.methodatlas;
2
3
import java.util.Set;
4
5
import org.egothor.methodatlas.api.ScanRecord;
6
7
/**
8
 * A single change entry in a MethodAtlas delta report.
9
 *
10
 * <p>
11
 * Each entry describes one test method that was added, removed, or modified
12
 * between two scan outputs. Entries are produced by {@link DeltaReport#compute}
13
 * and consumed by {@link org.egothor.methodatlas.emit.DeltaEmitter} to produce human-readable output.
14
 * </p>
15
 *
16
 * <h2>Change types</h2>
17
 *
18
 * <ul>
19
 * <li>{@link ChangeType#ADDED} — method is present in the <em>after</em> scan
20
 *     but absent from the <em>before</em> scan. {@link #before()} is
21
 *     {@code null}.</li>
22
 * <li>{@link ChangeType#REMOVED} — method is present in the <em>before</em>
23
 *     scan but absent from the <em>after</em> scan. {@link #after()} is
24
 *     {@code null}.</li>
25
 * <li>{@link ChangeType#MODIFIED} — method is present in both scans but one
26
 *     or more comparable fields differ. Both {@link #before()} and
27
 *     {@link #after()} are non-{@code null}. The {@link #changedFields()} set
28
 *     names each field that differs.</li>
29
 * </ul>
30
 *
31
 * <h2>Changed field names</h2>
32
 *
33
 * <p>
34
 * The {@link #changedFields()} set uses the following identifiers, which
35
 * correspond to CSV column names or human-readable labels:
36
 * </p>
37
 *
38
 * <ul>
39
 * <li>{@code "loc"} — lines of code changed</li>
40
 * <li>{@code "tags"} — JUnit {@code @Tag} set changed</li>
41
 * <li>{@code "source"} — {@code content_hash} differs (class source was
42
 *     edited); only present when both records have a non-{@code null}
43
 *     {@code contentHash}</li>
44
 * <li>{@code "ai_security_relevant"} — security-relevance classification
45
 *     flipped; only present when both records have a non-{@code null}
46
 *     {@code aiSecurityRelevant}</li>
47
 * <li>{@code "ai_tags"} — AI taxonomy tag set changed; only present when
48
 *     both records have non-{@code null} {@code aiTags}</li>
49
 * </ul>
50
 *
51
 * @param changeType    the type of change
52
 * @param before        the record from the <em>before</em> scan; {@code null}
53
 *                      for {@link ChangeType#ADDED} entries
54
 * @param after         the record from the <em>after</em> scan; {@code null}
55
 *                      for {@link ChangeType#REMOVED} entries
56
 * @param changedFields names of fields that differ between {@code before} and
57
 *                      {@code after}; empty for {@link ChangeType#ADDED} and
58
 *                      {@link ChangeType#REMOVED} entries
59
 *
60
 * @see DeltaReport
61
 * @see org.egothor.methodatlas.emit.DeltaEmitter
62
 */
63
public record DeltaEntry(ChangeType changeType, ScanRecord before, ScanRecord after, Set<String> changedFields) {
64
65
    /**
66
     * The type of change represented by a {@link DeltaEntry}.
67
     */
68
    public enum ChangeType {
69
70
        /** Method is present in the <em>after</em> scan but not the <em>before</em> scan. */
71
        ADDED,
72
73
        /** Method is present in the <em>before</em> scan but not the <em>after</em> scan. */
74
        REMOVED,
75
76
        /** Method is present in both scans but at least one comparable field differs. */
77
        MODIFIED
78
    }
79
80
    /**
81
     * Creates an {@code ADDED} entry for a method discovered in the <em>after</em> scan.
82
     *
83
     * @param after the record from the <em>after</em> scan
84
     * @return new ADDED entry
85
     */
86
    /* default */ static DeltaEntry added(ScanRecord after) {
87 1 1. added : replaced return value with null for org/egothor/methodatlas/DeltaEntry::added → KILLED
        return new DeltaEntry(ChangeType.ADDED, null, after, Set.of());
88
    }
89
90
    /**
91
     * Creates a {@code REMOVED} entry for a method absent from the <em>after</em> scan.
92
     *
93
     * @param before the record from the <em>before</em> scan
94
     * @return new REMOVED entry
95
     */
96
    /* default */ static DeltaEntry removed(ScanRecord before) {
97 1 1. removed : replaced return value with null for org/egothor/methodatlas/DeltaEntry::removed → KILLED
        return new DeltaEntry(ChangeType.REMOVED, before, null, Set.of());
98
    }
99
100
    /**
101
     * Creates a {@code MODIFIED} entry for a method present in both scans but with
102
     * differing field values.
103
     *
104
     * @param before        the record from the <em>before</em> scan
105
     * @param after         the record from the <em>after</em> scan
106
     * @param changedFields names of the fields that differ
107
     * @return new MODIFIED entry
108
     */
109
    /* default */ static DeltaEntry modified(ScanRecord before, ScanRecord after, Set<String> changedFields) {
110 1 1. modified : replaced return value with null for org/egothor/methodatlas/DeltaEntry::modified → KILLED
        return new DeltaEntry(ChangeType.MODIFIED, before, after, Set.copyOf(changedFields));
111
    }
112
113
    /**
114
     * Returns the primary record for this entry.
115
     *
116
     * <p>
117
     * For {@link ChangeType#ADDED} and {@link ChangeType#MODIFIED} entries this is
118
     * the {@link #after()} record. For {@link ChangeType#REMOVED} entries this is
119
     * the {@link #before()} record. Never returns {@code null}.
120
     * </p>
121
     *
122
     * @return the representative record for this entry
123
     */
124
    public ScanRecord record() {
125 3 1. record : replaced return value with null for org/egothor/methodatlas/DeltaEntry::record → KILLED
2. record : removed conditional - replaced equality check with true → KILLED
3. record : removed conditional - replaced equality check with false → KILLED
        return after != null ? after : before;
126
    }
127
}

Mutations

87

1.1
Location : added
Killed by : org.egothor.methodatlas.DeltaEntryTest.[engine:junit-jupiter]/[class:org.egothor.methodatlas.DeltaEntryTest]/[method:added_changedFields_isEmpty()]
replaced return value with null for org/egothor/methodatlas/DeltaEntry::added → KILLED

97

1.1
Location : removed
Killed by : org.egothor.methodatlas.DeltaEntryTest.[engine:junit-jupiter]/[class:org.egothor.methodatlas.DeltaEntryTest]/[method:removed_changedFields_isEmpty()]
replaced return value with null for org/egothor/methodatlas/DeltaEntry::removed → KILLED

110

1.1
Location : modified
Killed by : org.egothor.methodatlas.DeltaEntryTest.[engine:junit-jupiter]/[class:org.egothor.methodatlas.DeltaEntryTest]/[method:modified_emptyChangedFields_accepted()]
replaced return value with null for org/egothor/methodatlas/DeltaEntry::modified → KILLED

125

1.1
Location : record
Killed by : org.egothor.methodatlas.DeltaEntryTest.[engine:junit-jupiter]/[class:org.egothor.methodatlas.DeltaEntryTest]/[method:removed_record_returnsBefore()]
replaced return value with null for org/egothor/methodatlas/DeltaEntry::record → KILLED

2.2
Location : record
Killed by : org.egothor.methodatlas.DeltaEntryTest.[engine:junit-jupiter]/[class:org.egothor.methodatlas.DeltaEntryTest]/[method:removed_record_returnsBefore()]
removed conditional - replaced equality check with true → KILLED

3.3
Location : record
Killed by : org.egothor.methodatlas.DeltaEntryTest.[engine:junit-jupiter]/[class:org.egothor.methodatlas.DeltaEntryTest]/[method:modified_record_returnsAfter()]
removed conditional - replaced equality check with false → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1