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

@@ -27,6 +27,10 @@ import org.springframework.util.Assert;
/**
* Default {@link GenerationContext} implementation.
*
* <p>Generated classes are flushed out using {@link #writeGeneratedContent()}
* and should be called once the generation process using this instance has
* completed.
*
* @author Phillip Webb
* @author Stephane Nicoll
* @since 6.0
@@ -104,13 +108,8 @@ public class DefaultGenerationContext implements GenerationContext {
/**
* Write any generated content out to the generated files.
*/
public void writeGeneratedContent() {
try {
this.generatedClasses.writeTo(this.generatedFiles);
}
catch (IOException ex) {
throw new IllegalStateException(ex);
}
public void writeGeneratedContent() throws IOException {
this.generatedClasses.writeTo(this.generatedFiles);
}
}