From 58b0251af14f177a1accf08336987a149cf7e200 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Mon, 5 Sep 2022 16:21:17 +0200 Subject: [PATCH] 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 --- ...roxyBeanRegistrationAotProcessorTests.java | 2 +- ...nBeanRegistrationAotContributionTests.java | 2 +- .../BeanDefinitionMethodGeneratorTests.java | 2 +- ...efinitionPropertiesCodeGeneratorTests.java | 2 +- ...nitionPropertyValueCodeGeneratorTests.java | 2 +- ...BeanRegistrationsAotContributionTests.java | 4 +- ...ultBeanRegistrationCodeFragmentsTests.java | 2 +- .../InstanceSupplierCodeGeneratorTests.java | 2 +- spring-context/spring-context.gradle | 2 +- ...lassPostProcessorAotContributionTests.java | 2 +- .../ApplicationContextAotGeneratorTests.java | 2 +- .../aot/GeneratedClassHandlerTests.java | 2 +- ...actoryInitializationAotProcessorTests.java | 2 +- ...actoryInitializationAotProcessorTests.java | 2 +- ...nContextAotGeneratorRuntimeHintsTests.java | 2 +- .../test}/generate/TestGenerationContext.java | 17 ++++-- .../aot/test}/generate/TestTarget.java | 2 +- .../aot/test}/generate/package-info.java | 2 +- .../DefaultGenerationContextTests.java | 16 +++--- .../aot/generate/TestGenerationContext.java | 56 ------------------- ...ypesBeanRegistrationAotProcessorTests.java | 2 +- ...BeanPostProcessorAotContributionTests.java | 2 +- spring-tx/spring-tx.gradle | 1 + ...tionBeanRegistrationAotProcessorTests.java | 2 +- 24 files changed, 42 insertions(+), 90 deletions(-) rename {spring-test/src/main/java/org/springframework/test/aot => spring-core-test/src/main/java/org/springframework/aot/test}/generate/TestGenerationContext.java (90%) rename {spring-core/src/testFixtures/java/org/springframework/core/testfixture/aot => spring-core-test/src/main/java/org/springframework/aot/test}/generate/TestTarget.java (92%) rename {spring-test/src/main/java/org/springframework/test/aot => spring-core-test/src/main/java/org/springframework/aot/test}/generate/package-info.java (77%) delete mode 100644 spring-core/src/testFixtures/java/org/springframework/core/testfixture/aot/generate/TestGenerationContext.java diff --git a/spring-aop/src/test/java/org/springframework/aop/scope/ScopedProxyBeanRegistrationAotProcessorTests.java b/spring-aop/src/test/java/org/springframework/aop/scope/ScopedProxyBeanRegistrationAotProcessorTests.java index a84de8b8b9..5db7263f6b 100644 --- a/spring-aop/src/test/java/org/springframework/aop/scope/ScopedProxyBeanRegistrationAotProcessorTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/scope/ScopedProxyBeanRegistrationAotProcessorTests.java @@ -26,6 +26,7 @@ import org.junit.jupiter.api.Test; import org.springframework.aop.framework.AopInfrastructureBean; import org.springframework.aot.generate.MethodReference; +import org.springframework.aot.test.generate.TestGenerationContext; import org.springframework.aot.test.generator.compile.Compiled; import org.springframework.aot.test.generator.compile.TestCompiler; import org.springframework.beans.factory.BeanCreationException; @@ -41,7 +42,6 @@ import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.testfixture.beans.factory.aot.MockBeanFactoryInitializationCode; import org.springframework.beans.testfixture.beans.factory.generator.factory.NumberHolder; import org.springframework.core.ResolvableType; -import org.springframework.core.testfixture.aot.generate.TestGenerationContext; import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.MethodSpec; import org.springframework.javapoet.ParameterizedTypeName; diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanRegistrationAotContributionTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanRegistrationAotContributionTests.java index 998889ba19..b7e096108d 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanRegistrationAotContributionTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanRegistrationAotContributionTests.java @@ -25,6 +25,7 @@ import org.junit.jupiter.api.Test; import org.springframework.aot.generate.MethodReference; import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; +import org.springframework.aot.test.generate.TestGenerationContext; import org.springframework.aot.test.generator.compile.CompileWithTargetClassAccess; import org.springframework.aot.test.generator.compile.Compiled; import org.springframework.aot.test.generator.compile.TestCompiler; @@ -35,7 +36,6 @@ import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.testfixture.beans.factory.aot.MockBeanRegistrationCode; import org.springframework.core.env.Environment; import org.springframework.core.env.StandardEnvironment; -import org.springframework.core.testfixture.aot.generate.TestGenerationContext; import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.MethodSpec; import org.springframework.javapoet.ParameterizedTypeName; diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorTests.java index bfe35817ea..3f93fd7aa5 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorTests.java @@ -30,6 +30,7 @@ import org.junit.jupiter.api.Test; import org.springframework.aot.generate.GeneratedMethod; import org.springframework.aot.generate.GenerationContext; import org.springframework.aot.generate.MethodReference; +import org.springframework.aot.test.generate.TestGenerationContext; import org.springframework.aot.test.generator.compile.CompileWithTargetClassAccess; import org.springframework.aot.test.generator.compile.Compiled; import org.springframework.aot.test.generator.compile.TestCompiler; @@ -47,7 +48,6 @@ import org.springframework.beans.testfixture.beans.TestBean; import org.springframework.beans.testfixture.beans.factory.aot.MockBeanRegistrationsCode; import org.springframework.core.ResolvableType; import org.springframework.core.mock.MockSpringFactoriesLoader; -import org.springframework.core.testfixture.aot.generate.TestGenerationContext; import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.MethodSpec; import org.springframework.javapoet.ParameterizedTypeName; diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGeneratorTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGeneratorTests.java index 1948f7f454..0689e4b32b 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGeneratorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGeneratorTests.java @@ -29,6 +29,7 @@ import org.junit.jupiter.api.Test; import org.springframework.aot.generate.GeneratedClass; import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; +import org.springframework.aot.test.generate.TestGenerationContext; import org.springframework.aot.test.generator.compile.Compiled; import org.springframework.aot.test.generator.compile.TestCompiler; import org.springframework.beans.factory.FactoryBean; @@ -43,7 +44,6 @@ import org.springframework.beans.factory.support.ManagedMap; import org.springframework.beans.factory.support.ManagedSet; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.testfixture.beans.factory.aot.DeferredTypeBuilder; -import org.springframework.core.testfixture.aot.generate.TestGenerationContext; import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.MethodSpec; import org.springframework.javapoet.ParameterizedTypeName; diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertyValueCodeGeneratorTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertyValueCodeGeneratorTests.java index fdadd65a6f..747a73d766 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertyValueCodeGeneratorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertyValueCodeGeneratorTests.java @@ -34,6 +34,7 @@ import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.aot.generate.GeneratedClass; +import org.springframework.aot.test.generate.TestGenerationContext; import org.springframework.aot.test.generator.compile.Compiled; import org.springframework.aot.test.generator.compile.TestCompiler; import org.springframework.beans.factory.config.BeanReference; @@ -44,7 +45,6 @@ import org.springframework.beans.factory.support.ManagedMap; import org.springframework.beans.factory.support.ManagedSet; import org.springframework.beans.testfixture.beans.factory.aot.DeferredTypeBuilder; import org.springframework.core.ResolvableType; -import org.springframework.core.testfixture.aot.generate.TestGenerationContext; import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.MethodSpec; import org.springframework.javapoet.ParameterizedTypeName; diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContributionTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContributionTests.java index f84239532f..3cfcb9b613 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContributionTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContributionTests.java @@ -31,6 +31,8 @@ import org.junit.jupiter.api.Test; import org.springframework.aot.generate.ClassNameGenerator; import org.springframework.aot.generate.GenerationContext; import org.springframework.aot.generate.MethodReference; +import org.springframework.aot.test.generate.TestGenerationContext; +import org.springframework.aot.test.generate.TestTarget; import org.springframework.aot.test.generator.compile.Compiled; import org.springframework.aot.test.generator.compile.TestCompiler; import org.springframework.aot.test.generator.file.SourceFile; @@ -40,8 +42,6 @@ import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.testfixture.beans.TestBean; import org.springframework.beans.testfixture.beans.factory.aot.MockBeanFactoryInitializationCode; import org.springframework.core.mock.MockSpringFactoriesLoader; -import org.springframework.core.testfixture.aot.generate.TestGenerationContext; -import org.springframework.core.testfixture.aot.generate.TestTarget; import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.MethodSpec; import org.springframework.javapoet.ParameterizedTypeName; diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragmentsTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragmentsTests.java index 4883c06814..ac53388579 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragmentsTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragmentsTests.java @@ -20,6 +20,7 @@ import java.lang.reflect.Method; import org.junit.jupiter.api.Test; +import org.springframework.aot.test.generate.TestGenerationContext; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.annotation.InjectAnnotationBeanPostProcessorTests.StringFactoryBean; import org.springframework.beans.factory.support.DefaultListableBeanFactory; @@ -33,7 +34,6 @@ import org.springframework.beans.testfixture.beans.factory.aot.SimpleBean; import org.springframework.beans.testfixture.beans.factory.aot.SimpleBeanConfiguration; import org.springframework.beans.testfixture.beans.factory.aot.SimpleBeanFactoryBean; import org.springframework.core.ResolvableType; -import org.springframework.core.testfixture.aot.generate.TestGenerationContext; import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/aot/InstanceSupplierCodeGeneratorTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/aot/InstanceSupplierCodeGeneratorTests.java index 78378f6b0a..313052870c 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/aot/InstanceSupplierCodeGeneratorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/aot/InstanceSupplierCodeGeneratorTests.java @@ -30,6 +30,7 @@ import org.springframework.aot.hint.ExecutableHint; import org.springframework.aot.hint.ExecutableMode; import org.springframework.aot.hint.ReflectionHints; import org.springframework.aot.hint.TypeHint; +import org.springframework.aot.test.generate.TestGenerationContext; import org.springframework.aot.test.generator.compile.Compiled; import org.springframework.aot.test.generator.compile.TestCompiler; import org.springframework.beans.factory.config.BeanDefinition; @@ -50,7 +51,6 @@ import org.springframework.beans.testfixture.beans.factory.generator.factory.Num import org.springframework.beans.testfixture.beans.factory.generator.factory.SampleFactory; import org.springframework.beans.testfixture.beans.factory.generator.injection.InjectionComponent; import org.springframework.core.env.StandardEnvironment; -import org.springframework.core.testfixture.aot.generate.TestGenerationContext; import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.MethodSpec; import org.springframework.javapoet.ParameterizedTypeName; diff --git a/spring-context/spring-context.gradle b/spring-context/spring-context.gradle index 72c93322f8..5f5ac1001e 100644 --- a/spring-context/spring-context.gradle +++ b/spring-context/spring-context.gradle @@ -26,10 +26,10 @@ dependencies { optional("org.jetbrains.kotlin:kotlin-reflect") optional("org.jetbrains.kotlin:kotlin-stdlib") optional("org.reactivestreams:reactive-streams") + testImplementation(project(":spring-core-test")) testImplementation(testFixtures(project(":spring-aop"))) testImplementation(testFixtures(project(":spring-beans"))) testImplementation(testFixtures(project(":spring-core"))) - testImplementation(project(":spring-core-test")) testImplementation("io.projectreactor:reactor-core") testImplementation("org.apache.groovy:groovy-jsr223") testImplementation("org.apache.groovy:groovy-xml") diff --git a/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorAotContributionTests.java b/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorAotContributionTests.java index bae0835fc5..9187922512 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorAotContributionTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorAotContributionTests.java @@ -28,6 +28,7 @@ import org.junit.jupiter.api.Test; import org.springframework.aot.generate.MethodReference; import org.springframework.aot.hint.ResourcePatternHint; +import org.springframework.aot.test.generate.TestGenerationContext; import org.springframework.aot.test.generator.compile.Compiled; import org.springframework.aot.test.generator.compile.TestCompiler; import org.springframework.beans.BeansException; @@ -44,7 +45,6 @@ import org.springframework.context.support.GenericApplicationContext; import org.springframework.context.testfixture.context.generator.annotation.ImportAwareConfiguration; import org.springframework.context.testfixture.context.generator.annotation.ImportConfiguration; import org.springframework.core.Ordered; -import org.springframework.core.testfixture.aot.generate.TestGenerationContext; import org.springframework.core.type.AnnotationMetadata; import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.MethodSpec; diff --git a/spring-context/src/test/java/org/springframework/context/aot/ApplicationContextAotGeneratorTests.java b/spring-context/src/test/java/org/springframework/context/aot/ApplicationContextAotGeneratorTests.java index ace1f8fac6..1df024a819 100644 --- a/spring-context/src/test/java/org/springframework/context/aot/ApplicationContextAotGeneratorTests.java +++ b/spring-context/src/test/java/org/springframework/context/aot/ApplicationContextAotGeneratorTests.java @@ -31,6 +31,7 @@ import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.TypeReference; import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; +import org.springframework.aot.test.generate.TestGenerationContext; import org.springframework.aot.test.generator.compile.Compiled; import org.springframework.aot.test.generator.compile.TestCompiler; import org.springframework.beans.BeansException; @@ -62,7 +63,6 @@ import org.springframework.context.testfixture.context.generator.annotation.Lazy import org.springframework.context.testfixture.context.generator.annotation.LazyFactoryMethodArgumentComponent; import org.springframework.core.env.Environment; import org.springframework.core.io.ResourceLoader; -import org.springframework.core.testfixture.aot.generate.TestGenerationContext; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-context/src/test/java/org/springframework/context/aot/GeneratedClassHandlerTests.java b/spring-context/src/test/java/org/springframework/context/aot/GeneratedClassHandlerTests.java index 3959c3928c..4c884cae1a 100644 --- a/spring-context/src/test/java/org/springframework/context/aot/GeneratedClassHandlerTests.java +++ b/spring-context/src/test/java/org/springframework/context/aot/GeneratedClassHandlerTests.java @@ -26,8 +26,8 @@ import org.springframework.aot.generate.InMemoryGeneratedFiles; import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.TypeReference; import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; +import org.springframework.aot.test.generate.TestGenerationContext; import org.springframework.core.io.InputStreamSource; -import org.springframework.core.testfixture.aot.generate.TestGenerationContext; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; diff --git a/spring-context/src/test/java/org/springframework/context/aot/ReflectiveProcessorBeanFactoryInitializationAotProcessorTests.java b/spring-context/src/test/java/org/springframework/context/aot/ReflectiveProcessorBeanFactoryInitializationAotProcessorTests.java index cf0cf03d84..649e156f13 100644 --- a/spring-context/src/test/java/org/springframework/context/aot/ReflectiveProcessorBeanFactoryInitializationAotProcessorTests.java +++ b/spring-context/src/test/java/org/springframework/context/aot/ReflectiveProcessorBeanFactoryInitializationAotProcessorTests.java @@ -24,13 +24,13 @@ import org.springframework.aot.generate.GenerationContext; import org.springframework.aot.hint.annotation.Reflective; import org.springframework.aot.hint.predicate.ReflectionHintsPredicates; import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; +import org.springframework.aot.test.generate.TestGenerationContext; import org.springframework.beans.factory.aot.AotServices; import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution; import org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor; import org.springframework.beans.factory.aot.BeanFactoryInitializationCode; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.core.testfixture.aot.generate.TestGenerationContext; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; diff --git a/spring-context/src/test/java/org/springframework/context/aot/RuntimeHintsBeanFactoryInitializationAotProcessorTests.java b/spring-context/src/test/java/org/springframework/context/aot/RuntimeHintsBeanFactoryInitializationAotProcessorTests.java index 7836ee6b13..da799a56b7 100644 --- a/spring-context/src/test/java/org/springframework/context/aot/RuntimeHintsBeanFactoryInitializationAotProcessorTests.java +++ b/spring-context/src/test/java/org/springframework/context/aot/RuntimeHintsBeanFactoryInitializationAotProcessorTests.java @@ -29,6 +29,7 @@ import org.springframework.aot.generate.GenerationContext; import org.springframework.aot.hint.ResourceBundleHint; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; +import org.springframework.aot.test.generate.TestGenerationContext; import org.springframework.beans.BeanInstantiationException; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.context.annotation.AnnotationConfigUtils; @@ -36,7 +37,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportRuntimeHints; import org.springframework.context.support.GenericApplicationContext; -import org.springframework.core.testfixture.aot.generate.TestGenerationContext; import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-context/src/test/java/org/springframework/context/generator/ApplicationContextAotGeneratorRuntimeHintsTests.java b/spring-context/src/test/java/org/springframework/context/generator/ApplicationContextAotGeneratorRuntimeHintsTests.java index 3dd77fa04b..54149d6bd9 100644 --- a/spring-context/src/test/java/org/springframework/context/generator/ApplicationContextAotGeneratorRuntimeHintsTests.java +++ b/spring-context/src/test/java/org/springframework/context/generator/ApplicationContextAotGeneratorRuntimeHintsTests.java @@ -27,6 +27,7 @@ import org.springframework.aot.hint.TypeReference; import org.springframework.aot.test.agent.EnabledIfRuntimeHintsAgent; import org.springframework.aot.test.agent.RuntimeHintsInvocations; import org.springframework.aot.test.agent.RuntimeHintsRecorder; +import org.springframework.aot.test.generate.TestGenerationContext; import org.springframework.aot.test.generator.compile.TestCompiler; import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.RootBeanDefinition; @@ -37,7 +38,6 @@ import org.springframework.context.support.GenericApplicationContext; import org.springframework.context.testfixture.context.generator.SimpleComponent; import org.springframework.context.testfixture.context.generator.annotation.AutowiredComponent; import org.springframework.context.testfixture.context.generator.annotation.InitDestroyComponent; -import org.springframework.core.testfixture.aot.generate.TestGenerationContext; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-test/src/main/java/org/springframework/test/aot/generate/TestGenerationContext.java b/spring-core-test/src/main/java/org/springframework/aot/test/generate/TestGenerationContext.java similarity index 90% rename from spring-test/src/main/java/org/springframework/test/aot/generate/TestGenerationContext.java rename to spring-core-test/src/main/java/org/springframework/aot/test/generate/TestGenerationContext.java index f51f883405..061c0b8a8a 100644 --- a/spring-test/src/main/java/org/springframework/test/aot/generate/TestGenerationContext.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generate/TestGenerationContext.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.test.aot.generate; +package org.springframework.aot.test.generate; import org.springframework.aot.generate.ClassNameGenerator; import org.springframework.aot.generate.DefaultGenerationContext; @@ -31,6 +31,14 @@ import org.springframework.aot.generate.InMemoryGeneratedFiles; */ 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 @@ -40,11 +48,10 @@ public class TestGenerationContext extends DefaultGenerationContext { } /** - * Create an instance using the specified {@link ClassNameGenerator}. - * @param classNameGenerator the class name generator to use + * Create an instance using {@link TestTarget} as the {@code target}. */ - public TestGenerationContext(ClassNameGenerator classNameGenerator) { - super(classNameGenerator, new InMemoryGeneratedFiles()); + public TestGenerationContext() { + this(TestTarget.class); } diff --git a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/aot/generate/TestTarget.java b/spring-core-test/src/main/java/org/springframework/aot/test/generate/TestTarget.java similarity index 92% rename from spring-core/src/testFixtures/java/org/springframework/core/testfixture/aot/generate/TestTarget.java rename to spring-core-test/src/main/java/org/springframework/aot/test/generate/TestTarget.java index a7b5fa6564..f63ead634e 100644 --- a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/aot/generate/TestTarget.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generate/TestTarget.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.core.testfixture.aot.generate; +package org.springframework.aot.test.generate; /** * A default target class used by tests of code generation. diff --git a/spring-test/src/main/java/org/springframework/test/aot/generate/package-info.java b/spring-core-test/src/main/java/org/springframework/aot/test/generate/package-info.java similarity index 77% rename from spring-test/src/main/java/org/springframework/test/aot/generate/package-info.java rename to spring-core-test/src/main/java/org/springframework/aot/test/generate/package-info.java index 223552e697..9235cf21d5 100644 --- a/spring-test/src/main/java/org/springframework/test/aot/generate/package-info.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generate/package-info.java @@ -3,7 +3,7 @@ */ @NonNullApi @NonNullFields -package org.springframework.test.aot.generate; +package org.springframework.aot.test.generate; import org.springframework.lang.NonNullApi; import org.springframework.lang.NonNullFields; diff --git a/spring-core/src/test/java/org/springframework/aot/generate/DefaultGenerationContextTests.java b/spring-core/src/test/java/org/springframework/aot/generate/DefaultGenerationContextTests.java index fe036f7abf..137f166cb8 100644 --- a/spring-core/src/test/java/org/springframework/aot/generate/DefaultGenerationContextTests.java +++ b/spring-core/src/test/java/org/springframework/aot/generate/DefaultGenerationContextTests.java @@ -16,14 +16,12 @@ package org.springframework.aot.generate; -import java.io.IOException; import java.util.function.Consumer; import org.junit.jupiter.api.Test; import org.springframework.aot.generate.GeneratedFiles.Kind; import org.springframework.aot.hint.RuntimeHints; -import org.springframework.core.testfixture.aot.generate.TestTarget; import org.springframework.javapoet.TypeSpec; import static org.assertj.core.api.Assertions.assertThat; @@ -40,7 +38,7 @@ class DefaultGenerationContextTests { private static final Consumer typeSpecCustomizer = type -> {}; private final GeneratedClasses generatedClasses = new GeneratedClasses( - new ClassNameGenerator(TestTarget.class)); + new ClassNameGenerator(SampleTarget.class)); private final InMemoryGeneratedFiles generatedFiles = new InMemoryGeneratedFiles(); @@ -50,7 +48,7 @@ class DefaultGenerationContextTests { @Test void createWithOnlyGeneratedFilesCreatesContext() { DefaultGenerationContext context = new DefaultGenerationContext( - new ClassNameGenerator(TestTarget.class), this.generatedFiles); + new ClassNameGenerator(SampleTarget.class), this.generatedFiles); assertThat(context.getGeneratedFiles()).isSameAs(this.generatedFiles); assertThat(context.getRuntimeHints()).isInstanceOf(RuntimeHints.class); } @@ -111,7 +109,7 @@ class DefaultGenerationContextTests { @Test void withNameUpdateNamingConvention() { DefaultGenerationContext context = new DefaultGenerationContext( - new ClassNameGenerator(TestTarget.class), this.generatedFiles); + new ClassNameGenerator(SampleTarget.class), this.generatedFiles); GenerationContext anotherContext = context.withName("Another"); GeneratedClass generatedClass = anotherContext.getGeneratedClasses() .addForFeature("Test", typeSpecCustomizer); @@ -119,9 +117,9 @@ class DefaultGenerationContextTests { } @Test - void withNameKeepsTrackOfAllGeneratedFiles() throws IOException { + void withNameKeepsTrackOfAllGeneratedFiles() { DefaultGenerationContext context = new DefaultGenerationContext( - new ClassNameGenerator(TestTarget.class), this.generatedFiles); + new ClassNameGenerator(SampleTarget.class), this.generatedFiles); context.getGeneratedClasses().addForFeature("Test", typeSpecCustomizer); GenerationContext anotherContext = context.withName("Another"); assertThat(anotherContext.getGeneratedClasses()).isNotSameAs(context.getGeneratedClasses()); @@ -133,7 +131,7 @@ class DefaultGenerationContextTests { } @Test - void withNameGeneratesUniqueName() throws IOException { + void withNameGeneratesUniqueName() { DefaultGenerationContext context = new DefaultGenerationContext( new ClassNameGenerator(Object.class), this.generatedFiles); context.withName("Test").getGeneratedClasses() @@ -149,4 +147,6 @@ class DefaultGenerationContextTests { "java/lang/Object__Test2Feature.java"); } + static class SampleTarget {} + } diff --git a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/aot/generate/TestGenerationContext.java b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/aot/generate/TestGenerationContext.java deleted file mode 100644 index 65e62ab6cf..0000000000 --- a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/aot/generate/TestGenerationContext.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * 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.core.testfixture.aot.generate; - -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} and provides a convenient - * {@link TestTarget} by default. - * - * @author Stephane Nicoll - * @author Sam Brannen - * @since 6.0 - */ -public class TestGenerationContext extends DefaultGenerationContext { - - /** - * Create an instance using {@link TestTarget} as the default target class. - */ - public TestGenerationContext() { - this(new ClassNameGenerator(TestTarget.class)); - } - - /** - * Create an instance using the specified {@link ClassNameGenerator}. - * @param classNameGenerator the class name generator to use - */ - public TestGenerationContext(ClassNameGenerator classNameGenerator) { - super(classNameGenerator, new InMemoryGeneratedFiles()); - } - - - @Override - public InMemoryGeneratedFiles getGeneratedFiles() { - return (InMemoryGeneratedFiles) super.getGeneratedFiles(); - } - -} diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypesBeanRegistrationAotProcessorTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypesBeanRegistrationAotProcessorTests.java index 9af72e5e8e..563407995f 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypesBeanRegistrationAotProcessorTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypesBeanRegistrationAotProcessorTests.java @@ -22,6 +22,7 @@ import javax.sql.DataSource; import org.junit.jupiter.api.Test; +import org.springframework.aot.test.generate.TestGenerationContext; import org.springframework.aot.test.generator.compile.Compiled; import org.springframework.aot.test.generator.compile.TestCompiler; import org.springframework.context.ApplicationContextInitializer; @@ -31,7 +32,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.aot.ApplicationContextAotGenerator; import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.io.ResourceLoader; -import org.springframework.core.testfixture.aot.generate.TestGenerationContext; import org.springframework.orm.jpa.JpaVendorAdapter; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.domain.DriversLicense; diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessorAotContributionTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessorAotContributionTests.java index a1af961299..12d180de65 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessorAotContributionTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessorAotContributionTests.java @@ -34,6 +34,7 @@ import org.junit.jupiter.api.Test; import org.springframework.aot.hint.FieldMode; import org.springframework.aot.hint.TypeReference; +import org.springframework.aot.test.generate.TestGenerationContext; import org.springframework.aot.test.generator.compile.CompileWithTargetClassAccess; import org.springframework.aot.test.generator.compile.Compiled; import org.springframework.aot.test.generator.compile.TestCompiler; @@ -42,7 +43,6 @@ import org.springframework.beans.factory.aot.BeanRegistrationCode; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.core.testfixture.aot.generate.TestGenerationContext; import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-tx/spring-tx.gradle b/spring-tx/spring-tx.gradle index 75d1b22a94..17c9ce146a 100644 --- a/spring-tx/spring-tx.gradle +++ b/spring-tx/spring-tx.gradle @@ -17,6 +17,7 @@ dependencies { optional("org.jetbrains.kotlin:kotlin-stdlib") optional("org.jetbrains.kotlinx:kotlinx-coroutines-core") optional("org.jetbrains.kotlinx:kotlinx-coroutines-reactor") + testImplementation(project(":spring-core-test")) testImplementation(testFixtures(project(":spring-beans"))) testImplementation(testFixtures(project(":spring-context"))) testImplementation(testFixtures(project(":spring-core"))) diff --git a/spring-tx/src/test/java/org/springframework/transaction/annotation/TransactionBeanRegistrationAotProcessorTests.java b/spring-tx/src/test/java/org/springframework/transaction/annotation/TransactionBeanRegistrationAotProcessorTests.java index 94ca524f6b..12df9f4bc3 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/annotation/TransactionBeanRegistrationAotProcessorTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/annotation/TransactionBeanRegistrationAotProcessorTests.java @@ -21,12 +21,12 @@ import org.junit.jupiter.api.Test; import org.springframework.aot.generate.GenerationContext; import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.predicate.RuntimeHintsPredicates; +import org.springframework.aot.test.generate.TestGenerationContext; import org.springframework.beans.factory.aot.BeanRegistrationAotContribution; import org.springframework.beans.factory.aot.BeanRegistrationCode; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.core.testfixture.aot.generate.TestGenerationContext; import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat;