GapReportWriter.java

1
// SPDX-License-Identifier: Apache-2.0
2
// Copyright 2026 Egothor
3
// Copyright 2026 Accenture
4
package org.egothor.methodatlas.gap;
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 GapReport} to disk as pretty-printed JSON.
17
 *
18
 * <p>
19
 * Package-private because nothing outside the {@code gap} package needs direct
20
 * access; {@link GapFacade} is the sole external caller.
21
 * </p>
22
 */
23
final class GapReportWriter {
24
25
    private GapReportWriter() {
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.
33
     *
34
     * @param report     report to serialise
35
     * @param outputFile destination path; the parent directory must already exist
36
     * @throws IOException if the target file cannot be created or written
37
     */
38
    /* default */ static void write(GapReport report, Path outputFile) throws IOException {
39
        ObjectMapper mapper = JsonMapper.builder()
40
                .enable(SerializationFeature.INDENT_OUTPUT)
41
                .changeDefaultPropertyInclusion(
42 1 1. lambda$write$0 : replaced return value with null for org/egothor/methodatlas/gap/GapReportWriter::lambda$write$0 → NO_COVERAGE
                        v -> JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.NON_NULL))
43
                .build();
44
        try {
45
            mapper.writeValue(outputFile.toFile(), report);
46
        } catch (JacksonException e) {
47
            throw new IOException("Cannot write gap report to '" + outputFile + "'", e);
48
        }
49
    }
50
}

Mutations

42

1.1
Location : lambda$write$0
Killed by : none
replaced return value with null for org/egothor/methodatlas/gap/GapReportWriter::lambda$write$0 → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.30.1 support