Skip to content

Commit 4625e92

Browse files
committed
Break dependency between TestCompiler and AOT
This commit improves `TestCompiler` with a `with` function that allows to customize a test compiler instance. Rather than `TestCompiler` knowing about `TestGenerationContext`, the latter implements the function so that it can be passed as is. See spring-projectsgh-29175
1 parent 2f84096 commit 4625e92

File tree

17 files changed

+108
-37
lines changed

17 files changed

+108
-37
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
@@ -151,7 +151,7 @@ private void compile(BiConsumer<DefaultListableBeanFactory, Compiled> result) {
151151
.build());
152152
});
153153
this.generationContext.writeGeneratedContent();
154-
TestCompiler.forSystem().withFiles(this.generationContext.getGeneratedFiles()).compile(compiled -> {
154+
TestCompiler.forSystem().with(this.generationContext).compile(compiled -> {
155155
DefaultListableBeanFactory freshBeanFactory = new DefaultListableBeanFactory();
156156
freshBeanFactory.setBeanClassLoader(compiled.getClassLoader());
157157
compiled.getInstance(Consumer.class).accept(freshBeanFactory);

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
@@ -176,7 +176,7 @@ private void compile(RegisteredBean registeredBean,
176176

177177
});
178178
this.generationContext.writeGeneratedContent();
179-
TestCompiler.forSystem().withFiles(this.generationContext.getGeneratedFiles()).compile(compiled ->
179+
TestCompiler.forSystem().with(this.generationContext).compile(compiled ->
180180
result.accept(compiled.getInstance(BiFunction.class), compiled));
181181
}
182182

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
@@ -425,7 +425,7 @@ private void compile(MethodReference method,
425425
.addCode("return $L;", methodInvocation).build());
426426
});
427427
this.generationContext.writeGeneratedContent();
428-
TestCompiler.forSystem().withFiles(this.generationContext.getGeneratedFiles()).compile(compiled ->
428+
TestCompiler.forSystem().with(this.generationContext).compile(compiled ->
429429
result.accept((RootBeanDefinition) compiled.getInstance(Supplier.class).get(), compiled));
430430
}
431431

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
@@ -429,7 +429,7 @@ private void compile(
429429
.addStatement("return beanDefinition").build());
430430
});
431431
this.generationContext.writeGeneratedContent();
432-
TestCompiler.forSystem().withFiles(this.generationContext.getGeneratedFiles()).compile(compiled -> {
432+
TestCompiler.forSystem().with(this.generationContext).compile(compiled -> {
433433
RootBeanDefinition suppliedBeanDefinition = (RootBeanDefinition) compiled
434434
.getInstance(Supplier.class).get();
435435
result.accept(suppliedBeanDefinition, compiled);

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
@@ -76,7 +76,7 @@ private void compile(Object value, BiConsumer<Object, Compiled> result) {
7676
.returns(Object.class).addStatement("return $L", generatedCode).build());
7777
});
7878
generationContext.writeGeneratedContent();
79-
TestCompiler.forSystem().withFiles(generationContext.getGeneratedFiles()).compile(compiled ->
79+
TestCompiler.forSystem().with(generationContext).compile(compiled ->
8080
result.accept(compiled.getInstance(Supplier.class).get(), compiled));
8181
}
8282

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private void compile(
167167
.build());
168168
});
169169
this.generationContext.writeGeneratedContent();
170-
TestCompiler.forSystem().withFiles(this.generationContext.getGeneratedFiles()).compile(compiled ->
170+
TestCompiler.forSystem().with(this.generationContext).compile(compiled ->
171171
result.accept(compiled.getInstance(Consumer.class), compiled));
172172
}
173173

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
@@ -317,7 +317,7 @@ private void compile(DefaultListableBeanFactory beanFactory,
317317
.addStatement("return $L", generatedCode).build());
318318
});
319319
this.generationContext.writeGeneratedContent();
320-
TestCompiler.forSystem().withFiles(this.generationContext.getGeneratedFiles()).compile(compiled ->
320+
TestCompiler.forSystem().with(this.generationContext).compile(compiled ->
321321
result.accept((InstanceSupplier<?>) compiled.getInstance(Supplier.class).get(), compiled));
322322
}
323323

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private void compile(BiConsumer<Consumer<DefaultListableBeanFactory>, Compiled>
165165
.build());
166166
});
167167
generationContext.writeGeneratedContent();
168-
TestCompiler.forSystem().withFiles(generationContext.getGeneratedFiles()).compile(compiled ->
168+
TestCompiler.forSystem().with(generationContext).compile(compiled ->
169169
result.accept(compiled.getInstance(Consumer.class), compiled));
170170
}
171171

@@ -297,7 +297,7 @@ private void compile(BiConsumer<Consumer<GenericApplicationContext>, Compiled> r
297297
.build());
298298
});
299299
generationContext.writeGeneratedContent();
300-
TestCompiler.forSystem().withFiles(generationContext.getGeneratedFiles()).compile(compiled ->
300+
TestCompiler.forSystem().with(generationContext).compile(compiled ->
301301
result.accept(compiled.getInstance(Consumer.class), compiled));
302302
}
303303

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
@@ -315,7 +315,7 @@ private void testCompiledResult(GenericApplicationContext applicationContext,
315315
@SuppressWarnings({ "rawtypes", "unchecked" })
316316
private void testCompiledResult(TestGenerationContext generationContext,
317317
BiConsumer<ApplicationContextInitializer<GenericApplicationContext>, Compiled> result) {
318-
TestCompiler.forSystem().withFiles(generationContext.getGeneratedFiles()).compile(compiled ->
318+
TestCompiler.forSystem().with(generationContext).compile(compiled ->
319319
result.accept(compiled.getInstance(ApplicationContextInitializer.class), compiled));
320320
}
321321

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
@@ -86,7 +86,7 @@ private void compile(GenericApplicationContext applicationContext, BiConsumer<Ru
8686
TestGenerationContext generationContext = new TestGenerationContext();
8787
generator.processAheadOfTime(applicationContext, generationContext);
8888
generationContext.writeGeneratedContent();
89-
TestCompiler.forSystem().withFiles(generationContext.getGeneratedFiles()).compile(compiled -> {
89+
TestCompiler.forSystem().with(generationContext).compile(compiled -> {
9090
ApplicationContextInitializer instance = compiled.getInstance(ApplicationContextInitializer.class);
9191
GenericApplicationContext freshContext = new GenericApplicationContext();
9292
RuntimeHintsInvocations recordedInvocations = RuntimeHintsRecorder.record(() -> {

0 commit comments

Comments
 (0)