Browse Source

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
pull/29085/head
Stephane Nicoll 3 years ago
parent
commit
58b0251af1
  1. 2
      spring-aop/src/test/java/org/springframework/aop/scope/ScopedProxyBeanRegistrationAotProcessorTests.java
  2. 2
      spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanRegistrationAotContributionTests.java
  3. 2
      spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorTests.java
  4. 2
      spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGeneratorTests.java
  5. 2
      spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertyValueCodeGeneratorTests.java
  6. 4
      spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanRegistrationsAotContributionTests.java
  7. 2
      spring-beans/src/test/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragmentsTests.java
  8. 2
      spring-beans/src/test/java/org/springframework/beans/factory/aot/InstanceSupplierCodeGeneratorTests.java
  9. 2
      spring-context/spring-context.gradle
  10. 2
      spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorAotContributionTests.java
  11. 2
      spring-context/src/test/java/org/springframework/context/aot/ApplicationContextAotGeneratorTests.java
  12. 2
      spring-context/src/test/java/org/springframework/context/aot/GeneratedClassHandlerTests.java
  13. 2
      spring-context/src/test/java/org/springframework/context/aot/ReflectiveProcessorBeanFactoryInitializationAotProcessorTests.java
  14. 2
      spring-context/src/test/java/org/springframework/context/aot/RuntimeHintsBeanFactoryInitializationAotProcessorTests.java
  15. 2
      spring-context/src/test/java/org/springframework/context/generator/ApplicationContextAotGeneratorRuntimeHintsTests.java
  16. 17
      spring-core-test/src/main/java/org/springframework/aot/test/generate/TestGenerationContext.java
  17. 2
      spring-core-test/src/main/java/org/springframework/aot/test/generate/TestTarget.java
  18. 2
      spring-core-test/src/main/java/org/springframework/aot/test/generate/package-info.java
  19. 16
      spring-core/src/test/java/org/springframework/aot/generate/DefaultGenerationContextTests.java
  20. 56
      spring-core/src/testFixtures/java/org/springframework/core/testfixture/aot/generate/TestGenerationContext.java
  21. 2
      spring-orm/src/test/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypesBeanRegistrationAotProcessorTests.java
  22. 2
      spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessorAotContributionTests.java
  23. 1
      spring-tx/spring-tx.gradle
  24. 2
      spring-tx/src/test/java/org/springframework/transaction/annotation/TransactionBeanRegistrationAotProcessorTests.java

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

@ -26,6 +26,7 @@ import org.junit.jupiter.api.Test; @@ -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; @@ -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;

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

@ -25,6 +25,7 @@ import org.junit.jupiter.api.Test; @@ -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; @@ -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;

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

@ -30,6 +30,7 @@ import org.junit.jupiter.api.Test; @@ -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; @@ -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;

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

@ -29,6 +29,7 @@ import org.junit.jupiter.api.Test; @@ -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; @@ -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;

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

@ -34,6 +34,7 @@ import org.junit.jupiter.api.Nested; @@ -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; @@ -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;

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

@ -31,6 +31,8 @@ import org.junit.jupiter.api.Test; @@ -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; @@ -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;

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

@ -20,6 +20,7 @@ import java.lang.reflect.Method; @@ -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; @@ -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;

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

@ -30,6 +30,7 @@ import org.springframework.aot.hint.ExecutableHint; @@ -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 @@ -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;

2
spring-context/spring-context.gradle

@ -26,10 +26,10 @@ dependencies { @@ -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")

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

@ -28,6 +28,7 @@ import org.junit.jupiter.api.Test; @@ -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; @@ -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;

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

@ -31,6 +31,7 @@ import org.springframework.aot.hint.MemberCategory; @@ -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 @@ -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;

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

@ -26,8 +26,8 @@ import org.springframework.aot.generate.InMemoryGeneratedFiles; @@ -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;

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

@ -24,13 +24,13 @@ import org.springframework.aot.generate.GenerationContext; @@ -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;

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

@ -29,6 +29,7 @@ import org.springframework.aot.generate.GenerationContext; @@ -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; @@ -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;

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

@ -27,6 +27,7 @@ import org.springframework.aot.hint.TypeReference; @@ -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; @@ -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;

17
spring-test/src/main/java/org/springframework/test/aot/generate/TestGenerationContext.java → spring-core-test/src/main/java/org/springframework/aot/test/generate/TestGenerationContext.java

@ -14,7 +14,7 @@ @@ -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; @@ -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 { @@ -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);
}

2
spring-core/src/testFixtures/java/org/springframework/core/testfixture/aot/generate/TestTarget.java → spring-core-test/src/main/java/org/springframework/aot/test/generate/TestTarget.java

@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.core.testfixture.aot.generate;
package org.springframework.aot.test.generate;
/**
* A <em>default target class</em> used by tests of code generation.

2
spring-test/src/main/java/org/springframework/test/aot/generate/package-info.java → spring-core-test/src/main/java/org/springframework/aot/test/generate/package-info.java

@ -3,7 +3,7 @@ @@ -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;

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

@ -16,14 +16,12 @@ @@ -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 { @@ -40,7 +38,7 @@ class DefaultGenerationContextTests {
private static final Consumer<TypeSpec.Builder> 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 { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -149,4 +147,6 @@ class DefaultGenerationContextTests {
"java/lang/Object__Test2Feature.java");
}
static class SampleTarget {}
}

56
spring-core/src/testFixtures/java/org/springframework/core/testfixture/aot/generate/TestGenerationContext.java

@ -1,56 +0,0 @@ @@ -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();
}
}

2
spring-orm/src/test/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypesBeanRegistrationAotProcessorTests.java

@ -22,6 +22,7 @@ import javax.sql.DataSource; @@ -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; @@ -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;

2
spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessorAotContributionTests.java

@ -34,6 +34,7 @@ import org.junit.jupiter.api.Test; @@ -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; @@ -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;

1
spring-tx/spring-tx.gradle

@ -17,6 +17,7 @@ dependencies { @@ -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")))

2
spring-tx/src/test/java/org/springframework/transaction/annotation/TransactionBeanRegistrationAotProcessorTests.java

@ -21,12 +21,12 @@ import org.junit.jupiter.api.Test; @@ -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;

Loading…
Cancel
Save