Skip to content

Commit 58b0251

Browse files
committed
Relocate TestGenerationContext to spring-core-test
This commit moves the test implementation for GenerationContext in spring-core-test. This also removes the copy we had in testfixtures See gh-28877
1 parent e57b5f1 commit 58b0251

File tree

24 files changed

+42
-90
lines changed

24 files changed

+42
-90
lines changed

spring-aop/src/test/java/org/springframework/aop/scope/ScopedProxyBeanRegistrationAotProcessorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import org.springframework.aop.framework.AopInfrastructureBean;
2828
import org.springframework.aot.generate.MethodReference;
29+
import org.springframework.aot.test.generate.TestGenerationContext;
2930
import org.springframework.aot.test.generator.compile.Compiled;
3031
import org.springframework.aot.test.generator.compile.TestCompiler;
3132
import org.springframework.beans.factory.BeanCreationException;
@@ -41,7 +42,6 @@
4142
import org.springframework.beans.testfixture.beans.factory.aot.MockBeanFactoryInitializationCode;
4243
import org.springframework.beans.testfixture.beans.factory.generator.factory.NumberHolder;
4344
import org.springframework.core.ResolvableType;
44-
import org.springframework.core.testfixture.aot.generate.TestGenerationContext;
4545
import org.springframework.javapoet.CodeBlock;
4646
import org.springframework.javapoet.MethodSpec;
4747
import org.springframework.javapoet.ParameterizedTypeName;

spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanRegistrationAotContributionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import org.springframework.aot.generate.MethodReference;
2727
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
28+
import org.springframework.aot.test.generate.TestGenerationContext;
2829
import org.springframework.aot.test.generator.compile.CompileWithTargetClassAccess;
2930
import org.springframework.aot.test.generator.compile.Compiled;
3031
import org.springframework.aot.test.generator.compile.TestCompiler;
@@ -35,7 +36,6 @@
3536
import org.springframework.beans.testfixture.beans.factory.aot.MockBeanRegistrationCode;
3637
import org.springframework.core.env.Environment;
3738
import org.springframework.core.env.StandardEnvironment;
38-
import org.springframework.core.testfixture.aot.generate.TestGenerationContext;
3939
import org.springframework.javapoet.CodeBlock;
4040
import org.springframework.javapoet.MethodSpec;
4141
import org.springframework.javapoet.ParameterizedTypeName;

spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.springframework.aot.generate.GeneratedMethod;
3131
import org.springframework.aot.generate.GenerationContext;
3232
import org.springframework.aot.generate.MethodReference;
33+
import org.springframework.aot.test.generate.TestGenerationContext;
3334
import org.springframework.aot.test.generator.compile.CompileWithTargetClassAccess;
3435
import org.springframework.aot.test.generator.compile.Compiled;
3536
import org.springframework.aot.test.generator.compile.TestCompiler;
@@ -47,7 +48,6 @@
4748
import org.springframework.beans.testfixture.beans.factory.aot.MockBeanRegistrationsCode;
4849
import org.springframework.core.ResolvableType;
4950
import org.springframework.core.mock.MockSpringFactoriesLoader;
50-
import org.springframework.core.testfixture.aot.generate.TestGenerationContext;
5151
import org.springframework.javapoet.CodeBlock;
5252
import org.springframework.javapoet.MethodSpec;
5353
import org.springframework.javapoet.ParameterizedTypeName;

spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGeneratorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import org.springframework.aot.generate.GeneratedClass;
3131
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
32+
import org.springframework.aot.test.generate.TestGenerationContext;
3233
import org.springframework.aot.test.generator.compile.Compiled;
3334
import org.springframework.aot.test.generator.compile.TestCompiler;
3435
import org.springframework.beans.factory.FactoryBean;
@@ -43,7 +44,6 @@
4344
import org.springframework.beans.factory.support.ManagedSet;
4445
import org.springframework.beans.factory.support.RootBeanDefinition;
4546
import org.springframework.beans.testfixture.beans.factory.aot.DeferredTypeBuilder;
46-
import org.springframework.core.testfixture.aot.generate.TestGenerationContext;
4747
import org.springframework.javapoet.CodeBlock;
4848
import org.springframework.javapoet.MethodSpec;
4949
import org.springframework.javapoet.ParameterizedTypeName;

spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertyValueCodeGeneratorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.junit.jupiter.api.Test;
3535

3636
import org.springframework.aot.generate.GeneratedClass;
37+
import org.springframework.aot.test.generate.TestGenerationContext;
3738
import org.springframework.aot.test.generator.compile.Compiled;
3839
import org.springframework.aot.test.generator.compile.TestCompiler;
3940
import org.springframework.beans.factory.config.BeanReference;
@@ -44,7 +45,6 @@
4445
import org.springframework.beans.factory.support.ManagedSet;
4546
import org.springframework.beans.testfixture.beans.factory.aot.DeferredTypeBuilder;
4647
import org.springframework.core.ResolvableType;
47-
import org.springframework.core.testfixture.aot.generate.TestGenerationContext;
4848
import org.springframework.javapoet.CodeBlock;
4949
import org.springframework.javapoet.MethodSpec;
5050
import org.springframework.javapoet.ParameterizedTypeName;

spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContributionTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import org.springframework.aot.generate.ClassNameGenerator;
3232
import org.springframework.aot.generate.GenerationContext;
3333
import org.springframework.aot.generate.MethodReference;
34+
import org.springframework.aot.test.generate.TestGenerationContext;
35+
import org.springframework.aot.test.generate.TestTarget;
3436
import org.springframework.aot.test.generator.compile.Compiled;
3537
import org.springframework.aot.test.generator.compile.TestCompiler;
3638
import org.springframework.aot.test.generator.file.SourceFile;
@@ -40,8 +42,6 @@
4042
import org.springframework.beans.testfixture.beans.TestBean;
4143
import org.springframework.beans.testfixture.beans.factory.aot.MockBeanFactoryInitializationCode;
4244
import org.springframework.core.mock.MockSpringFactoriesLoader;
43-
import org.springframework.core.testfixture.aot.generate.TestGenerationContext;
44-
import org.springframework.core.testfixture.aot.generate.TestTarget;
4545
import org.springframework.javapoet.CodeBlock;
4646
import org.springframework.javapoet.MethodSpec;
4747
import org.springframework.javapoet.ParameterizedTypeName;

spring-beans/src/test/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragmentsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.junit.jupiter.api.Test;
2222

23+
import org.springframework.aot.test.generate.TestGenerationContext;
2324
import org.springframework.beans.factory.FactoryBean;
2425
import org.springframework.beans.factory.annotation.InjectAnnotationBeanPostProcessorTests.StringFactoryBean;
2526
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
@@ -33,7 +34,6 @@
3334
import org.springframework.beans.testfixture.beans.factory.aot.SimpleBeanConfiguration;
3435
import org.springframework.beans.testfixture.beans.factory.aot.SimpleBeanFactoryBean;
3536
import org.springframework.core.ResolvableType;
36-
import org.springframework.core.testfixture.aot.generate.TestGenerationContext;
3737
import org.springframework.util.ReflectionUtils;
3838

3939
import static org.assertj.core.api.Assertions.assertThat;

spring-beans/src/test/java/org/springframework/beans/factory/aot/InstanceSupplierCodeGeneratorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.springframework.aot.hint.ExecutableMode;
3131
import org.springframework.aot.hint.ReflectionHints;
3232
import org.springframework.aot.hint.TypeHint;
33+
import org.springframework.aot.test.generate.TestGenerationContext;
3334
import org.springframework.aot.test.generator.compile.Compiled;
3435
import org.springframework.aot.test.generator.compile.TestCompiler;
3536
import org.springframework.beans.factory.config.BeanDefinition;
@@ -50,7 +51,6 @@
5051
import org.springframework.beans.testfixture.beans.factory.generator.factory.SampleFactory;
5152
import org.springframework.beans.testfixture.beans.factory.generator.injection.InjectionComponent;
5253
import org.springframework.core.env.StandardEnvironment;
53-
import org.springframework.core.testfixture.aot.generate.TestGenerationContext;
5454
import org.springframework.javapoet.CodeBlock;
5555
import org.springframework.javapoet.MethodSpec;
5656
import org.springframework.javapoet.ParameterizedTypeName;

spring-context/spring-context.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ dependencies {
2626
optional("org.jetbrains.kotlin:kotlin-reflect")
2727
optional("org.jetbrains.kotlin:kotlin-stdlib")
2828
optional("org.reactivestreams:reactive-streams")
29+
testImplementation(project(":spring-core-test"))
2930
testImplementation(testFixtures(project(":spring-aop")))
3031
testImplementation(testFixtures(project(":spring-beans")))
3132
testImplementation(testFixtures(project(":spring-core")))
32-
testImplementation(project(":spring-core-test"))
3333
testImplementation("io.projectreactor:reactor-core")
3434
testImplementation("org.apache.groovy:groovy-jsr223")
3535
testImplementation("org.apache.groovy:groovy-xml")

spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorAotContributionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import org.springframework.aot.generate.MethodReference;
3030
import org.springframework.aot.hint.ResourcePatternHint;
31+
import org.springframework.aot.test.generate.TestGenerationContext;
3132
import org.springframework.aot.test.generator.compile.Compiled;
3233
import org.springframework.aot.test.generator.compile.TestCompiler;
3334
import org.springframework.beans.BeansException;
@@ -44,7 +45,6 @@
4445
import org.springframework.context.testfixture.context.generator.annotation.ImportAwareConfiguration;
4546
import org.springframework.context.testfixture.context.generator.annotation.ImportConfiguration;
4647
import org.springframework.core.Ordered;
47-
import org.springframework.core.testfixture.aot.generate.TestGenerationContext;
4848
import org.springframework.core.type.AnnotationMetadata;
4949
import org.springframework.javapoet.CodeBlock;
5050
import org.springframework.javapoet.MethodSpec;

spring-context/src/test/java/org/springframework/context/aot/ApplicationContextAotGeneratorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.springframework.aot.hint.RuntimeHints;
3232
import org.springframework.aot.hint.TypeReference;
3333
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
34+
import org.springframework.aot.test.generate.TestGenerationContext;
3435
import org.springframework.aot.test.generator.compile.Compiled;
3536
import org.springframework.aot.test.generator.compile.TestCompiler;
3637
import org.springframework.beans.BeansException;
@@ -62,7 +63,6 @@
6263
import org.springframework.context.testfixture.context.generator.annotation.LazyFactoryMethodArgumentComponent;
6364
import org.springframework.core.env.Environment;
6465
import org.springframework.core.io.ResourceLoader;
65-
import org.springframework.core.testfixture.aot.generate.TestGenerationContext;
6666

6767
import static org.assertj.core.api.Assertions.assertThat;
6868

spring-context/src/test/java/org/springframework/context/aot/GeneratedClassHandlerTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
import org.springframework.aot.hint.MemberCategory;
2727
import org.springframework.aot.hint.TypeReference;
2828
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
29+
import org.springframework.aot.test.generate.TestGenerationContext;
2930
import org.springframework.core.io.InputStreamSource;
30-
import org.springframework.core.testfixture.aot.generate.TestGenerationContext;
3131

3232
import static org.assertj.core.api.Assertions.assertThat;
3333
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;

spring-context/src/test/java/org/springframework/context/aot/ReflectiveProcessorBeanFactoryInitializationAotProcessorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
import org.springframework.aot.hint.annotation.Reflective;
2525
import org.springframework.aot.hint.predicate.ReflectionHintsPredicates;
2626
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
27+
import org.springframework.aot.test.generate.TestGenerationContext;
2728
import org.springframework.beans.factory.aot.AotServices;
2829
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution;
2930
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor;
3031
import org.springframework.beans.factory.aot.BeanFactoryInitializationCode;
3132
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
3233
import org.springframework.beans.factory.support.RootBeanDefinition;
33-
import org.springframework.core.testfixture.aot.generate.TestGenerationContext;
3434

3535
import static org.assertj.core.api.Assertions.assertThat;
3636
import static org.mockito.Mockito.mock;

spring-context/src/test/java/org/springframework/context/aot/RuntimeHintsBeanFactoryInitializationAotProcessorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
import org.springframework.aot.hint.ResourceBundleHint;
3030
import org.springframework.aot.hint.RuntimeHints;
3131
import org.springframework.aot.hint.RuntimeHintsRegistrar;
32+
import org.springframework.aot.test.generate.TestGenerationContext;
3233
import org.springframework.beans.BeanInstantiationException;
3334
import org.springframework.beans.factory.support.RootBeanDefinition;
3435
import org.springframework.context.annotation.AnnotationConfigUtils;
3536
import org.springframework.context.annotation.Bean;
3637
import org.springframework.context.annotation.Configuration;
3738
import org.springframework.context.annotation.ImportRuntimeHints;
3839
import org.springframework.context.support.GenericApplicationContext;
39-
import org.springframework.core.testfixture.aot.generate.TestGenerationContext;
4040
import org.springframework.lang.Nullable;
4141

4242
import static org.assertj.core.api.Assertions.assertThat;

spring-context/src/test/java/org/springframework/context/generator/ApplicationContextAotGeneratorRuntimeHintsTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.springframework.aot.test.agent.EnabledIfRuntimeHintsAgent;
2828
import org.springframework.aot.test.agent.RuntimeHintsInvocations;
2929
import org.springframework.aot.test.agent.RuntimeHintsRecorder;
30+
import org.springframework.aot.test.generate.TestGenerationContext;
3031
import org.springframework.aot.test.generator.compile.TestCompiler;
3132
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
3233
import org.springframework.beans.factory.support.RootBeanDefinition;
@@ -37,7 +38,6 @@
3738
import org.springframework.context.testfixture.context.generator.SimpleComponent;
3839
import org.springframework.context.testfixture.context.generator.annotation.AutowiredComponent;
3940
import org.springframework.context.testfixture.context.generator.annotation.InitDestroyComponent;
40-
import org.springframework.core.testfixture.aot.generate.TestGenerationContext;
4141

4242
import static org.assertj.core.api.Assertions.assertThat;
4343

spring-test/src/main/java/org/springframework/test/aot/generate/TestGenerationContext.java renamed to spring-core-test/src/main/java/org/springframework/aot/test/generate/TestGenerationContext.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.test.aot.generate;
17+
package org.springframework.aot.test.generate;
1818

1919
import org.springframework.aot.generate.ClassNameGenerator;
2020
import org.springframework.aot.generate.DefaultGenerationContext;
@@ -31,6 +31,14 @@
3131
*/
3232
public class TestGenerationContext extends DefaultGenerationContext {
3333

34+
/**
35+
* Create an instance using the specified {@link ClassNameGenerator}.
36+
* @param classNameGenerator the class name generator to use
37+
*/
38+
public TestGenerationContext(ClassNameGenerator classNameGenerator) {
39+
super(classNameGenerator, new InMemoryGeneratedFiles());
40+
}
41+
3442
/**
3543
* Create an instance using the specified {@code target}.
3644
* @param target the default target class to use
@@ -40,11 +48,10 @@ public TestGenerationContext(Class<?> target) {
4048
}
4149

4250
/**
43-
* Create an instance using the specified {@link ClassNameGenerator}.
44-
* @param classNameGenerator the class name generator to use
51+
* Create an instance using {@link TestTarget} as the {@code target}.
4552
*/
46-
public TestGenerationContext(ClassNameGenerator classNameGenerator) {
47-
super(classNameGenerator, new InMemoryGeneratedFiles());
53+
public TestGenerationContext() {
54+
this(TestTarget.class);
4855
}
4956

5057

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.core.testfixture.aot.generate;
17+
package org.springframework.aot.test.generate;
1818

1919
/**
2020
* A <em>default target class</em> used by tests of code generation.

spring-test/src/main/java/org/springframework/test/aot/generate/package-info.java renamed to spring-core-test/src/main/java/org/springframework/aot/test/generate/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
@NonNullApi
55
@NonNullFields
6-
package org.springframework.test.aot.generate;
6+
package org.springframework.aot.test.generate;
77

88
import org.springframework.lang.NonNullApi;
99
import org.springframework.lang.NonNullFields;

spring-core/src/test/java/org/springframework/aot/generate/DefaultGenerationContextTests.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616

1717
package org.springframework.aot.generate;
1818

19-
import java.io.IOException;
2019
import java.util.function.Consumer;
2120

2221
import org.junit.jupiter.api.Test;
2322

2423
import org.springframework.aot.generate.GeneratedFiles.Kind;
2524
import org.springframework.aot.hint.RuntimeHints;
26-
import org.springframework.core.testfixture.aot.generate.TestTarget;
2725
import org.springframework.javapoet.TypeSpec;
2826

2927
import static org.assertj.core.api.Assertions.assertThat;
@@ -40,7 +38,7 @@ class DefaultGenerationContextTests {
4038
private static final Consumer<TypeSpec.Builder> typeSpecCustomizer = type -> {};
4139

4240
private final GeneratedClasses generatedClasses = new GeneratedClasses(
43-
new ClassNameGenerator(TestTarget.class));
41+
new ClassNameGenerator(SampleTarget.class));
4442

4543
private final InMemoryGeneratedFiles generatedFiles = new InMemoryGeneratedFiles();
4644

@@ -50,7 +48,7 @@ class DefaultGenerationContextTests {
5048
@Test
5149
void createWithOnlyGeneratedFilesCreatesContext() {
5250
DefaultGenerationContext context = new DefaultGenerationContext(
53-
new ClassNameGenerator(TestTarget.class), this.generatedFiles);
51+
new ClassNameGenerator(SampleTarget.class), this.generatedFiles);
5452
assertThat(context.getGeneratedFiles()).isSameAs(this.generatedFiles);
5553
assertThat(context.getRuntimeHints()).isInstanceOf(RuntimeHints.class);
5654
}
@@ -111,17 +109,17 @@ void getRuntimeHintsReturnsRuntimeHints() {
111109
@Test
112110
void withNameUpdateNamingConvention() {
113111
DefaultGenerationContext context = new DefaultGenerationContext(
114-
new ClassNameGenerator(TestTarget.class), this.generatedFiles);
112+
new ClassNameGenerator(SampleTarget.class), this.generatedFiles);
115113
GenerationContext anotherContext = context.withName("Another");
116114
GeneratedClass generatedClass = anotherContext.getGeneratedClasses()
117115
.addForFeature("Test", typeSpecCustomizer);
118116
assertThat(generatedClass.getName().simpleName()).endsWith("__AnotherTest");
119117
}
120118

121119
@Test
122-
void withNameKeepsTrackOfAllGeneratedFiles() throws IOException {
120+
void withNameKeepsTrackOfAllGeneratedFiles() {
123121
DefaultGenerationContext context = new DefaultGenerationContext(
124-
new ClassNameGenerator(TestTarget.class), this.generatedFiles);
122+
new ClassNameGenerator(SampleTarget.class), this.generatedFiles);
125123
context.getGeneratedClasses().addForFeature("Test", typeSpecCustomizer);
126124
GenerationContext anotherContext = context.withName("Another");
127125
assertThat(anotherContext.getGeneratedClasses()).isNotSameAs(context.getGeneratedClasses());
@@ -133,7 +131,7 @@ void withNameKeepsTrackOfAllGeneratedFiles() throws IOException {
133131
}
134132

135133
@Test
136-
void withNameGeneratesUniqueName() throws IOException {
134+
void withNameGeneratesUniqueName() {
137135
DefaultGenerationContext context = new DefaultGenerationContext(
138136
new ClassNameGenerator(Object.class), this.generatedFiles);
139137
context.withName("Test").getGeneratedClasses()
@@ -149,4 +147,6 @@ void withNameGeneratesUniqueName() throws IOException {
149147
"java/lang/Object__Test2Feature.java");
150148
}
151149

150+
static class SampleTarget {}
151+
152152
}

0 commit comments

Comments
 (0)