| 1 | // SPDX-License-Identifier: Apache-2.0 | |
| 2 | // Copyright 2026 Egothor | |
| 3 | // Copyright 2026 Accenture | |
| 4 | package org.egothor.methodatlas.coverage; | |
| 5 | ||
| 6 | import java.io.IOException; | |
| 7 | import java.nio.file.Path; | |
| 8 | ||
| 9 | import org.egothor.methodatlas.emit.TestMethodSink; | |
| 10 | ||
| 11 | /** | |
| 12 | * Single public entry point used by {@code MethodAtlasApp} to drive | |
| 13 | * {@code -emit-coverage}. | |
| 14 | * | |
| 15 | * <p> | |
| 16 | * The package's data records, collector, writer and mapping loader are all | |
| 17 | * package-private so they remain implementation details. The facade exposes | |
| 18 | * only the operations the CLI needs: | |
| 19 | * </p> | |
| 20 | * <ol> | |
| 21 | * <li>load a mapping file (returning the framework label and a sink that | |
| 22 | * must be threaded through the orchestrator);</li> | |
| 23 | * <li>after the scan, ask the same handle to write the report.</li> | |
| 24 | * </ol> | |
| 25 | */ | |
| 26 | public final class CoverageFacade { | |
| 27 | ||
| 28 | /** Default filename used when {@code -coverage-file} is not supplied. */ | |
| 29 | public static final String DEFAULT_COVERAGE_FILENAME = "controls-coverage.json"; | |
| 30 | ||
| 31 | private CoverageFacade() { | |
| 32 | // Utility class. | |
| 33 | } | |
| 34 | ||
| 35 | /** | |
| 36 | * Loads {@code mappingFile} and prepares a coverage collector wrapped | |
| 37 | * inside a {@link Handle} that the CLI can later pass to the scan | |
| 38 | * orchestrator and the writer. | |
| 39 | * | |
| 40 | * @param mappingFile path to the user-authored mapping JSON | |
| 41 | * @param minConfidence AI minimum-confidence threshold from the CLI | |
| 42 | * @return handle ready for use by the orchestrator and writer | |
| 43 | * @throws IOException if the mapping file cannot be read | |
| 44 | * @throws IllegalArgumentException if the mapping file is invalid | |
| 45 | */ | |
| 46 | public static Handle prepare(Path mappingFile, double minConfidence) throws IOException { | |
| 47 | ControlMapping mapping = ControlMapping.load(mappingFile); | |
| 48 | ControlCoverageCollector collector = new ControlCoverageCollector(mapping, minConfidence); | |
| 49 |
1
1. prepare : replaced return value with null for org/egothor/methodatlas/coverage/CoverageFacade::prepare → KILLED |
return new Handle(collector); |
| 50 | } | |
| 51 | ||
| 52 | /** | |
| 53 | * Opaque handle returned by {@link #prepare(Path, double)}. Carries the | |
| 54 | * collector through the scan and yields the report when the scan is done. | |
| 55 | */ | |
| 56 | public static final class Handle { | |
| 57 | ||
| 58 | /** Backing collector — owned by this handle, never exposed directly. */ | |
| 59 | private final ControlCoverageCollector collector; | |
| 60 | ||
| 61 | private Handle(ControlCoverageCollector collector) { | |
| 62 | this.collector = collector; | |
| 63 | } | |
| 64 | ||
| 65 | /** | |
| 66 | * Returns the {@link TestMethodSink} that the orchestrator must | |
| 67 | * receive every per-method record on. | |
| 68 | * | |
| 69 | * @return collector as a sink | |
| 70 | */ | |
| 71 | public TestMethodSink asSink() { | |
| 72 |
1
1. asSink : replaced return value with null for org/egothor/methodatlas/coverage/CoverageFacade$Handle::asSink → KILLED |
return collector; |
| 73 | } | |
| 74 | ||
| 75 | /** | |
| 76 | * Builds the report and writes it to {@code outputFile}. | |
| 77 | * | |
| 78 | * @param toolVersion resolved tool version string | |
| 79 | * @param outputFile destination path | |
| 80 | * @throws IOException if the file cannot be written | |
| 81 | */ | |
| 82 | public void write(String toolVersion, Path outputFile) throws IOException { | |
| 83 | ControlCoverageReport report = collector.buildReport(toolVersion); | |
| 84 |
1
1. write : removed call to org/egothor/methodatlas/coverage/ControlCoverageWriter::write → KILLED |
ControlCoverageWriter.write(report, outputFile); |
| 85 | } | |
| 86 | } | |
| 87 | } | |
Mutations | ||
| 49 |
1.1 |
|
| 72 |
1.1 |
|
| 84 |
1.1 |