ControlCoverageWriter.java

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 com.fasterxml.jackson.annotation.JsonInclude;
10
import tools.jackson.core.JacksonException;
11
import tools.jackson.databind.ObjectMapper;
12
import tools.jackson.databind.SerializationFeature;
13
import tools.jackson.databind.json.JsonMapper;
14
15
/**
16
 * Serialises a {@link ControlCoverageReport} to disk as pretty-printed JSON.
17
 *
18
 * <p>
19
 * Package-private because nothing outside the {@code coverage} package needs
20
 * direct access; {@link CoverageFacade} is the sole external caller.
21
 * </p>
22
 */
23
final class ControlCoverageWriter {
24
25
    private ControlCoverageWriter() {
26
        // Utility class.
27
    }
28
29
    /**
30
     * Writes {@code report} to {@code outputFile} using a freshly constructed
31
     * {@link ObjectMapper} configured with {@code INDENT_OUTPUT} and
32
     * {@code NON_NULL} inclusion. A fresh mapper is intentional: the coverage
33
     * writer must not mutate or share configuration with mappers used by the
34
     * HTTP/AI subsystem.
35
     *
36
     * @param report     report to serialise
37
     * @param outputFile destination path; the parent directory must already
38
     *                   exist
39
     * @throws IOException if the target file cannot be created or written
40
     */
41
    /* default */ static void write(ControlCoverageReport report, Path outputFile) throws IOException {
42
        ObjectMapper mapper = JsonMapper.builder()
43
                .enable(SerializationFeature.INDENT_OUTPUT)
44
                .changeDefaultPropertyInclusion(
45 1 1. lambda$write$0 : replaced return value with null for org/egothor/methodatlas/coverage/ControlCoverageWriter::lambda$write$0 → KILLED
                        v -> JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.NON_NULL))
46
                .build();
47
        try {
48 1 1. write : removed call to tools/jackson/databind/ObjectMapper::writeValue → KILLED
            mapper.writeValue(outputFile.toFile(), report);
49
        } catch (JacksonException e) {
50
            throw new IOException("Cannot write control-coverage report to '" + outputFile + "'", e);
51
        }
52
    }
53
}

Mutations

45

1.1
Location : lambda$write$0
Killed by : org.egothor.methodatlas.coverage.ControlCoverageWriterTest.[engine:junit-jupiter]/[class:org.egothor.methodatlas.coverage.ControlCoverageWriterTest]/[method:write_throwsIoException_whenParentDirectoryMissing(java.nio.file.Path)]
replaced return value with null for org/egothor/methodatlas/coverage/ControlCoverageWriter::lambda$write$0 → KILLED

48

1.1
Location : write
Killed by : org.egothor.methodatlas.coverage.ControlCoverageWriterTest.[engine:junit-jupiter]/[class:org.egothor.methodatlas.coverage.ControlCoverageWriterTest]/[method:write_throwsIoException_whenParentDirectoryMissing(java.nio.file.Path)]
removed call to tools/jackson/databind/ObjectMapper::writeValue → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1