Introduce TestGenerationContext

This commit polishes DefaultGenerationContext to make the method
that flushes generated classes more explicit. It now throws an
IOException and TestGenerationContext has been updated to handle
that to ease its use in code that can't throw such an exception.

As this use case is likely to happen outside the Spring Framework,
this commit adds such a convenience to spring-test as well.

Closes gh-28877
This commit is contained in:
Stephane Nicoll
2022-07-26 15:58:28 +02:00
parent 60d2d16b2b
commit 3d5003ad63
18 changed files with 144 additions and 100 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.aot.generate;
import java.io.IOException;
import java.util.function.Consumer;
import org.junit.jupiter.api.Test;
@@ -118,7 +119,7 @@ class DefaultGenerationContextTests {
}
@Test
void withNameKeepsTrackOfAllGeneratedFiles() {
void withNameKeepsTrackOfAllGeneratedFiles() throws IOException {
DefaultGenerationContext context = new DefaultGenerationContext(
new ClassNameGenerator(TestTarget.class), this.generatedFiles);
context.getGeneratedClasses().addForFeature("Test", typeSpecCustomizer);
@@ -132,7 +133,7 @@ class DefaultGenerationContextTests {
}
@Test
void withNameGeneratesUniqueName() {
void withNameGeneratesUniqueName() throws IOException {
DefaultGenerationContext context = new DefaultGenerationContext(
new ClassNameGenerator(Object.class), this.generatedFiles);
context.withName("Test").getGeneratedClasses()