Browse Source
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-28877pull/30304/head
Stephane Nicoll
2 years ago
18 changed files with 144 additions and 100 deletions
@ -0,0 +1,67 @@
@@ -0,0 +1,67 @@
|
||||
/* |
||||
* Copyright 2002-2022 the original author or authors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||
* you may not use this file except in compliance with the License. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.test.aot.generate; |
||||
|
||||
import java.io.IOException; |
||||
|
||||
import org.springframework.aot.generate.ClassNameGenerator; |
||||
import org.springframework.aot.generate.DefaultGenerationContext; |
||||
import org.springframework.aot.generate.GenerationContext; |
||||
import org.springframework.aot.generate.InMemoryGeneratedFiles; |
||||
|
||||
/** |
||||
* {@link GenerationContext} test implementation that uses |
||||
* {@link InMemoryGeneratedFiles} by default, with a convenient override of |
||||
* {@link #writeGeneratedContent()} that does not throw {@link IOException}. |
||||
* |
||||
* @author Stephane Nicoll |
||||
* @since 6.0 |
||||
*/ |
||||
public class TestGenerationContext extends DefaultGenerationContext { |
||||
|
||||
/** |
||||
* Create an instance using the specified {@link ClassNameGenerator}. |
||||
* @param classNameGenerator the class name generator to use. |
||||
*/ |
||||
public TestGenerationContext(ClassNameGenerator classNameGenerator) { |
||||
super(classNameGenerator, new InMemoryGeneratedFiles()); |
||||
} |
||||
|
||||
/** |
||||
* Create an instance using the specified {@code target}. |
||||
* @param target the default target class to use |
||||
*/ |
||||
public TestGenerationContext(Class<?> target) { |
||||
this(new ClassNameGenerator(target)); |
||||
} |
||||
|
||||
@Override |
||||
public InMemoryGeneratedFiles getGeneratedFiles() { |
||||
return (InMemoryGeneratedFiles) super.getGeneratedFiles(); |
||||
} |
||||
|
||||
@Override |
||||
public void writeGeneratedContent() { |
||||
try { |
||||
super.writeGeneratedContent(); |
||||
} |
||||
catch (IOException ex) { |
||||
throw new IllegalStateException(ex); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,9 @@
@@ -0,0 +1,9 @@
|
||||
/** |
||||
* Test support for core AOT classes. |
||||
*/ |
||||
@NonNullApi |
||||
@NonNullFields |
||||
package org.springframework.test.aot.generate; |
||||
|
||||
import org.springframework.lang.NonNullApi; |
||||
import org.springframework.lang.NonNullFields; |
Loading…
Reference in new issue