ApplyTagsFromCsvCommand.java

1
package org.egothor.methodatlas.command;
2
3
import java.io.IOException;
4
import java.io.PrintWriter;
5
import java.nio.file.Path;
6
import java.nio.file.Paths;
7
import java.util.List;
8
9
import org.egothor.methodatlas.ApplyTagsFromCsvEngine;
10
import org.egothor.methodatlas.CliConfig;
11
import org.egothor.methodatlas.api.SourcePatcher;
12
import org.egothor.methodatlas.api.TestDiscoveryConfig;
13
14
/**
15
 * CLI command handler for the {@code -apply-tags-from-csv} mode.
16
 *
17
 * <p>
18
 * Applies the annotation decisions recorded in a reviewed CSV back to the
19
 * source files. The CSV is treated as a complete desired-state specification:
20
 * every test method's {@code @Tag} set and {@code @DisplayName} are driven
21
 * entirely by the corresponding CSV row.
22
 * </p>
23
 *
24
 * @see ApplyTagsCommand
25
 * @see org.egothor.methodatlas.ApplyTagsFromCsvEngine
26
 */
27
public final class ApplyTagsFromCsvCommand implements Command {
28
29
    private final CliConfig cliConfig;
30
    private final TestDiscoveryConfig discoveryConfig;
31
    private final PluginLoader pluginLoader;
32
33
    /**
34
     * Creates a new apply-tags-from-csv command.
35
     *
36
     * @param cliConfig       full parsed CLI configuration
37
     * @param discoveryConfig discovery configuration forwarded to patchers
38
     * @param pluginLoader    loader used to resolve {@link SourcePatcher}
39
     *                        plugins from the classpath
40
     */
41
    public ApplyTagsFromCsvCommand(CliConfig cliConfig, TestDiscoveryConfig discoveryConfig,
42
            PluginLoader pluginLoader) {
43
        this.cliConfig = cliConfig;
44
        this.discoveryConfig = discoveryConfig;
45
        this.pluginLoader = pluginLoader;
46
    }
47
48
    /**
49
     * Applies annotation decisions from the reviewed CSV to source files.
50
     *
51
     * @param out writer for progress and summary output
52
     * @return {@code 0} on success, {@code 1} when the mismatch limit is
53
     *         exceeded or a fatal error occurs
54
     * @throws IOException if the CSV or source files cannot be read or written
55
     */
56
    @Override
57
    public int execute(PrintWriter out) throws IOException {
58 2 1. execute : removed conditional - replaced equality check with false → SURVIVED
2. execute : removed conditional - replaced equality check with true → KILLED
        List<Path> roots = cliConfig.paths().isEmpty() ? List.of(Paths.get(".")) : cliConfig.paths();
59
        List<SourcePatcher> patchers = pluginLoader.loadPatchers(discoveryConfig);
60 1 1. execute : replaced int return with 0 for org/egothor/methodatlas/command/ApplyTagsFromCsvCommand::execute → KILLED
        return ApplyTagsFromCsvEngine.apply(
61
                cliConfig.applyTagsFromCsvFile(),
62
                roots,
63
                cliConfig.mismatchLimit(),
64
                patchers,
65
                out);
66
    }
67
}

Mutations

58

1.1
Location : execute
Killed by : org.egothor.methodatlas.MethodAtlasAppApplyTagsFromCsvTest.[engine:junit-jupiter]/[class:org.egothor.methodatlas.MethodAtlasAppApplyTagsFromCsvTest]/[method:applyTagsFromCsv_addsDisplayNameImportWhenDisplayNameSet(java.nio.file.Path)]
removed conditional - replaced equality check with true → KILLED

2.2
Location : execute
Killed by : none
removed conditional - replaced equality check with false → SURVIVED
Covering tests

60

1.1
Location : execute
Killed by : org.egothor.methodatlas.MethodAtlasAppApplyTagsFromCsvTest.[engine:junit-jupiter]/[class:org.egothor.methodatlas.MethodAtlasAppApplyTagsFromCsvTest]/[method:applyTagsFromCsv_mismatchLimitReturnsOne(java.nio.file.Path)]
replaced int return with 0 for org/egothor/methodatlas/command/ApplyTagsFromCsvCommand::execute → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1