From c1ed1925b8f282b9759a579dce60d497f0140258 Mon Sep 17 00:00:00 2001
From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Date: Wed, 11 Nov 2026 23:10:17 +0000
Subject: [PATCH 01/12] test: split processor tests into the modules they cover
(#390)
Move every test that exercises a shared codegen module into that
module so each module proves its behavior with tests in its own tree:
- simple-processor: JavaLangAnalyserTest, OptionValueParsersTest,
CodegenProcessorConfigurationTest, ProcessorOptionRegistryTest,
ElementCollectorTest and MinimalCodegenProcessorTest (now compiling
against CodegenTestUtils directly), plus new JavaLangMapperTest and
FieldAnnotationExtractorTest driving a probe processor
- codegen-core: ActivePerformanceTrackerTest (with a local capturing
logger, as codegen-testing would be a dependency cycle), plus new
SinkProcessingLoggerTest, CodegenEnumsTest and ImportCollectorTest;
jackson-databind added as test-scoped dep for the tracker's JSON
assertions
- codegen-testing: FormatterProfileTestUtilsTest plus new tests for
CapturingProcessingLogger, CodegenTestUtils, ProcessingEnvironmentStub
and ProcessorAsserts; a minimal eclipse-java-format.xml test resource
stands in for the bundled codegen-roaster profile
- codegen-roaster: RoasterCodeGeneratorResilienceTest rebuilt on a
GenerationEnvironment stub of codegen-core types, plus new
RoasterCodeGeneratorTest asserting whole generated sources against
generic DTOs
processor no longer depends on codegen-roaster: the only main-code
mention was a javadoc reference, now kept as plain text. Each module's
metrics profile reports coverage from its own tests alone (e.g.
codegen-core 91% lines, processor 98%).
---
codegen-core/pom.xml | 8 +
.../codegen/enums/CodegenEnumsTest.java | 61 +++++
.../logging/ActivePerformanceTrackerTest.java | 201 +++++++++------
.../logging/SinkProcessingLoggerTest.java | 110 ++++++++
.../codegen/util/ImportCollectorTest.java | 97 ++++++++
.../RoasterCodeGeneratorResilienceTest.java | 67 ++---
.../roaster/RoasterCodeGeneratorTest.java | 190 ++++++++++++++
.../CapturingProcessingLoggerTest.java | 73 ++++++
.../codegen/testing/CodegenTestUtilsTest.java | 140 +++++++++++
.../FormatterProfileTestUtilsTest.java | 3 +-
.../ProcessingEnvironmentStubTest.java | 57 +++++
.../codegen/testing/ProcessorAssertsTest.java | 83 +++++++
.../test/resources/eclipse-java-format.xml | 7 +
processor/pom.xml | 5 -
.../processing/BuilderDefinitionCreator.java | 4 +-
.../FieldAnnotationExtractorTest.java | 235 ++++++++++++++++++
.../analysis}/JavaLangAnalyserTest.java | 3 +-
.../codegen/analysis/JavaLangMapperTest.java | 207 +++++++++++++++
.../CodegenProcessorConfigurationTest.java | 0
.../processing/ElementCollectorTest.java | 0
.../MinimalCodegenProcessorTest.java | 8 +-
.../processing/OptionValueParsersTest.java | 3 +-
.../ProcessorOptionRegistryTest.java | 0
23 files changed, 1441 insertions(+), 121 deletions(-)
create mode 100644 codegen-core/src/test/java/org/javahelpers/codegen/enums/CodegenEnumsTest.java
rename {processor => codegen-core}/src/test/java/org/javahelpers/codegen/logging/ActivePerformanceTrackerTest.java (74%)
create mode 100644 codegen-core/src/test/java/org/javahelpers/codegen/logging/SinkProcessingLoggerTest.java
create mode 100644 codegen-core/src/test/java/org/javahelpers/codegen/util/ImportCollectorTest.java
rename {processor/src/test/java/org/javahelpers/simple/builders/processor => codegen-roaster/src/test/java/org/javahelpers/codegen/roaster}/RoasterCodeGeneratorResilienceTest.java (78%)
create mode 100644 codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterCodeGeneratorTest.java
create mode 100644 codegen-testing/src/test/java/org/javahelpers/codegen/testing/CapturingProcessingLoggerTest.java
create mode 100644 codegen-testing/src/test/java/org/javahelpers/codegen/testing/CodegenTestUtilsTest.java
rename {processor/src/test/java/org/javahelpers/simple/builders/processor => codegen-testing/src/test/java/org/javahelpers/codegen}/testing/FormatterProfileTestUtilsTest.java (95%)
create mode 100644 codegen-testing/src/test/java/org/javahelpers/codegen/testing/ProcessingEnvironmentStubTest.java
create mode 100644 codegen-testing/src/test/java/org/javahelpers/codegen/testing/ProcessorAssertsTest.java
create mode 100644 codegen-testing/src/test/resources/eclipse-java-format.xml
create mode 100644 simple-processor/src/test/java/org/javahelpers/codegen/analysis/FieldAnnotationExtractorTest.java
rename {processor/src/test/java/org/javahelpers/simple/builders/processor => simple-processor/src/test/java/org/javahelpers/codegen/analysis}/JavaLangAnalyserTest.java (98%)
create mode 100644 simple-processor/src/test/java/org/javahelpers/codegen/analysis/JavaLangMapperTest.java
rename {processor => simple-processor}/src/test/java/org/javahelpers/codegen/processing/CodegenProcessorConfigurationTest.java (100%)
rename {processor => simple-processor}/src/test/java/org/javahelpers/codegen/processing/ElementCollectorTest.java (100%)
rename {processor => simple-processor}/src/test/java/org/javahelpers/codegen/processing/MinimalCodegenProcessorTest.java (96%)
rename {processor/src/test/java/org/javahelpers/simple/builders/processor => simple-processor/src/test/java/org/javahelpers/codegen}/processing/OptionValueParsersTest.java (97%)
rename {processor => simple-processor}/src/test/java/org/javahelpers/codegen/processing/ProcessorOptionRegistryTest.java (100%)
diff --git a/codegen-core/pom.xml b/codegen-core/pom.xml
index 0172278c..6c4b5550 100644
--- a/codegen-core/pom.xml
+++ b/codegen-core/pom.xml
@@ -122,6 +122,14 @@
test
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ ${jackson-databind.version}
+ test
+
+
diff --git a/codegen-core/src/test/java/org/javahelpers/codegen/enums/CodegenEnumsTest.java b/codegen-core/src/test/java/org/javahelpers/codegen/enums/CodegenEnumsTest.java
new file mode 100644
index 00000000..3d95d67f
--- /dev/null
+++ b/codegen-core/src/test/java/org/javahelpers/codegen/enums/CodegenEnumsTest.java
@@ -0,0 +1,61 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2025-2026 Andreas Igel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.javahelpers.codegen.enums;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+/** Unit tests for the codegen enums' value mappings and parsing. */
+class CodegenEnumsTest {
+
+ @Test
+ void accessModifier_mapsToJavaKeyword() {
+ assertEquals("public", AccessModifier.DEFAULT.getJavaKeyword());
+ assertEquals("public", AccessModifier.PUBLIC.getJavaKeyword());
+ assertEquals("protected", AccessModifier.PROTECTED.getJavaKeyword());
+ assertEquals("", AccessModifier.PACKAGE_PRIVATE.getJavaKeyword());
+ assertEquals("private", AccessModifier.PRIVATE.getJavaKeyword());
+ }
+
+ @Test
+ void formattingMode_optionValuesAndParsing() {
+ assertEquals("jdt", FormattingMode.JDT.getOptionValue());
+ assertEquals("lightweight", FormattingMode.LIGHTWEIGHT.getOptionValue());
+ assertEquals("none", FormattingMode.NONE.getOptionValue());
+
+ assertEquals(FormattingMode.NONE, FormattingMode.fromString("none"));
+ assertEquals(FormattingMode.LIGHTWEIGHT, FormattingMode.fromString("LightWeight"));
+ assertEquals(FormattingMode.JDT, FormattingMode.fromString(null));
+ assertEquals(FormattingMode.JDT, FormattingMode.fromString("unknown"));
+ }
+
+ @Test
+ void optionState_hasTriStateValues() {
+ assertEquals(
+ java.util.Set.of(OptionState.UNSET, OptionState.ENABLED, OptionState.DISABLED),
+ java.util.Set.of(OptionState.values()));
+ }
+}
diff --git a/processor/src/test/java/org/javahelpers/codegen/logging/ActivePerformanceTrackerTest.java b/codegen-core/src/test/java/org/javahelpers/codegen/logging/ActivePerformanceTrackerTest.java
similarity index 74%
rename from processor/src/test/java/org/javahelpers/codegen/logging/ActivePerformanceTrackerTest.java
rename to codegen-core/src/test/java/org/javahelpers/codegen/logging/ActivePerformanceTrackerTest.java
index 46be9e84..2f08135b 100644
--- a/processor/src/test/java/org/javahelpers/codegen/logging/ActivePerformanceTrackerTest.java
+++ b/codegen-core/src/test/java/org/javahelpers/codegen/logging/ActivePerformanceTrackerTest.java
@@ -24,6 +24,7 @@
package org.javahelpers.codegen.logging;
+import static org.javahelpers.codegen.GenerationPhases.*;
import static org.junit.jupiter.api.Assertions.*;
import com.fasterxml.jackson.databind.JsonNode;
@@ -31,11 +32,12 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.javahelpers.codegen.GenerationPhases;
-import org.javahelpers.codegen.processing.PipelinePhases;
-import org.javahelpers.codegen.testing.CapturingProcessingLogger;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@@ -44,18 +46,79 @@
*
*
Tests cover phase tracking, generator/enhancer tracking, class metrics, JSON report output
* structure and correctness, edge cases, and ThreadLocal cleanup.
+ *
+ *
codegen-core cannot depend on codegen-testing (dependency cycle), so the capturing logger and
+ * the phase vocabulary are defined locally instead of reusing {@code CapturingLogger} and {@code
+ * PipelinePhases}.
*/
class ActivePerformanceTrackerTest {
@TempDir Path tempDir;
+ private static final String PHASE_ELEMENT_COLLECTION = "Element Collection";
+ private static final String PHASE_CONFIGURATION_RESOLUTION = "Configuration Resolution";
+ private static final String PHASE_ANALYSIS = "Analysis";
+ private static final String PHASE_TARGET_MAPPING = "Target Mapping";
+ private static final String PHASE_CODE_GENERATION = "Code Generation";
+
+ /** Phase hierarchy rendered in the report, mirroring a typical processing pipeline. */
+ private static final PhaseHierarchy TEST_HIERARCHY =
+ new PhaseHierarchy(
+ List.of(
+ PHASE_ELEMENT_COLLECTION,
+ PHASE_CONFIGURATION_RESOLUTION,
+ PHASE_ANALYSIS,
+ PHASE_TARGET_MAPPING,
+ PHASE_CODE_GENERATION),
+ Map.of(
+ PHASE_CODE_GENERATION,
+ List.of(PHASE_SOURCE_CONSTRUCTION, PHASE_FILE_WRITING),
+ PHASE_SOURCE_CONSTRUCTION,
+ List.of(PHASE_ELEMENT_BUILDING, PHASE_STRING_GENERATION, PHASE_FORMATTING),
+ PHASE_ELEMENT_BUILDING,
+ List.of(
+ PHASE_CLASS_CREATION,
+ PHASE_CLASS_METADATA,
+ PHASE_FIELDS,
+ PHASE_CONSTRUCTORS,
+ PHASE_METHODS,
+ PHASE_NESTED_TYPES,
+ PHASE_CLASS_ANNOTATIONS)));
+
+ /** Minimal capturing logger equivalent to codegen-testing's {@code CapturingLogger}. */
+ private static final class CapturingLogger {
+ private final List messages = new ArrayList<>();
+ private final ProcessingLogger logger;
+
+ private CapturingLogger(String loggingPrefix) {
+ logger =
+ new SinkProcessingLogger(
+ (severity, message) -> messages.add(severity + ": " + message), false, loggingPrefix);
+ }
+
+ private static CapturingLogger create() {
+ return new CapturingLogger(null);
+ }
+
+ private static CapturingLogger create(String loggingPrefix) {
+ return new CapturingLogger(loggingPrefix);
+ }
+
+ private ProcessingLogger logger() {
+ return logger;
+ }
+
+ private List messages() {
+ return messages;
+ }
+ }
+
/** Helper to create a tracker, track some data, and generate report with JSON output. */
private JsonNode generateReportAndParseJson(String outputFile) throws IOException {
- ActivePerformanceTracker tracker =
- new ActivePerformanceTracker(outputFile, PipelinePhases.PIPELINE_HIERARCHY);
+ ActivePerformanceTracker tracker = new ActivePerformanceTracker(outputFile, TEST_HIERARCHY);
tracker.startClass("TestClassA");
tracker.startPhase();
- tracker.endPhase(PipelinePhases.PHASE_ANALYSIS);
+ tracker.endPhase(PHASE_ANALYSIS);
tracker.startGenerator();
tracker.endGenerator("FieldSupplierGenerator");
tracker.startEnhancer();
@@ -64,10 +127,10 @@ private JsonNode generateReportAndParseJson(String outputFile) throws IOExceptio
tracker.startClass("TestClassB");
tracker.startPhase();
- tracker.endPhase(PipelinePhases.PHASE_TARGET_MAPPING);
+ tracker.endPhase(PHASE_TARGET_MAPPING);
tracker.endClass(3, 1);
- CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
+ CapturingLogger capturing = CapturingLogger.create();
ProcessingLogger logger = capturing.logger();
tracker.generateReport(logger);
@@ -111,18 +174,17 @@ private static JsonNode classMetricByName(JsonNode root, String className) {
*/
@Test
void generateReport_prefixedLogger_producesExpectedTaggedLayout() {
- ActivePerformanceTracker tracker =
- new ActivePerformanceTracker(null, PipelinePhases.PIPELINE_HIERARCHY);
+ ActivePerformanceTracker tracker = new ActivePerformanceTracker(null, TEST_HIERARCHY);
tracker.startClass("MyClass");
tracker.startPhase();
- tracker.endPhase(PipelinePhases.PHASE_ANALYSIS);
+ tracker.endPhase(PHASE_ANALYSIS);
tracker.startGenerator();
tracker.endGenerator("MyGenerator");
tracker.startEnhancer();
tracker.endEnhancer("MyEnhancer");
tracker.endClass(5, 2);
- CapturingProcessingLogger capturing = CapturingProcessingLogger.create("simple-builders");
+ CapturingLogger capturing = CapturingLogger.create("simple-builders");
tracker.generateReport(capturing.logger());
// Remove the diagnostic kind marker and the exact measurements (durations, percentages,
@@ -179,9 +241,8 @@ void generateReport_prefixedLogger_producesExpectedTaggedLayout() {
@Test
void generateReport_withNoData_logsBasicReport() {
- ActivePerformanceTracker tracker =
- new ActivePerformanceTracker(null, PipelinePhases.PIPELINE_HIERARCHY);
- CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
+ ActivePerformanceTracker tracker = new ActivePerformanceTracker(null, TEST_HIERARCHY);
+ CapturingLogger capturing = CapturingLogger.create();
ProcessingLogger logger = capturing.logger();
tracker.generateReport(logger);
@@ -193,12 +254,11 @@ void generateReport_withNoData_logsBasicReport() {
@Test
void generateReport_withClassData_logsClassCount() {
- ActivePerformanceTracker tracker =
- new ActivePerformanceTracker(null, PipelinePhases.PIPELINE_HIERARCHY);
+ ActivePerformanceTracker tracker = new ActivePerformanceTracker(null, TEST_HIERARCHY);
tracker.startClass("MyClass");
tracker.endClass(4, 1);
- CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
+ CapturingLogger capturing = CapturingLogger.create();
ProcessingLogger logger = capturing.logger();
tracker.generateReport(logger);
@@ -209,14 +269,13 @@ void generateReport_withClassData_logsClassCount() {
@Test
void generateReport_withGeneratorData_logsGeneratorStats() {
- ActivePerformanceTracker tracker =
- new ActivePerformanceTracker(null, PipelinePhases.PIPELINE_HIERARCHY);
+ ActivePerformanceTracker tracker = new ActivePerformanceTracker(null, TEST_HIERARCHY);
tracker.startClass("MyClass");
tracker.startGenerator();
tracker.endGenerator("MyGenerator");
tracker.endClass(2, 0);
- CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
+ CapturingLogger capturing = CapturingLogger.create();
ProcessingLogger logger = capturing.logger();
tracker.generateReport(logger);
@@ -226,14 +285,13 @@ void generateReport_withGeneratorData_logsGeneratorStats() {
@Test
void generateReport_withEnhancerData_logsEnhancerStats() {
- ActivePerformanceTracker tracker =
- new ActivePerformanceTracker(null, PipelinePhases.PIPELINE_HIERARCHY);
+ ActivePerformanceTracker tracker = new ActivePerformanceTracker(null, TEST_HIERARCHY);
tracker.startClass("MyClass");
tracker.startEnhancer();
tracker.endEnhancer("MyEnhancer");
tracker.endClass(2, 0);
- CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
+ CapturingLogger capturing = CapturingLogger.create();
ProcessingLogger logger = capturing.logger();
tracker.generateReport(logger);
@@ -243,61 +301,55 @@ void generateReport_withEnhancerData_logsEnhancerStats() {
@Test
void generateReport_withPhaseData_logsPhaseBreakdown() {
- ActivePerformanceTracker tracker =
- new ActivePerformanceTracker(null, PipelinePhases.PIPELINE_HIERARCHY);
+ ActivePerformanceTracker tracker = new ActivePerformanceTracker(null, TEST_HIERARCHY);
tracker.startPhase();
- tracker.endPhase(PipelinePhases.PHASE_CONFIGURATION_RESOLUTION);
+ tracker.endPhase(PHASE_CONFIGURATION_RESOLUTION);
tracker.startPhase();
- tracker.endPhase(PipelinePhases.PHASE_CODE_GENERATION);
+ tracker.endPhase(PHASE_CODE_GENERATION);
- CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
+ CapturingLogger capturing = CapturingLogger.create();
ProcessingLogger logger = capturing.logger();
tracker.generateReport(logger);
assertTrue(capturing.messages().stream().anyMatch(m -> m.contains("Phase breakdown")));
assertTrue(
- capturing.messages().stream()
- .anyMatch(m -> m.contains(PipelinePhases.PHASE_CONFIGURATION_RESOLUTION)));
- assertTrue(
- capturing.messages().stream()
- .anyMatch(m -> m.contains(PipelinePhases.PHASE_CODE_GENERATION)));
+ capturing.messages().stream().anyMatch(m -> m.contains(PHASE_CONFIGURATION_RESOLUTION)));
+ assertTrue(capturing.messages().stream().anyMatch(m -> m.contains(PHASE_CODE_GENERATION)));
}
@Test
void generateReport_withElementCollectionPhase_logsPhaseInReport() {
- ActivePerformanceTracker tracker =
- new ActivePerformanceTracker(null, PipelinePhases.PIPELINE_HIERARCHY);
+ ActivePerformanceTracker tracker = new ActivePerformanceTracker(null, TEST_HIERARCHY);
tracker.startPhase();
- tracker.endPhase(PipelinePhases.PHASE_ELEMENT_COLLECTION);
+ tracker.endPhase(PHASE_ELEMENT_COLLECTION);
- CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
+ CapturingLogger capturing = CapturingLogger.create();
ProcessingLogger logger = capturing.logger();
tracker.generateReport(logger);
assertTrue(
- capturing.messages().stream()
- .anyMatch(m -> m.contains(PipelinePhases.PHASE_ELEMENT_COLLECTION)),
- "Text report should contain " + PipelinePhases.PHASE_ELEMENT_COLLECTION);
+ capturing.messages().stream().anyMatch(m -> m.contains(PHASE_ELEMENT_COLLECTION)),
+ "Text report should contain " + PHASE_ELEMENT_COLLECTION);
}
@Test
void jsonReport_phaseBreakdown_containsElementCollectionPhase() throws IOException {
Path jsonFile = tempDir.resolve("report-element-collection.json");
ActivePerformanceTracker tracker =
- new ActivePerformanceTracker(jsonFile.toString(), PipelinePhases.PIPELINE_HIERARCHY);
+ new ActivePerformanceTracker(jsonFile.toString(), TEST_HIERARCHY);
tracker.startPhase();
- tracker.endPhase(PipelinePhases.PHASE_ELEMENT_COLLECTION);
+ tracker.endPhase(PHASE_ELEMENT_COLLECTION);
- CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
+ CapturingLogger capturing = CapturingLogger.create();
ProcessingLogger logger = capturing.logger();
tracker.generateReport(logger);
JsonNode root = new ObjectMapper().readTree(Files.readString(jsonFile));
JsonNode phases = root.get("phaseBreakdown");
assertTrue(
- phases.has(PipelinePhases.PHASE_ELEMENT_COLLECTION),
- "JSON phaseBreakdown should contain " + PipelinePhases.PHASE_ELEMENT_COLLECTION);
- JsonNode elementCollection = phases.get(PipelinePhases.PHASE_ELEMENT_COLLECTION);
+ phases.has(PHASE_ELEMENT_COLLECTION),
+ "JSON phaseBreakdown should contain " + PHASE_ELEMENT_COLLECTION);
+ JsonNode elementCollection = phases.get(PHASE_ELEMENT_COLLECTION);
assertTrue(elementCollection.has("elapsedNanos"));
assertTrue(elementCollection.has("elapsedSeconds"));
assertTrue(elementCollection.has("percentage"));
@@ -305,12 +357,11 @@ void jsonReport_phaseBreakdown_containsElementCollectionPhase() throws IOExcepti
@Test
void generateReport_withNullOutputFile_doesNotWriteFile() {
- ActivePerformanceTracker tracker =
- new ActivePerformanceTracker(null, PipelinePhases.PIPELINE_HIERARCHY);
+ ActivePerformanceTracker tracker = new ActivePerformanceTracker(null, TEST_HIERARCHY);
tracker.startClass("MyClass");
tracker.endClass(1, 0);
- CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
+ CapturingLogger capturing = CapturingLogger.create();
ProcessingLogger logger = capturing.logger();
tracker.generateReport(logger);
@@ -386,12 +437,12 @@ void jsonReport_phaseBreakdown_containsPhaseHierarchy() throws IOException {
JsonNode root = generateReportAndParseJson(jsonFile.toString());
JsonNode phases = root.get("phaseBreakdown");
- assertTrue(phases.has(PipelinePhases.PHASE_CONFIGURATION_RESOLUTION));
- assertTrue(phases.has(PipelinePhases.PHASE_ANALYSIS));
- assertTrue(phases.has(PipelinePhases.PHASE_TARGET_MAPPING));
- assertTrue(phases.has(PipelinePhases.PHASE_CODE_GENERATION));
+ assertTrue(phases.has(PHASE_CONFIGURATION_RESOLUTION));
+ assertTrue(phases.has(PHASE_ANALYSIS));
+ assertTrue(phases.has(PHASE_TARGET_MAPPING));
+ assertTrue(phases.has(PHASE_CODE_GENERATION));
- JsonNode codeGen = phases.get(PipelinePhases.PHASE_CODE_GENERATION);
+ JsonNode codeGen = phases.get(PHASE_CODE_GENERATION);
assertTrue(codeGen.has("elapsedNanos"));
assertTrue(codeGen.has("elapsedSeconds"));
assertTrue(codeGen.has("percentage"));
@@ -402,7 +453,7 @@ void jsonReport_phaseBreakdown_codeGenerationHasChildren() throws IOException {
Path jsonFile = tempDir.resolve("report.json");
JsonNode root = generateReportAndParseJson(jsonFile.toString());
- JsonNode codeGen = root.get("phaseBreakdown").get(PipelinePhases.PHASE_CODE_GENERATION);
+ JsonNode codeGen = root.get("phaseBreakdown").get(PHASE_CODE_GENERATION);
assertTrue(codeGen.has("children"));
JsonNode children = codeGen.get("children");
assertTrue(children.has(GenerationPhases.PHASE_SOURCE_CONSTRUCTION));
@@ -413,9 +464,9 @@ void jsonReport_phaseBreakdown_codeGenerationHasChildren() throws IOException {
void jsonReport_withNoData_hasEmptyArrays() throws IOException {
Path jsonFile = tempDir.resolve("report-empty.json");
ActivePerformanceTracker tracker =
- new ActivePerformanceTracker(jsonFile.toString(), PipelinePhases.PIPELINE_HIERARCHY);
+ new ActivePerformanceTracker(jsonFile.toString(), TEST_HIERARCHY);
- CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
+ CapturingLogger capturing = CapturingLogger.create();
ProcessingLogger logger = capturing.logger();
tracker.generateReport(logger);
@@ -440,14 +491,13 @@ void jsonReport_createsParentDirectoriesIfMissing() throws IOException {
@Test
void endMethodsWithoutStart_doesNothing() {
- ActivePerformanceTracker tracker =
- new ActivePerformanceTracker(null, PipelinePhases.PIPELINE_HIERARCHY);
- tracker.endPhase(PipelinePhases.PHASE_CONFIGURATION_RESOLUTION);
+ ActivePerformanceTracker tracker = new ActivePerformanceTracker(null, TEST_HIERARCHY);
+ tracker.endPhase(PHASE_CONFIGURATION_RESOLUTION);
tracker.endGenerator("NonexistentGenerator");
tracker.endEnhancer("NonexistentEnhancer");
tracker.endClass(5, 2);
- CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
+ CapturingLogger capturing = CapturingLogger.create();
ProcessingLogger logger = capturing.logger();
tracker.generateReport(logger);
@@ -462,7 +512,7 @@ void endMethodsWithoutStart_doesNothing() {
void multipleGenerators_accumulateTimeAndCalls() throws IOException {
Path jsonFile = tempDir.resolve("report-multi-gen.json");
ActivePerformanceTracker tracker =
- new ActivePerformanceTracker(jsonFile.toString(), PipelinePhases.PIPELINE_HIERARCHY);
+ new ActivePerformanceTracker(jsonFile.toString(), TEST_HIERARCHY);
tracker.startClass("MyClass");
tracker.startGenerator();
tracker.endGenerator("GenA");
@@ -472,7 +522,7 @@ void multipleGenerators_accumulateTimeAndCalls() throws IOException {
tracker.endGenerator("GenB");
tracker.endClass(2, 0);
- CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
+ CapturingLogger capturing = CapturingLogger.create();
ProcessingLogger logger = capturing.logger();
tracker.generateReport(logger);
@@ -488,7 +538,7 @@ void multipleGenerators_accumulateTimeAndCalls() throws IOException {
void jsonReport_escapesSpecialCharactersInNames() throws IOException {
Path jsonFile = tempDir.resolve("report-escaping.json");
ActivePerformanceTracker tracker =
- new ActivePerformanceTracker(jsonFile.toString(), PipelinePhases.PIPELINE_HIERARCHY);
+ new ActivePerformanceTracker(jsonFile.toString(), TEST_HIERARCHY);
tracker.startClass("MyClass");
tracker.startGenerator();
tracker.endGenerator("Gen\"\\\n\t\r\b\fA\u0001");
@@ -497,7 +547,7 @@ void jsonReport_escapesSpecialCharactersInNames() throws IOException {
tracker.endEnhancer("Enh\u0001x");
tracker.endClass(2, 0);
- tracker.generateReport(CapturingProcessingLogger.create().logger());
+ tracker.generateReport(CapturingLogger.create().logger());
JsonNode root = new ObjectMapper().readTree(Files.readString(jsonFile));
JsonNode genStats = root.get("generatorStats");
@@ -510,30 +560,29 @@ void jsonReport_escapesSpecialCharactersInNames() throws IOException {
void multiplePhases_accumulateTime() throws IOException {
Path jsonFile = tempDir.resolve("report-multi-phase.json");
ActivePerformanceTracker tracker =
- new ActivePerformanceTracker(jsonFile.toString(), PipelinePhases.PIPELINE_HIERARCHY);
+ new ActivePerformanceTracker(jsonFile.toString(), TEST_HIERARCHY);
tracker.startPhase();
- tracker.endPhase(PipelinePhases.PHASE_CONFIGURATION_RESOLUTION);
+ tracker.endPhase(PHASE_CONFIGURATION_RESOLUTION);
tracker.startPhase();
- tracker.endPhase(PipelinePhases.PHASE_CONFIGURATION_RESOLUTION);
+ tracker.endPhase(PHASE_CONFIGURATION_RESOLUTION);
- CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
+ CapturingLogger capturing = CapturingLogger.create();
ProcessingLogger logger = capturing.logger();
tracker.generateReport(logger);
JsonNode root = new ObjectMapper().readTree(Files.readString(jsonFile));
- JsonNode phase = root.get("phaseBreakdown").get(PipelinePhases.PHASE_CONFIGURATION_RESOLUTION);
+ JsonNode phase = root.get("phaseBreakdown").get(PHASE_CONFIGURATION_RESOLUTION);
assertTrue(phase.get("elapsedNanos").asLong() > 0);
}
@Test
void generateReport_logsWarningOnInvalidPath() {
ActivePerformanceTracker tracker =
- new ActivePerformanceTracker(
- "/nonexistent\0invalid/path.json", PipelinePhases.PIPELINE_HIERARCHY);
+ new ActivePerformanceTracker("/nonexistent\0invalid/path.json", TEST_HIERARCHY);
tracker.startClass("MyClass");
tracker.endClass(1, 0);
- CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
+ CapturingLogger capturing = CapturingLogger.create();
ProcessingLogger logger = capturing.logger();
tracker.generateReport(logger);
@@ -545,7 +594,7 @@ void generateReport_logsWarningOnInvalidPath() {
@Test
void noOpPerformanceTracker_allMethodsAreNoOps() {
NoOpPerformanceTracker tracker = new NoOpPerformanceTracker();
- CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
+ CapturingLogger capturing = CapturingLogger.create();
ProcessingLogger logger = capturing.logger();
tracker.startPhase();
@@ -565,7 +614,7 @@ void noOpPerformanceTracker_allMethodsAreNoOps() {
void jsonReport_generatorAndEnhancerStats_sortedByElapsedDesc() throws IOException {
Path jsonFile = tempDir.resolve("report-sorted.json");
ActivePerformanceTracker tracker =
- new ActivePerformanceTracker(jsonFile.toString(), PipelinePhases.PIPELINE_HIERARCHY);
+ new ActivePerformanceTracker(jsonFile.toString(), TEST_HIERARCHY);
tracker.startClass("MyClass");
tracker.startGenerator();
tracker.endGenerator("SlowGen");
@@ -577,7 +626,7 @@ void jsonReport_generatorAndEnhancerStats_sortedByElapsedDesc() throws IOExcepti
tracker.endEnhancer("FastEnh");
tracker.endClass(2, 0);
- CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
+ CapturingLogger capturing = CapturingLogger.create();
ProcessingLogger logger = capturing.logger();
tracker.generateReport(logger);
diff --git a/codegen-core/src/test/java/org/javahelpers/codegen/logging/SinkProcessingLoggerTest.java b/codegen-core/src/test/java/org/javahelpers/codegen/logging/SinkProcessingLoggerTest.java
new file mode 100644
index 00000000..9a766f96
--- /dev/null
+++ b/codegen-core/src/test/java/org/javahelpers/codegen/logging/SinkProcessingLoggerTest.java
@@ -0,0 +1,110 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2025-2026 Andreas Igel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.javahelpers.codegen.logging;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.jupiter.api.Test;
+
+/** Unit tests for {@link SinkProcessingLogger} — flat vs. hierarchical emission to a sink. */
+class SinkProcessingLoggerTest {
+
+ @Test
+ void nonVerbose_emitsFlatPrefixedMessages() {
+ List messages = new ArrayList<>();
+ SinkProcessingLogger logger =
+ new SinkProcessingLogger((sev, msg) -> messages.add(sev + ": " + msg), false, "test");
+
+ logger.info("hello %s", "world");
+ logger.warning("careful");
+ logger.error("boom");
+ logger.debug("hidden");
+
+ assertEquals(
+ List.of("NOTE: test: hello world", "WARNING: test: careful", "ERROR: test: boom"),
+ messages);
+ }
+
+ @Test
+ void verbose_debugCarriesDebugPrefixAndTreeMarker() {
+ List messages = new ArrayList<>();
+ SinkProcessingLogger logger =
+ new SinkProcessingLogger((sev, msg) -> messages.add(sev + ": " + msg), true, "test");
+
+ logger.debug("flat detail");
+ logger.debugStartOperation("outer op");
+ logger.debug("nested detail");
+ logger.debugEndOperation("outer done");
+ logger.debug("flat again");
+
+ assertEquals(
+ List.of(
+ "OTHER: [DEBUG] test: flat detail",
+ "NOTE: [DEBUG] test: outer op",
+ "OTHER: [DEBUG] test: ├─ nested detail",
+ "NOTE: [DEBUG] test: └─ outer done",
+ "OTHER: [DEBUG] test: flat again"),
+ messages);
+ }
+
+ @Test
+ void verbose_warningAtNestedLevelGetsHierarchicalIndent() {
+ List messages = new ArrayList<>();
+ SinkProcessingLogger logger =
+ new SinkProcessingLogger((sev, msg) -> messages.add(sev + ": " + msg), true, "test");
+
+ logger.debugStartOperation("op");
+ logger.warning("at level one");
+
+ assertEquals(
+ List.of("NOTE: [DEBUG] test: op", "WARNING: test: └─ at level one"), messages);
+ }
+
+ @Test
+ void noPrefix_leavesMessageUnchanged() {
+ List messages = new ArrayList<>();
+ SinkProcessingLogger logger =
+ new SinkProcessingLogger((sev, msg) -> messages.add(msg), false, null);
+
+ logger.info("plain");
+
+ assertEquals(List.of("plain"), messages);
+ }
+
+ @Test
+ void resetIndentation_returnsToLevelZero() {
+ List messages = new ArrayList<>();
+ SinkProcessingLogger logger =
+ new SinkProcessingLogger((sev, msg) -> messages.add(msg), true, null);
+
+ logger.debugStartOperation("op");
+ assertTrue(logger.getCurrentIndentationLevel() > 0);
+ logger.resetIndentation();
+ assertEquals(0, logger.getCurrentIndentationLevel());
+ }
+}
diff --git a/codegen-core/src/test/java/org/javahelpers/codegen/util/ImportCollectorTest.java b/codegen-core/src/test/java/org/javahelpers/codegen/util/ImportCollectorTest.java
new file mode 100644
index 00000000..56e628fe
--- /dev/null
+++ b/codegen-core/src/test/java/org/javahelpers/codegen/util/ImportCollectorTest.java
@@ -0,0 +1,97 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2025-2026 Andreas Igel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.javahelpers.codegen.util;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.List;
+import org.javahelpers.codegen.model.core.ClassFieldDto;
+import org.javahelpers.codegen.model.core.GenerationTargetClassDto;
+import org.javahelpers.codegen.model.imports.ImportStatement;
+import org.javahelpers.codegen.model.method.MethodDto;
+import org.javahelpers.codegen.model.method.MethodParameterDto;
+import org.javahelpers.codegen.model.type.TypeName;
+import org.junit.jupiter.api.Test;
+
+/** Unit tests for {@link ImportCollector}: skip rules, generic args and sort order. */
+class ImportCollectorTest {
+
+ private static List fqns(GenerationTargetClassDto classDef) {
+ return ImportCollector.collectAndSortImports(classDef).stream()
+ .map(ImportStatement::getFullyQualifiedName)
+ .toList();
+ }
+
+ private static GenerationTargetClassDto classDef(String pkg, String name) {
+ GenerationTargetClassDto classDef = new GenerationTargetClassDto();
+ classDef.setTypeName(new TypeName(pkg, name));
+ return classDef;
+ }
+
+ private static ClassFieldDto field(String name, String pkg, String type) {
+ ClassFieldDto field = new ClassFieldDto();
+ field.setFieldName(name);
+ field.setFieldType(new TypeName(pkg, type));
+ return field;
+ }
+
+ @Test
+ void skipsJavaLangAndSamePackageTypes() {
+ GenerationTargetClassDto classDef = classDef("com.example", "Dto");
+ classDef.addClassField(field("samePackage", "com.example", "Sibling"));
+ classDef.addClassField(field("langType", "java.lang", "String"));
+ classDef.addClassField(field("needed", "java.util", "Optional"));
+
+ assertEquals(List.of("java.util.Optional"), fqns(classDef));
+ }
+
+ @Test
+ void importsSortedAlphabetically() {
+ GenerationTargetClassDto classDef = classDef("com.example", "Dto");
+ classDef.addClassField(field("z", "java.util", "TreeSet"));
+ classDef.addClassField(field("a", "java.util", "ArrayDeque"));
+ classDef.addClassField(field("m", "java.time", "Instant"));
+
+ assertEquals(
+ List.of("java.time.Instant", "java.util.ArrayDeque", "java.util.TreeSet"), fqns(classDef));
+ }
+
+ @Test
+ void genericTypeImportsRawTypeAndArguments() {
+ GenerationTargetClassDto classDef = classDef("com.example", "Dto");
+ classDef.addClassField(field("mapping", "com.example", "StringIntegerMap"));
+
+ MethodDto method = new MethodDto("values", new TypeName("java.util", "Collection"));
+ MethodParameterDto param = new MethodParameterDto();
+ param.setParameterName("key");
+ param.setParameterTypeName(new TypeName("com.other", "KeyDto"));
+ method.addParameter(param);
+ classDef.addMethod(method);
+
+ assertTrue(fqns(classDef).contains("java.util.Collection"));
+ assertTrue(fqns(classDef).contains("com.other.KeyDto"));
+ }
+}
diff --git a/processor/src/test/java/org/javahelpers/simple/builders/processor/RoasterCodeGeneratorResilienceTest.java b/codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterCodeGeneratorResilienceTest.java
similarity index 78%
rename from processor/src/test/java/org/javahelpers/simple/builders/processor/RoasterCodeGeneratorResilienceTest.java
rename to codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterCodeGeneratorResilienceTest.java
index 7fa0ceb4..e681bbed 100644
--- a/processor/src/test/java/org/javahelpers/simple/builders/processor/RoasterCodeGeneratorResilienceTest.java
+++ b/codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterCodeGeneratorResilienceTest.java
@@ -22,16 +22,20 @@
* SOFTWARE.
*/
-package org.javahelpers.simple.builders.processor;
+package org.javahelpers.codegen.roaster;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import javax.annotation.processing.ProcessingEnvironment;
import org.javahelpers.codegen.CodeGenerationException;
+import org.javahelpers.codegen.GeneratedSourceFile;
+import org.javahelpers.codegen.GenerationEnvironment;
+import org.javahelpers.codegen.GenerationIssueReporter;
import org.javahelpers.codegen.SourceFormatter;
import org.javahelpers.codegen.enums.AccessModifier;
import org.javahelpers.codegen.enums.FormattingMode;
+import org.javahelpers.codegen.logging.NoOpPerformanceTracker;
+import org.javahelpers.codegen.logging.PerformanceTracker;
import org.javahelpers.codegen.logging.ProcessingLogger;
import org.javahelpers.codegen.model.core.GenerationTargetClassDto;
import org.javahelpers.codegen.model.method.ConstructorDto;
@@ -40,15 +44,8 @@
import org.javahelpers.codegen.model.method.MethodDto;
import org.javahelpers.codegen.model.method.MethodParameterDto;
import org.javahelpers.codegen.model.type.TypeName;
-import org.javahelpers.codegen.processing.AnnotationProcessingEnvironment;
-import org.javahelpers.codegen.processing.logging.MessagerProcessingLogger;
-import org.javahelpers.codegen.roaster.RoasterCodeGenerator;
-import org.javahelpers.codegen.roaster.RoasterSourceFormatter;
import org.javahelpers.codegen.roaster.exceptions.RoasterMapperException;
import org.javahelpers.codegen.testing.CapturingProcessingLogger;
-import org.javahelpers.codegen.testing.ProcessingEnvironmentStub;
-import org.javahelpers.simple.builders.processor.model.core.BuilderConfiguration;
-import org.javahelpers.simple.builders.processor.processing.BuilderProcessingContext;
import org.junit.jupiter.api.Test;
/**
@@ -62,6 +59,35 @@
*/
class RoasterCodeGeneratorResilienceTest {
+ /**
+ * Minimal {@link GenerationEnvironment} built only from codegen-core types: issues surface on the
+ * logger as warnings, timing is not tracked, and {@code createSourceFile} returns {@code null} so
+ * the file-write step fails deterministically on it.
+ */
+ private static GenerationEnvironment stubEnvironment(ProcessingLogger logger) {
+ return new GenerationEnvironment() {
+ @Override
+ public ProcessingLogger getLogger() {
+ return logger;
+ }
+
+ @Override
+ public PerformanceTracker getPerformanceTracker() {
+ return new NoOpPerformanceTracker();
+ }
+
+ @Override
+ public GenerationIssueReporter getIssueReporter() {
+ return logger::warning;
+ }
+
+ @Override
+ public GeneratedSourceFile createSourceFile(CharSequence qualifiedName) {
+ return null;
+ }
+ };
+ }
+
/** Placeholder subtype the mapper does not know how to render, forcing a mapping failure. */
private static final class UnsupportedPlaceholder extends MethodCodePlaceholder {
private UnsupportedPlaceholder(String label, String value) {
@@ -84,14 +110,8 @@ void shouldWrapRenderingRuntimeExceptionInCodeGenerationException() {
constructor.setMethodCodeDto(code);
classDef.addConstructor(constructor);
- ProcessingEnvironment env = ProcessingEnvironmentStub.createEmpty();
- ProcessingLogger logger = MessagerProcessingLogger.create(env);
- BuilderProcessingContext context =
- new BuilderProcessingContext(logger, BuilderConfiguration.DEFAULT, env);
- RoasterCodeGenerator generator =
- new RoasterCodeGenerator(
- new AnnotationProcessingEnvironment(
- env, logger, context.getPerformanceTracker(), context::reportBasedOnStrictMode));
+ ProcessingLogger logger = CapturingProcessingLogger.create().logger();
+ RoasterCodeGenerator generator = new RoasterCodeGenerator(stubEnvironment(logger));
SourceFormatter formatter = new RoasterSourceFormatter(logger, FormattingMode.NONE);
CodeGenerationException thrown =
@@ -117,19 +137,10 @@ void shouldKeepFirstMethodAndWarnOnDuplicateSignature() {
classDef.addMethod(duplicateSignatureMethod("second"));
CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
- ProcessingEnvironment env = ProcessingEnvironmentStub.createEmpty();
- BuilderProcessingContext context =
- new BuilderProcessingContext(capturing.logger(), BuilderConfiguration.DEFAULT, env);
- RoasterCodeGenerator generator =
- new RoasterCodeGenerator(
- new AnnotationProcessingEnvironment(
- env,
- capturing.logger(),
- context.getPerformanceTracker(),
- context::reportBasedOnStrictMode));
+ RoasterCodeGenerator generator = new RoasterCodeGenerator(stubEnvironment(capturing.logger()));
SourceFormatter formatter = new RoasterSourceFormatter(capturing.logger(), FormattingMode.NONE);
- // generation itself succeeds; only the file-write step fails on the stub's null filer
+ // generation itself succeeds; only the file-write step fails on the stub's null source file
assertThrows(NullPointerException.class, () -> generator.generateClass(classDef, formatter));
capturing.assertMessage(
"WARNING: Unexpected duplicate method signature: 'name(java.lang.String)'"
diff --git a/codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterCodeGeneratorTest.java b/codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterCodeGeneratorTest.java
new file mode 100644
index 00000000..aee5a54a
--- /dev/null
+++ b/codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterCodeGeneratorTest.java
@@ -0,0 +1,190 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2025-2026 Andreas Igel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.javahelpers.codegen.roaster;
+
+import static org.javahelpers.codegen.testing.ProcessorAsserts.assertNormalizedEquals;
+
+import java.io.StringWriter;
+import java.io.Writer;
+import java.net.URI;
+import org.javahelpers.codegen.GeneratedSourceFile;
+import org.javahelpers.codegen.GenerationEnvironment;
+import org.javahelpers.codegen.GenerationIssueReporter;
+import org.javahelpers.codegen.SourceFormatter;
+import org.javahelpers.codegen.enums.AccessModifier;
+import org.javahelpers.codegen.enums.FormattingMode;
+import org.javahelpers.codegen.logging.NoOpPerformanceTracker;
+import org.javahelpers.codegen.logging.PerformanceTracker;
+import org.javahelpers.codegen.logging.ProcessingLogger;
+import org.javahelpers.codegen.model.core.ClassFieldDto;
+import org.javahelpers.codegen.model.core.GenerationTargetClassDto;
+import org.javahelpers.codegen.model.method.MethodDto;
+import org.javahelpers.codegen.model.method.MethodParameterDto;
+import org.javahelpers.codegen.model.type.TypeName;
+import org.javahelpers.codegen.testing.CapturingProcessingLogger;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests for {@link RoasterCodeGenerator} driving {@link GenerationTargetClassDto}s directly — no
+ * simple-builder types involved, the {@link GenerationEnvironment} is built from codegen-core types
+ * only and the emitted source is captured in memory and asserted as a whole text block.
+ */
+class RoasterCodeGeneratorTest {
+
+ private static final class CapturingFile implements GeneratedSourceFile {
+ private final String name;
+ private final StringWriter buffer = new StringWriter();
+
+ private CapturingFile(CharSequence qualifiedName) {
+ this.name = qualifiedName.toString();
+ }
+
+ @Override
+ public URI toUri() {
+ return URI.create("mem:///" + name.replace('.', '/') + ".java");
+ }
+
+ @Override
+ public Writer openWriter() {
+ return buffer;
+ }
+
+ private String source() {
+ return buffer.toString();
+ }
+ }
+
+ private static GenerationEnvironment environment(
+ ProcessingLogger logger, CapturingFile[] written) {
+ return new GenerationEnvironment() {
+ @Override
+ public ProcessingLogger getLogger() {
+ return logger;
+ }
+
+ @Override
+ public PerformanceTracker getPerformanceTracker() {
+ return new NoOpPerformanceTracker();
+ }
+
+ @Override
+ public GenerationIssueReporter getIssueReporter() {
+ return logger::warning;
+ }
+
+ @Override
+ public GeneratedSourceFile createSourceFile(CharSequence qualifiedName) {
+ CapturingFile file = new CapturingFile(qualifiedName);
+ written[0] = file;
+ return file;
+ }
+ };
+ }
+
+ /** A builder-style DTO: private target field, one delegating setter, one build method. */
+ private static GenerationTargetClassDto personBuilderDefinition() {
+ TypeName builderType = new TypeName("test", "PersonBuilder");
+ TypeName personType = new TypeName("test", "Person");
+
+ GenerationTargetClassDto target = new GenerationTargetClassDto();
+ target.setTypeName(builderType);
+ target.setClassAccessModifier(AccessModifier.PUBLIC);
+ target.setFormattingMode(FormattingMode.NONE);
+
+ ClassFieldDto field = new ClassFieldDto();
+ field.setFieldName("target");
+ field.setFieldType(personType);
+ field.setVisibility(AccessModifier.PRIVATE);
+ field.setLiteralInitializer("new Person()");
+ target.addClassField(field);
+
+ MethodDto name = new MethodDto("name", builderType);
+ name.setModifier(AccessModifier.PUBLIC);
+ MethodParameterDto param = new MethodParameterDto();
+ param.setParameterName("name");
+ param.setParameterTypeName(new TypeName("java.lang", "String"));
+ name.addParameter(param);
+ name.setCode(
+ """
+ target.setName(name);
+ return this;""");
+ target.addMethod(name);
+
+ MethodDto build = new MethodDto("build", personType);
+ build.setModifier(AccessModifier.PUBLIC);
+ build.setCode("return target;");
+ target.addMethod(build);
+ return target;
+ }
+
+ @Test
+ void generatesDelegatingBuilderFromDto() throws Exception {
+ CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
+ CapturingFile[] written = new CapturingFile[1];
+ RoasterCodeGenerator generator =
+ new RoasterCodeGenerator(environment(capturing.logger(), written));
+ SourceFormatter formatter = new RoasterSourceFormatter(capturing.logger(), FormattingMode.NONE);
+
+ generator.generateClass(personBuilderDefinition(), formatter);
+
+ assertNormalizedEquals(
+ """
+ package test;
+ public class PersonBuilder {
+
+ private Person target = new Person();
+
+ public PersonBuilder name(String name) {
+ target.setName(name);
+ return this;
+ }
+
+ public Person build() {
+ return target;
+ }
+ }""",
+ written[0].source(),
+ "generated PersonBuilder must match the expected source");
+ }
+
+ @Test
+ void writesFileUnderQualifiedName() throws Exception {
+ CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
+ CapturingFile[] written = new CapturingFile[1];
+ RoasterCodeGenerator generator =
+ new RoasterCodeGenerator(environment(capturing.logger(), written));
+
+ GenerationTargetClassDto empty = new GenerationTargetClassDto();
+ empty.setTypeName(new TypeName("com.example", "EmptyBuilder"));
+ empty.setClassAccessModifier(AccessModifier.PUBLIC);
+ empty.setFormattingMode(FormattingMode.NONE);
+
+ generator.generateClass(
+ empty, new RoasterSourceFormatter(capturing.logger(), FormattingMode.NONE));
+
+ org.junit.jupiter.api.Assertions.assertEquals(
+ "mem:///com/example/EmptyBuilder.java", written[0].toUri().toString());
+ }
+}
diff --git a/codegen-testing/src/test/java/org/javahelpers/codegen/testing/CapturingProcessingLoggerTest.java b/codegen-testing/src/test/java/org/javahelpers/codegen/testing/CapturingProcessingLoggerTest.java
new file mode 100644
index 00000000..d009554e
--- /dev/null
+++ b/codegen-testing/src/test/java/org/javahelpers/codegen/testing/CapturingProcessingLoggerTest.java
@@ -0,0 +1,73 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2025-2026 Andreas Igel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.javahelpers.codegen.testing;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Test;
+
+/** Unit tests for {@link CapturingProcessingLogger}. */
+class CapturingProcessingLoggerTest {
+
+ @Test
+ void capturesSeverityPrefixedMessages() {
+ CapturingProcessingLogger capturing = CapturingProcessingLogger.create("pfx");
+
+ capturing.logger().info("hello");
+ capturing.logger().warning("careful %s", "now");
+ capturing.logger().debug("suppressed");
+
+ assertEquals(
+ java.util.List.of("NOTE: pfx: hello", "WARNING: pfx: careful now"), capturing.messages());
+ }
+
+ @Test
+ void debugEnabled_capturesDebugMessages() {
+ CapturingProcessingLogger capturing = CapturingProcessingLogger.createDebugEnabled();
+
+ capturing.logger().debug("visible");
+
+ assertEquals(1, capturing.messages().size());
+ assertTrue(capturing.messages().get(0).startsWith("OTHER: [DEBUG]"));
+ }
+
+ @Test
+ void assertMessage_passesForCapturedMessage() {
+ CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
+
+ capturing.logger().info("expected");
+
+ capturing.assertMessage("NOTE: expected");
+ }
+
+ @Test
+ void assertMessage_failsForMissingMessage() {
+ CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
+
+ assertThrows(AssertionError.class, () -> capturing.assertMessage("NOTE: never emitted"));
+ }
+}
diff --git a/codegen-testing/src/test/java/org/javahelpers/codegen/testing/CodegenTestUtilsTest.java b/codegen-testing/src/test/java/org/javahelpers/codegen/testing/CodegenTestUtilsTest.java
new file mode 100644
index 00000000..41d90c21
--- /dev/null
+++ b/codegen-testing/src/test/java/org/javahelpers/codegen/testing/CodegenTestUtilsTest.java
@@ -0,0 +1,140 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2025-2026 Andreas Igel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.javahelpers.codegen.testing;
+
+import static com.google.testing.compile.CompilationSubject.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import com.google.testing.compile.Compilation;
+import java.util.Set;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.RoundEnvironment;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.TypeElement;
+import javax.tools.JavaFileObject;
+import org.junit.jupiter.api.Test;
+
+/** Unit tests for {@link CodegenTestUtils} — the compile-testing helpers themselves. */
+class CodegenTestUtilsTest {
+
+ /** Emits one fixed generated source file so {@code loadGeneratedSource} has something to read. */
+ private static class EmittingProcessor extends AbstractProcessor {
+ private boolean ran;
+
+ @Override
+ public SourceVersion getSupportedSourceVersion() {
+ return SourceVersion.latestSupported();
+ }
+
+ @Override
+ public Set getSupportedAnnotationTypes() {
+ return Set.of("*");
+ }
+
+ @Override
+ public boolean process(Set extends TypeElement> annotations, RoundEnvironment roundEnv) {
+ if (!ran && !roundEnv.processingOver()) {
+ ran = true;
+ try {
+ var file = processingEnv.getFiler().createSourceFile("test.Generated");
+ try (var writer = file.openWriter()) {
+ writer.write("package test;\npublic class Generated {}\n");
+ }
+ } catch (java.io.IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return false;
+ }
+ }
+
+ @Test
+ void forSource_derivesQualifiedNameFromSource() {
+ JavaFileObject file =
+ CodegenTestUtils.forSource(
+ """
+ package test.sub;
+ public record Item(String value) {}
+ """);
+
+ // compile-testing names in-memory files after the derived qualified name
+ assertTrue(file.getName().endsWith("Item.java"));
+ assertTrue(file.getName().contains("test/sub"));
+ }
+
+ @Test
+ void forSource_rejectsSourceWithoutTypeDeclaration() {
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> CodegenTestUtils.forSource("package test;\n// no type here\n"));
+ }
+
+ @Test
+ void createMockAnnotation_producesCompilableAnnotation() {
+ JavaFileObject annotation =
+ CodegenTestUtils.createMockAnnotation(
+ "test.anno", "Marker", "ElementType.FIELD", "String value();");
+
+ Compilation compilation =
+ CodegenTestUtils.createCompiler()
+ .compile(
+ annotation,
+ CodegenTestUtils.forSource(
+ """
+ package test;
+ public class Dto {
+ @test.anno.Marker("x")
+ private String field;
+ }
+ """));
+
+ assertThat(compilation).succeeded();
+ }
+
+ @Test
+ void loadGeneratedSource_readsEmittedFile() {
+ Compilation compilation =
+ CodegenTestUtils.createCompiler(new EmittingProcessor())
+ .compile(CodegenTestUtils.forSource("package test;\npublic class Dto {}\n"));
+
+ assertThat(compilation).succeeded();
+ assertEquals(
+ "package test;\npublic class Generated {}\n",
+ CodegenTestUtils.loadGeneratedSource(compilation, "Generated"));
+ }
+
+ @Test
+ void loadGeneratedSource_failsForMissingFile() {
+ Compilation compilation =
+ CodegenTestUtils.createCompiler()
+ .compile(CodegenTestUtils.forSource("package test;\npublic class Dto {}\n"));
+
+ assertThat(compilation).succeeded();
+ assertThrows(
+ AssertionError.class, () -> CodegenTestUtils.loadGeneratedSource(compilation, "Missing"));
+ }
+}
diff --git a/processor/src/test/java/org/javahelpers/simple/builders/processor/testing/FormatterProfileTestUtilsTest.java b/codegen-testing/src/test/java/org/javahelpers/codegen/testing/FormatterProfileTestUtilsTest.java
similarity index 95%
rename from processor/src/test/java/org/javahelpers/simple/builders/processor/testing/FormatterProfileTestUtilsTest.java
rename to codegen-testing/src/test/java/org/javahelpers/codegen/testing/FormatterProfileTestUtilsTest.java
index f7e15648..a7f08a4e 100644
--- a/processor/src/test/java/org/javahelpers/simple/builders/processor/testing/FormatterProfileTestUtilsTest.java
+++ b/codegen-testing/src/test/java/org/javahelpers/codegen/testing/FormatterProfileTestUtilsTest.java
@@ -22,7 +22,7 @@
* SOFTWARE.
*/
-package org.javahelpers.simple.builders.processor.testing;
+package org.javahelpers.codegen.testing;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -32,7 +32,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
-import org.javahelpers.codegen.testing.FormatterProfileTestUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
diff --git a/codegen-testing/src/test/java/org/javahelpers/codegen/testing/ProcessingEnvironmentStubTest.java b/codegen-testing/src/test/java/org/javahelpers/codegen/testing/ProcessingEnvironmentStubTest.java
new file mode 100644
index 00000000..7f272f3f
--- /dev/null
+++ b/codegen-testing/src/test/java/org/javahelpers/codegen/testing/ProcessingEnvironmentStubTest.java
@@ -0,0 +1,57 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2025-2026 Andreas Igel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.javahelpers.codegen.testing;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Map;
+import javax.annotation.processing.ProcessingEnvironment;
+import org.junit.jupiter.api.Test;
+
+/** Unit tests for {@link ProcessingEnvironmentStub}. */
+class ProcessingEnvironmentStubTest {
+
+ @Test
+ void createEmpty_returnsEmptyOptions() {
+ ProcessingEnvironment env = ProcessingEnvironmentStub.createEmpty();
+ assertTrue(env.getOptions().isEmpty());
+ }
+
+ @Test
+ void create_returnsProvidedOptions() {
+ ProcessingEnvironment env =
+ ProcessingEnvironmentStub.create(Map.of("verbose", "true", "strict", "false"));
+ assertEquals("true", env.getOptions().get("verbose"));
+ assertEquals("false", env.getOptions().get("strict"));
+ }
+
+ @Test
+ void builder_accumulatesOptions() {
+ ProcessingEnvironment env =
+ ProcessingEnvironmentStub.builder().put("a", "1").put("b", "2").build();
+ assertEquals(Map.of("a", "1", "b", "2"), env.getOptions());
+ }
+}
diff --git a/codegen-testing/src/test/java/org/javahelpers/codegen/testing/ProcessorAssertsTest.java b/codegen-testing/src/test/java/org/javahelpers/codegen/testing/ProcessorAssertsTest.java
new file mode 100644
index 00000000..61c00ae0
--- /dev/null
+++ b/codegen-testing/src/test/java/org/javahelpers/codegen/testing/ProcessorAssertsTest.java
@@ -0,0 +1,83 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2025-2026 Andreas Igel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.javahelpers.codegen.testing;
+
+import static org.javahelpers.codegen.testing.ProcessorAsserts.assertContaining;
+import static org.javahelpers.codegen.testing.ProcessorAsserts.assertNormalizedEquals;
+import static org.javahelpers.codegen.testing.ProcessorAsserts.assertNotContaining;
+import static org.javahelpers.codegen.testing.ProcessorAsserts.contains;
+import static org.javahelpers.codegen.testing.ProcessorAsserts.notContains;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import org.junit.jupiter.api.Test;
+
+/** Unit tests for {@link ProcessorAsserts} — asserting the assertion helpers themselves. */
+class ProcessorAssertsTest {
+
+ private static final String CODE = "public class Foo {\n private String name;\n}";
+
+ @Test
+ void assertContaining_passesWhenAllSearchStringsPresent() {
+ assertContaining(CODE, "class Foo", "String name");
+ }
+
+ @Test
+ void assertContaining_failsOnMissingSearchString() {
+ assertThrows(AssertionError.class, () -> assertContaining(CODE, "class Bar"));
+ }
+
+ @Test
+ void assertNotContaining_passesWhenSearchStringAbsent() {
+ assertNotContaining(CODE, "class Bar");
+ assertThrows(AssertionError.class, () -> assertNotContaining(CODE, "class Foo"));
+ }
+
+ @Test
+ void assertingResult_supportsRecordChecks() {
+ ProcessorAsserts.assertingResult(CODE, contains("class Foo"), notContains("class Bar"));
+ assertThrows(
+ AssertionError.class,
+ () -> ProcessorAsserts.assertingResult(CODE, notContains("class Foo")));
+ }
+
+ @Test
+ void assertNormalizedEquals_ignoresWhitespaceDifferences() {
+ assertNormalizedEquals(
+ """
+ package test;
+ public class Foo {
+ private String name;
+ }""",
+ "package test;\n public class Foo {\n private String name; \n}\n",
+ "whitespace-normalized comparison should pass");
+ }
+
+ @Test
+ void assertNormalizedEquals_failsOnContentDifference() {
+ assertThrows(
+ AssertionError.class,
+ () -> assertNormalizedEquals("public class Foo {}", "public class Bar {}", "mismatch"));
+ }
+}
diff --git a/codegen-testing/src/test/resources/eclipse-java-format.xml b/codegen-testing/src/test/resources/eclipse-java-format.xml
new file mode 100644
index 00000000..16144891
--- /dev/null
+++ b/codegen-testing/src/test/resources/eclipse-java-format.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/processor/pom.xml b/processor/pom.xml
index 152827d1..7bcc8de5 100644
--- a/processor/pom.xml
+++ b/processor/pom.xml
@@ -103,11 +103,6 @@
simple-processor${project.version}
-
- io.github.java-helpers.codegen
- codegen-roaster
- ${project.version}
- io.github.java-helpers.codegencodegen-testing
diff --git a/processor/src/main/java/org/javahelpers/simple/builders/processor/processing/BuilderDefinitionCreator.java b/processor/src/main/java/org/javahelpers/simple/builders/processor/processing/BuilderDefinitionCreator.java
index 19b0dd1a..c1dd899d 100644
--- a/processor/src/main/java/org/javahelpers/simple/builders/processor/processing/BuilderDefinitionCreator.java
+++ b/processor/src/main/java/org/javahelpers/simple/builders/processor/processing/BuilderDefinitionCreator.java
@@ -315,8 +315,8 @@ private static String buildSetterSourceDescription(
* same signature key are resolved by keeping the highest-priority one; losers are removed from
* their field/class method lists so they are never mapped to the rendering DTO.
*
- *
A generic safety net in {@link
- * org.javahelpers.codegen.roaster.RoasterCodeGenerator#resolveMethodConflicts} handles any
+ *
A generic safety net in the code generator's method-conflict resolution (see {@code
+ * RoasterCodeGenerator#resolveMethodConflicts} in the codegen-roaster backend) handles any
* remaining duplicates (e.g., from enhancer methods added after this step) by keeping the first
* occurrence.
*
diff --git a/simple-processor/src/test/java/org/javahelpers/codegen/analysis/FieldAnnotationExtractorTest.java b/simple-processor/src/test/java/org/javahelpers/codegen/analysis/FieldAnnotationExtractorTest.java
new file mode 100644
index 00000000..a9c96b37
--- /dev/null
+++ b/simple-processor/src/test/java/org/javahelpers/codegen/analysis/FieldAnnotationExtractorTest.java
@@ -0,0 +1,235 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2025-2026 Andreas Igel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.javahelpers.codegen.analysis;
+
+import static com.google.testing.compile.CompilationSubject.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import com.google.testing.compile.Compilation;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.BiConsumer;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.RoundEnvironment;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+import org.javahelpers.codegen.model.annotation.AnnotationDto;
+import org.javahelpers.codegen.model.type.TypeName;
+import org.javahelpers.codegen.processing.AnnotationProcessingContext;
+import org.javahelpers.codegen.testing.CapturingProcessingLogger;
+import org.javahelpers.codegen.testing.CodegenTestUtils;
+import org.junit.jupiter.api.Test;
+
+/** Unit tests for {@link FieldAnnotationExtractor} against elements captured from a compilation. */
+class FieldAnnotationExtractorTest {
+
+ private static class ProbeProcessor extends AbstractProcessor {
+ private final BiConsumer probe;
+ private boolean ran;
+
+ ProbeProcessor(BiConsumer probe) {
+ this.probe = probe;
+ }
+
+ @Override
+ public SourceVersion getSupportedSourceVersion() {
+ return SourceVersion.latestSupported();
+ }
+
+ @Override
+ public Set getSupportedAnnotationTypes() {
+ return Set.of("*");
+ }
+
+ @Override
+ public boolean process(Set extends TypeElement> annotations, RoundEnvironment roundEnv) {
+ if (ran || roundEnv.processingOver()) {
+ return false;
+ }
+ ran = true;
+ probe.accept(
+ roundEnv,
+ new AnnotationProcessingContext(
+ CapturingProcessingLogger.create().logger(), processingEnv));
+ return false;
+ }
+ }
+
+ private static VariableElement field(TypeElement dto, String fieldName) {
+ return dto.getEnclosedElements().stream()
+ .filter(VariableElement.class::isInstance)
+ .map(VariableElement.class::cast)
+ .filter(e -> e.getSimpleName().toString().equals(fieldName))
+ .findFirst()
+ .orElseThrow();
+ }
+
+ private static final String DTO_SOURCE =
+ """
+ package test;
+ public class Dto {
+ @Deprecated
+ private String legacy;
+ @test.Default("GENERAL")
+ private String mode;
+ @test.NonNull
+ private String required;
+ private String plain;
+ }
+ """;
+
+ private static final String ANNOTATION_SOURCES =
+ """
+ package test;
+ public @interface Default { String value(); }
+ """;
+
+ private static final String NONNULL_SOURCE =
+ """
+ package test;
+ public @interface NonNull {}
+ """;
+
+ private Compilation compile(BiConsumer probe) {
+ return CodegenTestUtils.createCompiler(new ProbeProcessor(probe))
+ .compile(
+ CodegenTestUtils.forSource(DTO_SOURCE),
+ CodegenTestUtils.forSource(ANNOTATION_SOURCES),
+ CodegenTestUtils.forSource(NONNULL_SOURCE));
+ }
+
+ @Test
+ void extractDeprecatedAnnotation_findsDeprecatedField() {
+ AtomicReference> result = new AtomicReference<>();
+ Compilation compilation =
+ compile(
+ (roundEnv, ctx) ->
+ result.set(
+ FieldAnnotationExtractor.extractDeprecatedAnnotation(
+ field(ctx.getTypeElement("test.Dto"), "legacy"), ctx)));
+
+ assertThat(compilation).succeeded();
+ assertTrue(result.get().isPresent());
+ assertEquals(
+ "java.lang.Deprecated",
+ result.get().get().getAnnotationType().getPackageName()
+ + "."
+ + result.get().get().getAnnotationType().getClassName());
+ }
+
+ @Test
+ void extractDeprecatedAnnotation_emptyForPlainField() {
+ AtomicReference> result = new AtomicReference<>();
+ Compilation compilation =
+ compile(
+ (roundEnv, ctx) ->
+ result.set(
+ FieldAnnotationExtractor.extractDeprecatedAnnotation(
+ field(ctx.getTypeElement("test.Dto"), "plain"), ctx)));
+
+ assertThat(compilation).succeeded();
+ assertTrue(result.get().isEmpty());
+ }
+
+ @Test
+ void extractAnnotations_returnsMemberValues() {
+ AtomicReference> result = new AtomicReference<>();
+ Compilation compilation =
+ compile(
+ (roundEnv, ctx) ->
+ result.set(
+ FieldAnnotationExtractor.extractAnnotations(
+ field(ctx.getTypeElement("test.Dto"), "mode"), ctx)));
+
+ assertThat(compilation).succeeded();
+ assertEquals(1, result.get().size());
+ AnnotationDto annotation = result.get().get(0);
+ assertEquals("Default", annotation.getAnnotationType().getClassName());
+ assertEquals("\"GENERAL\"", annotation.getMembers().get("value"));
+ }
+
+ @Test
+ void hasNonNullConstraint_detectsNonNullAnnotation() {
+ AtomicReference nonNull = new AtomicReference<>();
+ AtomicReference plain = new AtomicReference<>();
+ Compilation compilation =
+ compile(
+ (roundEnv, ctx) -> {
+ TypeElement dto = ctx.getTypeElement("test.Dto");
+ nonNull.set(FieldAnnotationExtractor.hasNonNullConstraint(field(dto, "required")));
+ plain.set(FieldAnnotationExtractor.hasNonNullConstraint(field(dto, "plain")));
+ });
+
+ assertThat(compilation).succeeded();
+ assertTrue(nonNull.get());
+ assertFalse(plain.get());
+ }
+
+ @Test
+ void extractAnnotationValue_matchesAnnotationBySimpleName() {
+ AtomicReference> result = new AtomicReference<>();
+ Compilation compilation =
+ compile(
+ (roundEnv, ctx) ->
+ result.set(
+ FieldAnnotationExtractor.extractAnnotationValue(
+ field(ctx.getTypeElement("test.Dto"), "mode"), Set.of("Default"))));
+
+ assertThat(compilation).succeeded();
+ assertEquals(Optional.of("GENERAL"), result.get());
+ }
+
+ @Test
+ void formatDefaultExpression_quotesStringValues() {
+ assertEquals(
+ "\"GENERAL\"",
+ FieldAnnotationExtractor.formatDefaultExpression("GENERAL", TypeName.of(String.class)));
+ }
+
+ @Test
+ void formatDefaultExpression_qualifiesSimpleEnumConstant() {
+ TypeName enumType = new TypeName("test", "ItemCondition");
+ enumType.setEnumType(true);
+ assertEquals(
+ "ItemCondition.GOOD", FieldAnnotationExtractor.formatDefaultExpression("GOOD", enumType));
+ }
+
+ @Test
+ void formatDefaultExpression_keepsComplexExpressions() {
+ TypeName enumType = new TypeName("test", "ItemCondition");
+ enumType.setEnumType(true);
+ assertEquals(
+ "ItemCondition.GOOD",
+ FieldAnnotationExtractor.formatDefaultExpression("ItemCondition.GOOD", enumType));
+ assertEquals(
+ "List.of()",
+ FieldAnnotationExtractor.formatDefaultExpression("List.of()", TypeName.of(List.class)));
+ }
+}
diff --git a/processor/src/test/java/org/javahelpers/simple/builders/processor/JavaLangAnalyserTest.java b/simple-processor/src/test/java/org/javahelpers/codegen/analysis/JavaLangAnalyserTest.java
similarity index 98%
rename from processor/src/test/java/org/javahelpers/simple/builders/processor/JavaLangAnalyserTest.java
rename to simple-processor/src/test/java/org/javahelpers/codegen/analysis/JavaLangAnalyserTest.java
index 1a211d13..c7ed3033 100644
--- a/processor/src/test/java/org/javahelpers/simple/builders/processor/JavaLangAnalyserTest.java
+++ b/simple-processor/src/test/java/org/javahelpers/codegen/analysis/JavaLangAnalyserTest.java
@@ -22,7 +22,7 @@
* SOFTWARE.
*/
-package org.javahelpers.simple.builders.processor;
+package org.javahelpers.codegen.analysis;
import static org.junit.jupiter.api.Assertions.*;
@@ -38,7 +38,6 @@
import javax.lang.model.element.Name;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeMirror;
-import org.javahelpers.codegen.analysis.JavaLangAnalyser;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
diff --git a/simple-processor/src/test/java/org/javahelpers/codegen/analysis/JavaLangMapperTest.java b/simple-processor/src/test/java/org/javahelpers/codegen/analysis/JavaLangMapperTest.java
new file mode 100644
index 00000000..34c2a0fb
--- /dev/null
+++ b/simple-processor/src/test/java/org/javahelpers/codegen/analysis/JavaLangMapperTest.java
@@ -0,0 +1,207 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2025-2026 Andreas Igel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.javahelpers.codegen.analysis;
+
+import static com.google.testing.compile.CompilationSubject.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+
+import com.google.testing.compile.Compilation;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.BiConsumer;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.RoundEnvironment;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+import org.javahelpers.codegen.model.method.MethodParameterDto;
+import org.javahelpers.codegen.model.type.TypeName;
+import org.javahelpers.codegen.model.type.TypeNameList;
+import org.javahelpers.codegen.processing.AnnotationProcessingContext;
+import org.javahelpers.codegen.testing.CapturingProcessingLogger;
+import org.javahelpers.codegen.testing.CodegenTestUtils;
+import org.junit.jupiter.api.Test;
+
+/** Unit tests for {@link JavaLangMapper} against elements captured from a real compilation. */
+class JavaLangMapperTest {
+
+ /** Runs {@code probe} once during the first processing round with a live processing context. */
+ private static class ProbeProcessor extends AbstractProcessor {
+ private final BiConsumer probe;
+ private boolean ran;
+
+ ProbeProcessor(BiConsumer probe) {
+ this.probe = probe;
+ }
+
+ @Override
+ public SourceVersion getSupportedSourceVersion() {
+ return SourceVersion.latestSupported();
+ }
+
+ @Override
+ public Set getSupportedAnnotationTypes() {
+ return Set.of("*");
+ }
+
+ @Override
+ public boolean process(Set extends TypeElement> annotations, RoundEnvironment roundEnv) {
+ if (ran || roundEnv.processingOver()) {
+ return false;
+ }
+ ran = true;
+ probe.accept(
+ roundEnv,
+ new AnnotationProcessingContext(
+ CapturingProcessingLogger.create().logger(), processingEnv));
+ return false;
+ }
+ }
+
+ private static VariableElement setterParameter(
+ TypeElement dto, String setterName, int paramIndex) {
+ return dto.getEnclosedElements().stream()
+ .filter(ExecutableElement.class::isInstance)
+ .map(ExecutableElement.class::cast)
+ .filter(m -> m.getSimpleName().toString().equals(setterName))
+ .map(m -> m.getParameters().get(paramIndex))
+ .findFirst()
+ .orElseThrow();
+ }
+
+ @Test
+ void map2TypeName_mapsJavaClass() {
+ TypeName typeName = JavaLangMapper.map2TypeName(String.class);
+ assertEquals("java.lang", typeName.getPackageName());
+ assertEquals("String", typeName.getClassName());
+ }
+
+ @Test
+ void mapToTypeName_mapsTypeElement() {
+ AtomicReference result = new AtomicReference<>();
+ Compilation compilation =
+ CodegenTestUtils.createCompiler(
+ new ProbeProcessor(
+ (roundEnv, ctx) -> {
+ TypeElement dto = ctx.getTypeElement("test.Dto");
+ result.set(JavaLangMapper.mapToTypeName(dto, ctx));
+ }))
+ .compile(
+ CodegenTestUtils.forSource(
+ """
+ package test;
+ public class Dto {
+ private String name;
+ public void setName(String name) { this.name = name; }
+ }
+ """));
+
+ assertThat(compilation).succeeded();
+ assertEquals("test", result.get().getPackageName());
+ assertEquals("Dto", result.get().getClassName());
+ }
+
+ @Test
+ void map2MethodParameter_mapsNameAndListType() {
+ AtomicReference result = new AtomicReference<>();
+ Compilation compilation =
+ CodegenTestUtils.createCompiler(
+ new ProbeProcessor(
+ (roundEnv, ctx) -> {
+ TypeElement dto = ctx.getTypeElement("test.Dto");
+ VariableElement param = setterParameter(dto, "setTags", 0);
+ result.set(JavaLangMapper.map2MethodParameter(param, ctx));
+ }))
+ .compile(
+ CodegenTestUtils.forSource(
+ """
+ package test;
+ import java.util.List;
+ public class Dto {
+ private List tags;
+ public void setTags(List tags) { this.tags = tags; }
+ }
+ """));
+
+ assertThat(compilation).succeeded();
+ MethodParameterDto param = result.get();
+ assertEquals("tags", param.getParameterName());
+ TypeNameList typeName = assertInstanceOf(TypeNameList.class, param.getParameterType());
+ assertEquals("java.util.List", typeName.getPackageName() + "." + typeName.getClassName());
+ assertEquals("String", typeName.getElementType().getClassName());
+ }
+
+ @Test
+ void createDerivedTypeName_appendsSuffix() {
+ AtomicReference result = new AtomicReference<>();
+ Compilation compilation =
+ CodegenTestUtils.createCompiler(
+ new ProbeProcessor(
+ (roundEnv, ctx) -> {
+ TypeElement dto = ctx.getTypeElement("test.Dto");
+ result.set(JavaLangMapper.createDerivedTypeName(dto, ctx, "Builder"));
+ }))
+ .compile(
+ CodegenTestUtils.forSource(
+ """
+ package test;
+ public class Dto {}
+ """));
+
+ assertThat(compilation).succeeded();
+ assertEquals("test", result.get().getPackageName());
+ assertEquals("DtoBuilder", result.get().getClassName());
+ }
+
+ @Test
+ void extractInterfaceTypeArguments_resolvesInheritedListArgument() {
+ // CustomList extends ArrayList: the List element type is Y, not the declared X/Y pair
+ AtomicReference> result = new AtomicReference<>();
+ Compilation compilation =
+ CodegenTestUtils.createCompiler(
+ new ProbeProcessor(
+ (roundEnv, ctx) -> {
+ TypeElement customList = ctx.getTypeElement("test.CustomList");
+ TypeElement listInterface = ctx.getTypeElement("java.util.List");
+ result.set(
+ JavaLangMapper.extractInterfaceTypeArguments(
+ customList.asType(), listInterface, ctx));
+ }))
+ .compile(
+ CodegenTestUtils.forSource(
+ """
+ package test;
+ import java.util.ArrayList;
+ public class CustomList extends ArrayList {}
+ """));
+
+ assertThat(compilation).succeeded();
+ assertEquals(1, result.get().size());
+ assertEquals("Y", result.get().get(0).getClassName());
+ }
+}
diff --git a/processor/src/test/java/org/javahelpers/codegen/processing/CodegenProcessorConfigurationTest.java b/simple-processor/src/test/java/org/javahelpers/codegen/processing/CodegenProcessorConfigurationTest.java
similarity index 100%
rename from processor/src/test/java/org/javahelpers/codegen/processing/CodegenProcessorConfigurationTest.java
rename to simple-processor/src/test/java/org/javahelpers/codegen/processing/CodegenProcessorConfigurationTest.java
diff --git a/processor/src/test/java/org/javahelpers/codegen/processing/ElementCollectorTest.java b/simple-processor/src/test/java/org/javahelpers/codegen/processing/ElementCollectorTest.java
similarity index 100%
rename from processor/src/test/java/org/javahelpers/codegen/processing/ElementCollectorTest.java
rename to simple-processor/src/test/java/org/javahelpers/codegen/processing/ElementCollectorTest.java
diff --git a/processor/src/test/java/org/javahelpers/codegen/processing/MinimalCodegenProcessorTest.java b/simple-processor/src/test/java/org/javahelpers/codegen/processing/MinimalCodegenProcessorTest.java
similarity index 96%
rename from processor/src/test/java/org/javahelpers/codegen/processing/MinimalCodegenProcessorTest.java
rename to simple-processor/src/test/java/org/javahelpers/codegen/processing/MinimalCodegenProcessorTest.java
index 3358a2b8..189e1585 100644
--- a/processor/src/test/java/org/javahelpers/codegen/processing/MinimalCodegenProcessorTest.java
+++ b/simple-processor/src/test/java/org/javahelpers/codegen/processing/MinimalCodegenProcessorTest.java
@@ -24,8 +24,8 @@
package org.javahelpers.codegen.processing;
import static com.google.testing.compile.CompilationSubject.assertThat;
+import static org.javahelpers.codegen.testing.CodegenTestUtils.loadGeneratedSource;
import static org.javahelpers.codegen.testing.ProcessorAsserts.assertNormalizedEquals;
-import static org.javahelpers.simple.builders.processor.testing.ProcessorTestUtils.loadGeneratedSource;
import com.google.testing.compile.Compilation;
import java.lang.annotation.ElementType;
@@ -48,7 +48,7 @@
import org.javahelpers.codegen.model.core.GenerationTargetClassDto;
import org.javahelpers.codegen.model.method.MethodDto;
import org.javahelpers.codegen.model.type.TypeName;
-import org.javahelpers.simple.builders.processor.testing.ProcessorTestUtils;
+import org.javahelpers.codegen.testing.CodegenTestUtils;
import org.junit.jupiter.api.Test;
/**
@@ -173,7 +173,7 @@ private static TypeName builderName(TypeElement target, AnnotationProcessingCont
void minimalProcessorGeneratesDelegatingBuilder() {
// Given
JavaFileObject source =
- ProcessorTestUtils.forSource(
+ CodegenTestUtils.forSource(
"""
package test;
import org.javahelpers.codegen.processing.MinimalCodegenProcessorTest.GenerateBuilder;
@@ -186,7 +186,7 @@ public class Person {
// When
Compilation compilation =
- ProcessorTestUtils.createCompiler(new MinimalProcessor()).compile(source);
+ CodegenTestUtils.createCompiler(new MinimalProcessor()).compile(source);
// Then
assertThat(compilation).succeeded();
diff --git a/processor/src/test/java/org/javahelpers/simple/builders/processor/processing/OptionValueParsersTest.java b/simple-processor/src/test/java/org/javahelpers/codegen/processing/OptionValueParsersTest.java
similarity index 97%
rename from processor/src/test/java/org/javahelpers/simple/builders/processor/processing/OptionValueParsersTest.java
rename to simple-processor/src/test/java/org/javahelpers/codegen/processing/OptionValueParsersTest.java
index fa2f546d..45f4fe0d 100644
--- a/processor/src/test/java/org/javahelpers/simple/builders/processor/processing/OptionValueParsersTest.java
+++ b/simple-processor/src/test/java/org/javahelpers/codegen/processing/OptionValueParsersTest.java
@@ -22,14 +22,13 @@
* SOFTWARE.
*/
-package org.javahelpers.simple.builders.processor.processing;
+package org.javahelpers.codegen.processing;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.javahelpers.codegen.enums.AccessModifier;
import org.javahelpers.codegen.enums.OptionState;
-import org.javahelpers.codegen.processing.OptionValueParsers;
import org.javahelpers.codegen.testing.CapturingProcessingLogger;
import org.junit.jupiter.api.Test;
diff --git a/processor/src/test/java/org/javahelpers/codegen/processing/ProcessorOptionRegistryTest.java b/simple-processor/src/test/java/org/javahelpers/codegen/processing/ProcessorOptionRegistryTest.java
similarity index 100%
rename from processor/src/test/java/org/javahelpers/codegen/processing/ProcessorOptionRegistryTest.java
rename to simple-processor/src/test/java/org/javahelpers/codegen/processing/ProcessorOptionRegistryTest.java
From 6e7e0dc17cba1e4f4fa3eb4c8f008f2fe9f7375e Mon Sep 17 00:00:00 2001
From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Date: Sun, 15 Nov 2026 15:26:36 +0000
Subject: [PATCH 02/12] test: lift per-module coverage and share test helpers
(#390)
- add missing coverage for codegen-testing helpers, codegen-roaster
backend/mapper/generator and simple-processor analysers, context,
options and logging
- move shared test support into codegen-testing (ProbeProcessor,
ElementTestUtils, TestingGenerationEnvironment)
- delete enum-only test and exclude enums/DTO model packages from
JaCoCo coverage scope in all modules
- pin surefire 3.6.0 in core so JUnit 5 tests actually run
Per-module line coverage now: core 95%, codegen-core 90%,
codegen-roaster 91%, codegen-testing 91%, simple-processor 84%,
processor 97%.
Co-Authored-By: Andreas Igel
---
codegen-core/pom.xml | 5 +-
.../codegen/enums/CodegenEnumsTest.java | 61 --
codegen-roaster/pom.xml | 5 +
.../codegen/roaster/RoasterBackendTest.java | 53 ++
.../RoasterCodeGeneratorResilienceTest.java | 41 +-
.../roaster/RoasterCodeGeneratorTest.java | 237 ++++--
.../codegen/roaster/RoasterMapperTest.java | 209 +++++
codegen-testing/pom.xml | 5 +-
.../codegen/testing/ElementTestUtils.java | 91 +++
.../codegen/testing/ProbeProcessor.java | 83 ++
.../testing/TestingGenerationEnvironment.java | 124 +++
.../CapturingProcessingLoggerTest.java | 12 +
.../codegen/testing/CodegenTestUtilsTest.java | 42 +
.../codegen/testing/ElementTestUtilsTest.java | 116 +++
.../codegen/testing/ProbeProcessorTest.java | 67 ++
.../ProcessingEnvironmentStubTest.java | 12 +
.../codegen/testing/ProcessorAssertsTest.java | 92 +++
.../TestingGenerationEnvironmentTest.java | 77 ++
core/pom.xml | 21 +
processor/pom.xml | 5 +-
simple-processor/pom.xml | 5 +-
.../FieldAnnotationExtractorTest.java | 109 ++-
.../codegen/analysis/GeneratedTypesTest.java | 66 ++
.../analysis/JavaLangAnalyserTest.java | 722 ++++++++++++------
.../codegen/analysis/JavaLangMapperTest.java | 344 ++++++---
.../analysis/TypeNameAnalyserTest.java | 76 ++
.../codegen/analysis/testannotations/Tag.java | 33 +
.../analysis/testannotations/Tags.java | 30 +
.../AnnotationProcessingContextTest.java | 231 ++++++
.../CompilerArgumentsReaderTest.java | 100 +++
.../processing/PipelinePhasesTest.java | 48 ++
.../ProcessorOptionRegistryTest.java | 70 +-
.../logging/MessagerProcessingLoggerTest.java | 236 ++++++
33 files changed, 2866 insertions(+), 562 deletions(-)
delete mode 100644 codegen-core/src/test/java/org/javahelpers/codegen/enums/CodegenEnumsTest.java
create mode 100644 codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterBackendTest.java
create mode 100644 codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterMapperTest.java
create mode 100644 codegen-testing/src/main/java/org/javahelpers/codegen/testing/ElementTestUtils.java
create mode 100644 codegen-testing/src/main/java/org/javahelpers/codegen/testing/ProbeProcessor.java
create mode 100644 codegen-testing/src/main/java/org/javahelpers/codegen/testing/TestingGenerationEnvironment.java
create mode 100644 codegen-testing/src/test/java/org/javahelpers/codegen/testing/ElementTestUtilsTest.java
create mode 100644 codegen-testing/src/test/java/org/javahelpers/codegen/testing/ProbeProcessorTest.java
create mode 100644 codegen-testing/src/test/java/org/javahelpers/codegen/testing/TestingGenerationEnvironmentTest.java
create mode 100644 simple-processor/src/test/java/org/javahelpers/codegen/analysis/GeneratedTypesTest.java
create mode 100644 simple-processor/src/test/java/org/javahelpers/codegen/analysis/TypeNameAnalyserTest.java
create mode 100644 simple-processor/src/test/java/org/javahelpers/codegen/analysis/testannotations/Tag.java
create mode 100644 simple-processor/src/test/java/org/javahelpers/codegen/analysis/testannotations/Tags.java
create mode 100644 simple-processor/src/test/java/org/javahelpers/codegen/processing/AnnotationProcessingContextTest.java
create mode 100644 simple-processor/src/test/java/org/javahelpers/codegen/processing/CompilerArgumentsReaderTest.java
create mode 100644 simple-processor/src/test/java/org/javahelpers/codegen/processing/PipelinePhasesTest.java
create mode 100644 simple-processor/src/test/java/org/javahelpers/codegen/processing/logging/MessagerProcessingLoggerTest.java
diff --git a/codegen-core/pom.xml b/codegen-core/pom.xml
index 6c4b5550..78efb444 100644
--- a/codegen-core/pom.xml
+++ b/codegen-core/pom.xml
@@ -348,10 +348,13 @@
-
+
**/codegen/model/**
+ **/processor/model/**
+ **/enums/****/*Exception.*
+ **/exceptions/****/JavadocConstants.*
diff --git a/codegen-core/src/test/java/org/javahelpers/codegen/enums/CodegenEnumsTest.java b/codegen-core/src/test/java/org/javahelpers/codegen/enums/CodegenEnumsTest.java
deleted file mode 100644
index 3d95d67f..00000000
--- a/codegen-core/src/test/java/org/javahelpers/codegen/enums/CodegenEnumsTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * MIT License
- *
- * Copyright (c) 2025-2026 Andreas Igel
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package org.javahelpers.codegen.enums;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import org.junit.jupiter.api.Test;
-
-/** Unit tests for the codegen enums' value mappings and parsing. */
-class CodegenEnumsTest {
-
- @Test
- void accessModifier_mapsToJavaKeyword() {
- assertEquals("public", AccessModifier.DEFAULT.getJavaKeyword());
- assertEquals("public", AccessModifier.PUBLIC.getJavaKeyword());
- assertEquals("protected", AccessModifier.PROTECTED.getJavaKeyword());
- assertEquals("", AccessModifier.PACKAGE_PRIVATE.getJavaKeyword());
- assertEquals("private", AccessModifier.PRIVATE.getJavaKeyword());
- }
-
- @Test
- void formattingMode_optionValuesAndParsing() {
- assertEquals("jdt", FormattingMode.JDT.getOptionValue());
- assertEquals("lightweight", FormattingMode.LIGHTWEIGHT.getOptionValue());
- assertEquals("none", FormattingMode.NONE.getOptionValue());
-
- assertEquals(FormattingMode.NONE, FormattingMode.fromString("none"));
- assertEquals(FormattingMode.LIGHTWEIGHT, FormattingMode.fromString("LightWeight"));
- assertEquals(FormattingMode.JDT, FormattingMode.fromString(null));
- assertEquals(FormattingMode.JDT, FormattingMode.fromString("unknown"));
- }
-
- @Test
- void optionState_hasTriStateValues() {
- assertEquals(
- java.util.Set.of(OptionState.UNSET, OptionState.ENABLED, OptionState.DISABLED),
- java.util.Set.of(OptionState.values()));
- }
-}
diff --git a/codegen-roaster/pom.xml b/codegen-roaster/pom.xml
index 8d876dba..50381048 100644
--- a/codegen-roaster/pom.xml
+++ b/codegen-roaster/pom.xml
@@ -345,8 +345,13 @@
+
+ **/codegen/model/**
+ **/processor/model/**
+ **/enums/****/*Exception.*
+ **/exceptions/****/JavadocConstants.*
diff --git a/codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterBackendTest.java b/codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterBackendTest.java
new file mode 100644
index 00000000..3cdf124e
--- /dev/null
+++ b/codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterBackendTest.java
@@ -0,0 +1,53 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2025-2026 Andreas Igel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.javahelpers.codegen.roaster;
+
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertSame;
+
+import org.javahelpers.codegen.enums.FormattingMode;
+import org.javahelpers.codegen.testing.CapturingProcessingLogger;
+import org.javahelpers.codegen.testing.TestingGenerationEnvironment;
+import org.junit.jupiter.api.Test;
+
+/** Tests for {@link RoasterBackend}'s matched generator/formatter pair. */
+class RoasterBackendTest {
+
+ @Test
+ void exposesGeneratorAndCachesFormatterPerMode() {
+ CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
+ RoasterBackend backend =
+ new RoasterBackend(
+ TestingGenerationEnvironment.create(capturing.logger()), capturing.logger(), null);
+
+ assertInstanceOf(RoasterCodeGenerator.class, backend.generator());
+ assertInstanceOf(
+ RoasterSourceFormatter.class, backend.formatterFor(FormattingMode.LIGHTWEIGHT));
+ // formatters are cached per mode
+ assertSame(
+ backend.formatterFor(FormattingMode.LIGHTWEIGHT),
+ backend.formatterFor(FormattingMode.LIGHTWEIGHT));
+ }
+}
diff --git a/codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterCodeGeneratorResilienceTest.java b/codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterCodeGeneratorResilienceTest.java
index e681bbed..5d1de85d 100644
--- a/codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterCodeGeneratorResilienceTest.java
+++ b/codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterCodeGeneratorResilienceTest.java
@@ -28,14 +28,9 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.javahelpers.codegen.CodeGenerationException;
-import org.javahelpers.codegen.GeneratedSourceFile;
-import org.javahelpers.codegen.GenerationEnvironment;
-import org.javahelpers.codegen.GenerationIssueReporter;
import org.javahelpers.codegen.SourceFormatter;
import org.javahelpers.codegen.enums.AccessModifier;
import org.javahelpers.codegen.enums.FormattingMode;
-import org.javahelpers.codegen.logging.NoOpPerformanceTracker;
-import org.javahelpers.codegen.logging.PerformanceTracker;
import org.javahelpers.codegen.logging.ProcessingLogger;
import org.javahelpers.codegen.model.core.GenerationTargetClassDto;
import org.javahelpers.codegen.model.method.ConstructorDto;
@@ -46,6 +41,7 @@
import org.javahelpers.codegen.model.type.TypeName;
import org.javahelpers.codegen.roaster.exceptions.RoasterMapperException;
import org.javahelpers.codegen.testing.CapturingProcessingLogger;
+import org.javahelpers.codegen.testing.TestingGenerationEnvironment;
import org.junit.jupiter.api.Test;
/**
@@ -59,35 +55,6 @@
*/
class RoasterCodeGeneratorResilienceTest {
- /**
- * Minimal {@link GenerationEnvironment} built only from codegen-core types: issues surface on the
- * logger as warnings, timing is not tracked, and {@code createSourceFile} returns {@code null} so
- * the file-write step fails deterministically on it.
- */
- private static GenerationEnvironment stubEnvironment(ProcessingLogger logger) {
- return new GenerationEnvironment() {
- @Override
- public ProcessingLogger getLogger() {
- return logger;
- }
-
- @Override
- public PerformanceTracker getPerformanceTracker() {
- return new NoOpPerformanceTracker();
- }
-
- @Override
- public GenerationIssueReporter getIssueReporter() {
- return logger::warning;
- }
-
- @Override
- public GeneratedSourceFile createSourceFile(CharSequence qualifiedName) {
- return null;
- }
- };
- }
-
/** Placeholder subtype the mapper does not know how to render, forcing a mapping failure. */
private static final class UnsupportedPlaceholder extends MethodCodePlaceholder {
private UnsupportedPlaceholder(String label, String value) {
@@ -111,7 +78,8 @@ void shouldWrapRenderingRuntimeExceptionInCodeGenerationException() {
classDef.addConstructor(constructor);
ProcessingLogger logger = CapturingProcessingLogger.create().logger();
- RoasterCodeGenerator generator = new RoasterCodeGenerator(stubEnvironment(logger));
+ RoasterCodeGenerator generator =
+ new RoasterCodeGenerator(TestingGenerationEnvironment.createUnwritable(logger));
SourceFormatter formatter = new RoasterSourceFormatter(logger, FormattingMode.NONE);
CodeGenerationException thrown =
@@ -137,7 +105,8 @@ void shouldKeepFirstMethodAndWarnOnDuplicateSignature() {
classDef.addMethod(duplicateSignatureMethod("second"));
CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
- RoasterCodeGenerator generator = new RoasterCodeGenerator(stubEnvironment(capturing.logger()));
+ RoasterCodeGenerator generator =
+ new RoasterCodeGenerator(TestingGenerationEnvironment.createUnwritable(capturing.logger()));
SourceFormatter formatter = new RoasterSourceFormatter(capturing.logger(), FormattingMode.NONE);
// generation itself succeeds; only the file-write step fails on the stub's null source file
diff --git a/codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterCodeGeneratorTest.java b/codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterCodeGeneratorTest.java
index aee5a54a..85a6b2ab 100644
--- a/codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterCodeGeneratorTest.java
+++ b/codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterCodeGeneratorTest.java
@@ -24,85 +24,38 @@
package org.javahelpers.codegen.roaster;
+import static org.javahelpers.codegen.testing.ProcessorAsserts.assertContaining;
import static org.javahelpers.codegen.testing.ProcessorAsserts.assertNormalizedEquals;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.net.URI;
-import org.javahelpers.codegen.GeneratedSourceFile;
-import org.javahelpers.codegen.GenerationEnvironment;
-import org.javahelpers.codegen.GenerationIssueReporter;
+import java.util.List;
import org.javahelpers.codegen.SourceFormatter;
import org.javahelpers.codegen.enums.AccessModifier;
import org.javahelpers.codegen.enums.FormattingMode;
-import org.javahelpers.codegen.logging.NoOpPerformanceTracker;
-import org.javahelpers.codegen.logging.PerformanceTracker;
-import org.javahelpers.codegen.logging.ProcessingLogger;
+import org.javahelpers.codegen.model.annotation.AnnotationDto;
+import org.javahelpers.codegen.model.annotation.InterfaceName;
import org.javahelpers.codegen.model.core.ClassFieldDto;
import org.javahelpers.codegen.model.core.GenerationTargetClassDto;
+import org.javahelpers.codegen.model.javadoc.JavadocDto;
+import org.javahelpers.codegen.model.method.ConstructorDto;
import org.javahelpers.codegen.model.method.MethodDto;
import org.javahelpers.codegen.model.method.MethodParameterDto;
+import org.javahelpers.codegen.model.type.GenericParameterDto;
+import org.javahelpers.codegen.model.type.NestedTypeDto;
import org.javahelpers.codegen.model.type.TypeName;
+import org.javahelpers.codegen.model.type.TypeNameGeneric;
+import org.javahelpers.codegen.model.type.TypeNamePrimitive;
+import org.javahelpers.codegen.model.type.TypeNameVariable;
import org.javahelpers.codegen.testing.CapturingProcessingLogger;
+import org.javahelpers.codegen.testing.TestingGenerationEnvironment;
import org.junit.jupiter.api.Test;
/**
* Tests for {@link RoasterCodeGenerator} driving {@link GenerationTargetClassDto}s directly — no
- * simple-builder types involved, the {@link GenerationEnvironment} is built from codegen-core types
- * only and the emitted source is captured in memory and asserted as a whole text block.
+ * simple-builder types involved, the {@code GenerationEnvironment} comes from shared test support
+ * ({@link TestingGenerationEnvironment}) and the emitted source is asserted as a whole text block.
*/
class RoasterCodeGeneratorTest {
- private static final class CapturingFile implements GeneratedSourceFile {
- private final String name;
- private final StringWriter buffer = new StringWriter();
-
- private CapturingFile(CharSequence qualifiedName) {
- this.name = qualifiedName.toString();
- }
-
- @Override
- public URI toUri() {
- return URI.create("mem:///" + name.replace('.', '/') + ".java");
- }
-
- @Override
- public Writer openWriter() {
- return buffer;
- }
-
- private String source() {
- return buffer.toString();
- }
- }
-
- private static GenerationEnvironment environment(
- ProcessingLogger logger, CapturingFile[] written) {
- return new GenerationEnvironment() {
- @Override
- public ProcessingLogger getLogger() {
- return logger;
- }
-
- @Override
- public PerformanceTracker getPerformanceTracker() {
- return new NoOpPerformanceTracker();
- }
-
- @Override
- public GenerationIssueReporter getIssueReporter() {
- return logger::warning;
- }
-
- @Override
- public GeneratedSourceFile createSourceFile(CharSequence qualifiedName) {
- CapturingFile file = new CapturingFile(qualifiedName);
- written[0] = file;
- return file;
- }
- };
- }
-
/** A builder-style DTO: private target field, one delegating setter, one build method. */
private static GenerationTargetClassDto personBuilderDefinition() {
TypeName builderType = new TypeName("test", "PersonBuilder");
@@ -142,9 +95,8 @@ private static GenerationTargetClassDto personBuilderDefinition() {
@Test
void generatesDelegatingBuilderFromDto() throws Exception {
CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
- CapturingFile[] written = new CapturingFile[1];
- RoasterCodeGenerator generator =
- new RoasterCodeGenerator(environment(capturing.logger(), written));
+ TestingGenerationEnvironment env = TestingGenerationEnvironment.create(capturing.logger());
+ RoasterCodeGenerator generator = new RoasterCodeGenerator(env);
SourceFormatter formatter = new RoasterSourceFormatter(capturing.logger(), FormattingMode.NONE);
generator.generateClass(personBuilderDefinition(), formatter);
@@ -165,16 +117,15 @@ public Person build() {
return target;
}
}""",
- written[0].source(),
+ env.generatedSource(),
"generated PersonBuilder must match the expected source");
}
@Test
void writesFileUnderQualifiedName() throws Exception {
CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
- CapturingFile[] written = new CapturingFile[1];
- RoasterCodeGenerator generator =
- new RoasterCodeGenerator(environment(capturing.logger(), written));
+ TestingGenerationEnvironment env = TestingGenerationEnvironment.create(capturing.logger());
+ RoasterCodeGenerator generator = new RoasterCodeGenerator(env);
GenerationTargetClassDto empty = new GenerationTargetClassDto();
empty.setTypeName(new TypeName("com.example", "EmptyBuilder"));
@@ -185,6 +136,154 @@ void writesFileUnderQualifiedName() throws Exception {
empty, new RoasterSourceFormatter(capturing.logger(), FormattingMode.NONE));
org.junit.jupiter.api.Assertions.assertEquals(
- "mem:///com/example/EmptyBuilder.java", written[0].toUri().toString());
+ "mem:///com/example/EmptyBuilder.java", env.writtenUri().toString());
+ }
+
+ @Test
+ void generatesClassMetadataJavadocAndAnnotations() throws Exception {
+ GenerationTargetClassDto classDef = new GenerationTargetClassDto();
+ classDef.setTypeName(new TypeName("test", "AnnotatedBuilder"));
+ classDef.setClassAccessModifier(AccessModifier.PUBLIC);
+ classDef.setFormattingMode(FormattingMode.NONE);
+ classDef.setClassJavadoc(new JavadocDto("Builder for {@link Person}."));
+ AnnotationDto generated = new AnnotationDto();
+ generated.setAnnotationType(new TypeName("javax.annotation", "Generated"));
+ generated.addMember("value", "\"simple-builders\"");
+ classDef.addClassAnnotation(generated);
+ classDef.setSuperType(new TypeName("test", "AbstractBuilder"));
+ InterfaceName iface = new InterfaceName("java.io", "Serializable");
+ classDef.addInterface(iface);
+
+ assertContaining(
+ generate(classDef),
+ "extends AbstractBuilder",
+ "implements Serializable",
+ "Builder for",
+ "Generated(\"simple-builders\")");
+ }
+
+ @Test
+ void generatesGenericClassAndMethods() throws Exception {
+ GenerationTargetClassDto classDef = new GenerationTargetClassDto();
+ classDef.setTypeName(new TypeName("test", "GenericBuilder"));
+ classDef.setClassAccessModifier(AccessModifier.PUBLIC);
+ classDef.setFormattingMode(FormattingMode.NONE);
+ GenericParameterDto generic = new GenericParameterDto();
+ generic.setName("T");
+ classDef.addGeneric(generic);
+
+ MethodDto genericMethod = new MethodDto("of", new TypeNameVariable("T"));
+ genericMethod.setModifier(AccessModifier.PUBLIC);
+ genericMethod.setStatic(true);
+ GenericParameterDto methodGeneric = new GenericParameterDto();
+ methodGeneric.setName("R");
+ methodGeneric.addUpperBound(TypeName.of(Number.class));
+ genericMethod.addGenericParameter(methodGeneric);
+ MethodParameterDto param = new MethodParameterDto();
+ param.setParameterName("input");
+ param.setParameterTypeName(new TypeNameVariable("R"));
+ genericMethod.addParameter(param);
+ genericMethod.setCode("return null;");
+ classDef.addMethod(genericMethod);
+
+ assertContaining(
+ generate(classDef), "class GenericBuilder", "static T of(R input)");
+ }
+
+ @Test
+ void generatesConstructorAndFieldVariants() throws Exception {
+ GenerationTargetClassDto classDef = new GenerationTargetClassDto();
+ classDef.setTypeName(new TypeName("test", "CtorBuilder"));
+ classDef.setClassAccessModifier(AccessModifier.PUBLIC);
+ classDef.setFormattingMode(FormattingMode.NONE);
+
+ ClassFieldDto constant = new ClassFieldDto();
+ constant.setFieldName("DEFAULT_SIZE");
+ constant.setFieldType(TypeNamePrimitive.INT);
+ constant.setVisibility(AccessModifier.PRIVATE);
+ constant.setLiteralInitializer("42");
+ classDef.addClassField(constant);
+
+ ConstructorDto ctor = new ConstructorDto();
+ ctor.setVisibility(AccessModifier.PROTECTED);
+ MethodParameterDto param = new MethodParameterDto();
+ param.setParameterName("capacity");
+ param.setParameterTypeName(TypeNamePrimitive.INT);
+ AnnotationDto paramAnnotation = new AnnotationDto();
+ paramAnnotation.setAnnotationType(new TypeName("test.anno", "NonNull"));
+ param.addAnnotation(paramAnnotation);
+ ctor.addParameter(param);
+ classDef.addConstructor(ctor);
+
+ assertContaining(
+ generate(classDef), "private int DEFAULT_SIZE = 42", "protected CtorBuilder(int capacity)");
+ }
+
+ @Test
+ void generatesNestedTypesWithMembers() throws Exception {
+ GenerationTargetClassDto classDef = new GenerationTargetClassDto();
+ classDef.setTypeName(new TypeName("test", "OuterBuilder"));
+ classDef.setClassAccessModifier(AccessModifier.PUBLIC);
+ classDef.setFormattingMode(FormattingMode.NONE);
+
+ NestedTypeDto nested = new NestedTypeDto();
+ nested.setTypeName("Helper");
+ nested.setKind(NestedTypeDto.NestedTypeKind.CLASS);
+ nested.setVisibility(AccessModifier.PUBLIC);
+ nested.setJavadoc(new JavadocDto("Nested helper."));
+ MethodDto nestedMethod = new MethodDto("assist", TypeNamePrimitive.VOID);
+ nestedMethod.setModifier(AccessModifier.PRIVATE);
+ nestedMethod.setCode("// nothing");
+ nested.addMethod(nestedMethod);
+ classDef.addNestedType(nested);
+
+ assertContaining(generate(classDef), "class Helper", "Nested helper.", "void assist()");
+ }
+
+ @Test
+ void generatesMethodWithJavadocAnnotationsAndTypedParameters() throws Exception {
+ GenerationTargetClassDto classDef = new GenerationTargetClassDto();
+ classDef.setTypeName(new TypeName("test", "RichBuilder"));
+ classDef.setClassAccessModifier(AccessModifier.PUBLIC);
+ classDef.setFormattingMode(FormattingMode.NONE);
+
+ MethodDto method =
+ new MethodDto(
+ "items",
+ new TypeNameGeneric(
+ new TypeName("java.util", "List"), List.of(TypeName.of(String.class))));
+ method.setModifier(AccessModifier.PUBLIC);
+ JavadocDto javadoc = new JavadocDto("Adds items.");
+ javadoc.addParam("values", "items to add");
+ javadoc.addReturn("this builder");
+ method.setJavadoc(javadoc);
+ AnnotationDto override_ = new AnnotationDto();
+ override_.setAnnotationType(new TypeName("java.lang", "Override"));
+ method.addAnnotation(override_);
+ MethodParameterDto param = new MethodParameterDto();
+ param.setParameterName("values");
+ param.setParameterTypeName(
+ new TypeNameGeneric(new TypeName("java.util", "List"), List.of(TypeName.of(String.class))));
+ method.addParameter(param);
+ method.setCode("return null;");
+ classDef.addMethod(method);
+
+ String generated = generate(classDef);
+ assertContaining(
+ generated,
+ "Adds items",
+ "@param values",
+ "@return",
+ "@Override",
+ "List items(List values)");
+ }
+
+ private static String generate(GenerationTargetClassDto classDef) throws Exception {
+ CapturingProcessingLogger capturing = CapturingProcessingLogger.create();
+ TestingGenerationEnvironment env = TestingGenerationEnvironment.create(capturing.logger());
+ RoasterCodeGenerator generator = new RoasterCodeGenerator(env);
+ generator.generateClass(
+ classDef, new RoasterSourceFormatter(capturing.logger(), FormattingMode.NONE));
+ return env.generatedSource();
}
}
diff --git a/codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterMapperTest.java b/codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterMapperTest.java
new file mode 100644
index 00000000..c4cc66d7
--- /dev/null
+++ b/codegen-roaster/src/test/java/org/javahelpers/codegen/roaster/RoasterMapperTest.java
@@ -0,0 +1,209 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2025-2026 Andreas Igel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.javahelpers.codegen.roaster;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.util.List;
+import org.javahelpers.codegen.model.annotation.AnnotationDto;
+import org.javahelpers.codegen.model.annotation.InterfaceName;
+import org.javahelpers.codegen.model.method.CodeTemplateDto;
+import org.javahelpers.codegen.model.method.MethodCodePlaceholder;
+import org.javahelpers.codegen.model.method.MethodCodeStringPlaceholder;
+import org.javahelpers.codegen.model.method.MethodCodeTypePlaceholder;
+import org.javahelpers.codegen.model.type.TypeName;
+import org.javahelpers.codegen.model.type.TypeNameArray;
+import org.javahelpers.codegen.model.type.TypeNameGeneric;
+import org.javahelpers.codegen.model.type.TypeNamePrimitive;
+import org.javahelpers.codegen.model.type.TypeNameVariable;
+import org.javahelpers.codegen.roaster.exceptions.RoasterMapperException;
+import org.junit.jupiter.api.Test;
+
+/** Unit tests for {@link RoasterMapper}'s type/annotation/code-template rendering. */
+class RoasterMapperTest {
+
+ @Test
+ void mapType_rendersPlainClassName() {
+ assertEquals("String", RoasterMapper.mapType(TypeName.of(String.class)));
+ }
+
+ @Test
+ void mapType_rendersVariableName() {
+ assertEquals("T", RoasterMapper.mapType(new TypeNameVariable("T")));
+ }
+
+ @Test
+ void mapType_rendersPrimitive() {
+ assertEquals("int", RoasterMapper.mapType(TypeNamePrimitive.INT));
+ }
+
+ @Test
+ void mapType_rendersArrayOfInnerType() {
+ assertEquals("String[]", RoasterMapper.mapType(new TypeNameArray(TypeName.of(String.class))));
+ }
+
+ @Test
+ void mapType_rendersGenericWithInnerArguments() {
+ TypeNameGeneric generic =
+ new TypeNameGeneric(new TypeName("java.util", "List"), List.of(TypeName.of(String.class)));
+ assertEquals("List", RoasterMapper.mapType(generic));
+ }
+
+ @Test
+ void mapType_rendersRawGenericWithoutArguments() {
+ TypeNameGeneric generic = new TypeNameGeneric(new TypeName("java.util", "List"), List.of());
+ assertEquals("List", RoasterMapper.mapType(generic));
+ }
+
+ @Test
+ void mapType_prependsTypeUseAnnotations() {
+ TypeName annotated = new TypeName("java.lang", "String");
+ AnnotationDto nonNull = new AnnotationDto();
+ nonNull.setAnnotationType(new TypeName("test.anno", "NonNull"));
+ annotated.addAnnotation(nonNull);
+ assertEquals("@NonNull String", RoasterMapper.mapType(annotated));
+ }
+
+ @Test
+ void mapBoxedType_boxesAllPrimitives() {
+ assertEquals("Boolean", RoasterMapper.mapBoxedType(TypeNamePrimitive.BOOLEAN));
+ assertEquals("Byte", RoasterMapper.mapBoxedType(TypeNamePrimitive.BYTE));
+ assertEquals("Character", RoasterMapper.mapBoxedType(TypeNamePrimitive.CHAR));
+ assertEquals("Double", RoasterMapper.mapBoxedType(TypeNamePrimitive.DOUBLE));
+ assertEquals("Float", RoasterMapper.mapBoxedType(TypeNamePrimitive.FLOAT));
+ assertEquals("Integer", RoasterMapper.mapBoxedType(TypeNamePrimitive.INT));
+ assertEquals("Long", RoasterMapper.mapBoxedType(TypeNamePrimitive.LONG));
+ assertEquals("Short", RoasterMapper.mapBoxedType(TypeNamePrimitive.SHORT));
+ assertEquals("Void", RoasterMapper.mapBoxedType(TypeNamePrimitive.VOID));
+ }
+
+ @Test
+ void mapBoxedType_passesThroughNonPrimitives() {
+ assertEquals("String", RoasterMapper.mapBoxedType(TypeName.of(String.class)));
+ }
+
+ @Test
+ void mapAnnotation_rendersMarkerWithoutMembers() {
+ AnnotationDto annotation = new AnnotationDto();
+ annotation.setAnnotationType(new TypeName("test.anno", "Marker"));
+ assertEquals("@Marker", RoasterMapper.mapAnnotation(annotation));
+ }
+
+ @Test
+ void mapAnnotation_rendersValueMemberBareAndOthersNamed() {
+ AnnotationDto annotation = new AnnotationDto();
+ annotation.setAnnotationType(new TypeName("test.anno", "Meta"));
+ annotation.addMember("value", "\"x\"");
+ annotation.addMember("order", "3");
+ assertEquals("@Meta(\"x\", order = 3)", RoasterMapper.mapAnnotation(annotation));
+ }
+
+ @Test
+ void mapAnnotation_wrapsFailuresInMapperException() {
+ AnnotationDto annotation = new AnnotationDto();
+ annotation.setAnnotationType(
+ new TypeName("test.anno", "Broken") {
+ @Override
+ public List getAnnotations() {
+ throw new IllegalStateException("boom");
+ }
+ });
+ assertThrows(RoasterMapperException.class, () -> RoasterMapper.mapAnnotation(annotation));
+ }
+
+ @Test
+ void mapInterfaceToTypeName_rendersSimpleAndParameterized() {
+ InterfaceName plain = new InterfaceName("java.util.function", "Supplier");
+ assertEquals("Supplier", RoasterMapper.mapInterfaceToTypeName(plain));
+
+ InterfaceName generic = new InterfaceName("java.util.function", "Supplier");
+ generic.addTypeParameter(TypeName.of(String.class));
+ assertEquals("Supplier", RoasterMapper.mapInterfaceToTypeName(generic));
+ }
+
+ @Test
+ void mapInterfaceToTypeName_prependsTypeUseAnnotations() {
+ InterfaceName iface = new InterfaceName("java.io", "Serializable");
+ AnnotationDto marker = new AnnotationDto();
+ marker.setAnnotationType(new TypeName("test.anno", "Tag"));
+ iface.addAnnotation(marker);
+ assertEquals("@Tag Serializable", RoasterMapper.mapInterfaceToTypeName(iface));
+ }
+
+ @Test
+ void mapInterfaceToTypeName_wrapsFailuresInMapperException() {
+ InterfaceName iface =
+ new InterfaceName("java.io", "Serializable") {
+ @Override
+ public List getTypeParameters() {
+ throw new IllegalStateException("boom");
+ }
+ };
+ iface.addTypeParameter(TypeName.of(String.class));
+ // hasTypeParameters() calls getTypeParameters() -> throws
+ assertThrows(RoasterMapperException.class, () -> RoasterMapper.mapInterfaceToTypeName(iface));
+ }
+
+ @Test
+ void resolveCodeTemplate_replacesStringAndTypePlaceholders() {
+ CodeTemplateDto code = new CodeTemplateDto();
+ code.setCodeFormat("return $name:S, $type:T, $boxed:B, $raw:N;");
+ code.addCodeArgument(new MethodCodeStringPlaceholder("name", "val"));
+ code.addCodeArgument(new MethodCodeTypePlaceholder("type", TypeNamePrimitive.INT));
+ code.addCodeArgument(new MethodCodeTypePlaceholder("boxed", TypeNamePrimitive.INT));
+ code.addCodeArgument(new MethodCodeStringPlaceholder("raw", "literal"));
+
+ assertEquals("return \"val\", int, Integer, literal;", RoasterMapper.resolveCodeTemplate(code));
+ }
+
+ @Test
+ void resolveCodeTemplate_rewritesTrackedValueFactoryNames() {
+ CodeTemplateDto code = new CodeTemplateDto();
+ code.setCodeFormat(
+ "TrackedValue.initialValue(x); TrackedValue.changedValue(y); TrackedValue.unsetValue();");
+ assertEquals(
+ "initialValue(x); changedValue(y); unsetValue();", RoasterMapper.resolveCodeTemplate(code));
+ }
+
+ @Test
+ void resolveCodeTemplate_rejectsUnknownPlaceholderKinds() {
+ CodeTemplateDto code = new CodeTemplateDto();
+ code.setCodeFormat("return $x:X;");
+ code.addCodeArgument(new MethodCodePlaceholder("x", "v") {});
+ assertThrows(RoasterMapperException.class, () -> RoasterMapper.resolveCodeTemplate(code));
+ }
+
+ @Test
+ void quote_escapesSpecialCharacters() {
+ assertEquals("\"a\\\"b\\\\c\\n\\t\"", RoasterMapper.quote("a\"b\\c\n\t"));
+ }
+
+ @Test
+ void packageNameOf_stripsClassName() {
+ assertEquals("java.util", RoasterMapper.packageNameOf("java.util.List"));
+ assertEquals("", RoasterMapper.packageNameOf("List"));
+ }
+}
diff --git a/codegen-testing/pom.xml b/codegen-testing/pom.xml
index ae4d610c..42c6558f 100644
--- a/codegen-testing/pom.xml
+++ b/codegen-testing/pom.xml
@@ -351,10 +351,13 @@
-
+
**/codegen/model/**
+ **/processor/model/**
+ **/enums/****/*Exception.*
+ **/exceptions/****/JavadocConstants.*
diff --git a/codegen-testing/src/main/java/org/javahelpers/codegen/testing/ElementTestUtils.java b/codegen-testing/src/main/java/org/javahelpers/codegen/testing/ElementTestUtils.java
new file mode 100644
index 00000000..6d994ed4
--- /dev/null
+++ b/codegen-testing/src/main/java/org/javahelpers/codegen/testing/ElementTestUtils.java
@@ -0,0 +1,91 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2025-2026 Andreas Igel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.javahelpers.codegen.testing;
+
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+
+/**
+ * Look-ups for {@code javax.lang.model} elements during a live compilation — used inside {@link
+ * ProbeProcessor} probes to grab compiled test types, their fields, methods and parameters.
+ */
+public final class ElementTestUtils {
+
+ private ElementTestUtils() {}
+
+ /**
+ * Resolves a compiled type by qualified name.
+ *
+ * @param processingEnv the live processing environment
+ * @param qualifiedName fully qualified type name (e.g. {@code "test.Dto"})
+ */
+ public static TypeElement typeElement(ProcessingEnvironment processingEnv, String qualifiedName) {
+ return processingEnv.getElementUtils().getTypeElement(qualifiedName);
+ }
+
+ /** Finds a field (or any {@link VariableElement} member) of a type by simple name. */
+ public static VariableElement field(TypeElement type, String fieldName) {
+ return type.getEnclosedElements().stream()
+ .filter(VariableElement.class::isInstance)
+ .map(VariableElement.class::cast)
+ .filter(e -> e.getSimpleName().toString().equals(fieldName))
+ .findFirst()
+ .orElseThrow();
+ }
+
+ /**
+ * Finds a method of a type by simple name; fails when several overloads exist — use {@link
+ * #method(TypeElement, String, int)} or {@link #parameter(ExecutableElement, int)} then.
+ */
+ public static ExecutableElement method(TypeElement type, String methodName) {
+ return type.getEnclosedElements().stream()
+ .filter(ExecutableElement.class::isInstance)
+ .map(ExecutableElement.class::cast)
+ .filter(e -> e.getSimpleName().toString().equals(methodName))
+ .findFirst()
+ .orElseThrow();
+ }
+
+ /**
+ * Finds the {@code overloadIndex}-th method of a type with the given simple name, in declaration
+ * order.
+ */
+ public static ExecutableElement method(TypeElement type, String methodName, int overloadIndex) {
+ return type.getEnclosedElements().stream()
+ .filter(ExecutableElement.class::isInstance)
+ .map(ExecutableElement.class::cast)
+ .filter(e -> e.getSimpleName().toString().equals(methodName))
+ .skip(overloadIndex)
+ .findFirst()
+ .orElseThrow();
+ }
+
+ /** Returns the {@code index}-th parameter of a method. */
+ public static VariableElement parameter(ExecutableElement method, int index) {
+ return method.getParameters().get(index);
+ }
+}
diff --git a/codegen-testing/src/main/java/org/javahelpers/codegen/testing/ProbeProcessor.java b/codegen-testing/src/main/java/org/javahelpers/codegen/testing/ProbeProcessor.java
new file mode 100644
index 00000000..f4493d51
--- /dev/null
+++ b/codegen-testing/src/main/java/org/javahelpers/codegen/testing/ProbeProcessor.java
@@ -0,0 +1,83 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2025-2026 Andreas Igel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.javahelpers.codegen.testing;
+
+import java.util.Set;
+import java.util.function.BiConsumer;
+import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.annotation.processing.RoundEnvironment;
+import javax.lang.model.SourceVersion;
+import javax.lang.model.element.TypeElement;
+
+/**
+ * Test processor that runs a probe once inside a real compilation.
+ *
+ *
During the first processing round the probe receives the {@link RoundEnvironment} and the live
+ * {@link ProcessingEnvironment}, so it can look up {@code TypeElement}s of compiled test sources
+ * (see {@link ElementTestUtils}) and inspect them with real {@code javax.lang.model} types. Results
+ * are captured by the probe (e.g. into {@link java.util.concurrent.atomic.AtomicReference}s) and
+ * asserted by the test after compilation.
+ *
+ *
{@code
+ * AtomicReference found = new AtomicReference<>();
+ * Compilation compilation = CodegenTestUtils.createCompiler(
+ * new ProbeProcessor((roundEnv, processingEnv) ->
+ * found.set(ElementTestUtils.typeElement(processingEnv, "test.Dto"))))
+ * .compile(CodegenTestUtils.forSource("package test; public class Dto {}"));
+ * }
+ */
+public class ProbeProcessor extends AbstractProcessor {
+
+ private final BiConsumer probe;
+ private boolean ran;
+
+ /**
+ * @param probe callback invoked exactly once in the first processing round
+ */
+ public ProbeProcessor(BiConsumer probe) {
+ this.probe = probe;
+ }
+
+ @Override
+ public SourceVersion getSupportedSourceVersion() {
+ return SourceVersion.latestSupported();
+ }
+
+ @Override
+ public Set getSupportedAnnotationTypes() {
+ return Set.of("*");
+ }
+
+ @Override
+ public boolean process(Set extends TypeElement> annotations, RoundEnvironment roundEnv) {
+ if (ran || roundEnv.processingOver()) {
+ return false;
+ }
+ ran = true;
+ probe.accept(roundEnv, processingEnv);
+ return false;
+ }
+}
diff --git a/codegen-testing/src/main/java/org/javahelpers/codegen/testing/TestingGenerationEnvironment.java b/codegen-testing/src/main/java/org/javahelpers/codegen/testing/TestingGenerationEnvironment.java
new file mode 100644
index 00000000..0f8231f7
--- /dev/null
+++ b/codegen-testing/src/main/java/org/javahelpers/codegen/testing/TestingGenerationEnvironment.java
@@ -0,0 +1,124 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2025-2026 Andreas Igel
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package org.javahelpers.codegen.testing;
+
+import java.io.StringWriter;
+import java.io.Writer;
+import java.net.URI;
+import org.javahelpers.codegen.GeneratedSourceFile;
+import org.javahelpers.codegen.GenerationEnvironment;
+import org.javahelpers.codegen.GenerationIssueReporter;
+import org.javahelpers.codegen.logging.NoOpPerformanceTracker;
+import org.javahelpers.codegen.logging.PerformanceTracker;
+import org.javahelpers.codegen.logging.ProcessingLogger;
+
+/**
+ * A {@link GenerationEnvironment} built only from codegen-core types for tests of code generators:
+ * issues surface on the logger as warnings, timing is not tracked, and generated sources are
+ * captured in memory for assertions.
+ *
+ *