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
This commit is contained in:
@@ -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<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 {
|
||||
@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 {}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,26 +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;
|
||||
|
||||
/**
|
||||
* A <em>default target class</em> used by tests of code generation.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 6.0
|
||||
*/
|
||||
public class TestTarget {
|
||||
}
|
||||
Reference in New Issue
Block a user