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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user