Polish tests

This commit is contained in:
Stephane Nicoll
2022-06-07 12:03:50 +02:00
parent ad0573a91e
commit 92961d75f0
2 changed files with 22 additions and 34 deletions

View File

@@ -103,8 +103,8 @@ class ScopedProxyBeanRegistrationAotProcessorTests {
this.beanFactory.registerBeanDefinition("test", beanDefinition);
testCompile((freshBeanFactory,
compiled) -> assertThatExceptionOfType(BeanCreationException.class)
.isThrownBy(() -> freshBeanFactory.getBean("test"))
.withMessageContaining("'targetBeanName' is required"));
.isThrownBy(() -> freshBeanFactory.getBean("test"))
.withMessageContaining("'targetBeanName' is required"));
}
@Test
@@ -116,8 +116,8 @@ class ScopedProxyBeanRegistrationAotProcessorTests {
this.beanFactory.registerBeanDefinition("test", beanDefinition);
testCompile((freshBeanFactory,
compiled) -> assertThatExceptionOfType(BeanCreationException.class)
.isThrownBy(() -> freshBeanFactory.getBean("test"))
.withMessageContaining("No bean named 'testDoesNotExist'"));
.isThrownBy(() -> freshBeanFactory.getBean("test"))
.withMessageContaining("No bean named 'testDoesNotExist'"));
}
@Test
@@ -144,19 +144,18 @@ class ScopedProxyBeanRegistrationAotProcessorTests {
assertThat(contribution).isNotNull();
contribution.applyTo(this.generationContext, this.beanFactoryInitializationCode);
this.generationContext.writeGeneratedContent();
TestCompiler.forSystem().withFiles(this.generatedFiles).printFiles(System.out)
.compile(compiled -> {
MethodReference reference = this.beanFactoryInitializationCode
.getInitializers().get(0);
Object instance = compiled.getInstance(Object.class,
reference.getDeclaringClass().toString());
Method method = ReflectionUtils.findMethod(instance.getClass(),
reference.getMethodName(), DefaultListableBeanFactory.class);
DefaultListableBeanFactory freshBeanFactory = new DefaultListableBeanFactory();
freshBeanFactory.setBeanClassLoader(compiled.getClassLoader());
ReflectionUtils.invokeMethod(method, instance, freshBeanFactory);
result.accept(freshBeanFactory, compiled);
});
TestCompiler.forSystem().withFiles(this.generatedFiles).compile(compiled -> {
MethodReference reference = this.beanFactoryInitializationCode
.getInitializers().get(0);
Object instance = compiled.getInstance(Object.class,
reference.getDeclaringClass().toString());
Method method = ReflectionUtils.findMethod(instance.getClass(),
reference.getMethodName(), DefaultListableBeanFactory.class);
DefaultListableBeanFactory freshBeanFactory = new DefaultListableBeanFactory();
freshBeanFactory.setBeanClassLoader(compiled.getClassLoader());
ReflectionUtils.invokeMethod(method, instance, freshBeanFactory);
result.accept(freshBeanFactory, compiled);
});
}