mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Explicitly close ApplicationContexts and clean up warnings in tests
This commit is contained in:
+5
-8
@@ -672,14 +672,11 @@ class ConfigurationClassProcessingTests {
|
||||
|
||||
@Bean
|
||||
@Scope(value = "prototype")
|
||||
public PrototypeInterface getDemoBean( int i) {
|
||||
switch ( i) {
|
||||
case 1: return new PrototypeOne();
|
||||
case 2:
|
||||
default:
|
||||
return new PrototypeTwo();
|
||||
|
||||
}
|
||||
public PrototypeInterface getDemoBean(int i) {
|
||||
return switch (i) {
|
||||
case 1 -> new PrototypeOne();
|
||||
default -> new PrototypeTwo();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -211,6 +211,7 @@ class ApplicationContextAotGeneratorTests {
|
||||
GeneratedTypeContext generationContext = createGenerationContext();
|
||||
GenericApplicationContext applicationContext = new GenericApplicationContext();
|
||||
DefaultListableBeanFactory beanFactory = applicationContext.getDefaultListableBeanFactory();
|
||||
@SuppressWarnings("unchecked")
|
||||
BiPredicate<String, BeanDefinition> excludeFilter = mock(BiPredicate.class);
|
||||
given(excludeFilter.test(eq("bean1"), any(BeanDefinition.class))).willReturn(Boolean.FALSE);
|
||||
given(excludeFilter.test(eq("bean2"), any(BeanDefinition.class))).willReturn(Boolean.TRUE);
|
||||
@@ -328,12 +329,11 @@ class ApplicationContextAotGeneratorTests {
|
||||
}
|
||||
|
||||
static class TestBeanFactoryContribution implements BeanFactoryContribution {
|
||||
|
||||
private final Consumer<BeanFactoryInitialization> contribution;
|
||||
|
||||
private final BiPredicate<String, BeanDefinition> excludeFilter;
|
||||
|
||||
private int order;
|
||||
|
||||
public TestBeanFactoryContribution(Consumer<BeanFactoryInitialization> contribution,
|
||||
BiPredicate<String, BeanDefinition> excludeFilter) {
|
||||
this.contribution = contribution;
|
||||
|
||||
+13
-2
@@ -241,6 +241,7 @@ class GenericApplicationContextTests {
|
||||
assertThat(context.isActive()).isFalse();
|
||||
context.refreshForAotProcessing();
|
||||
assertThat(context.isActive()).isTrue();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -250,6 +251,7 @@ class GenericApplicationContextTests {
|
||||
context.setEnvironment(environment);
|
||||
context.refreshForAotProcessing();
|
||||
assertThat(context.getBean(Environment.class)).isEqualTo(environment);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -258,6 +260,7 @@ class GenericApplicationContextTests {
|
||||
context.registerBeanDefinition("number", new RootBeanDefinition("java.lang.Integer"));
|
||||
context.refreshForAotProcessing();
|
||||
assertThat(getBeanDefinition(context, "number").getBeanClass()).isEqualTo(Integer.class);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -274,7 +277,7 @@ class GenericApplicationContextTests {
|
||||
.getIndexedArgumentValue(0, GenericBeanDefinition.class).getValue();
|
||||
assertThat(value.hasBeanClass()).isTrue();
|
||||
assertThat(value.getBeanClass()).isEqualTo(Integer.class);
|
||||
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -290,6 +293,7 @@ class GenericApplicationContextTests {
|
||||
GenericBeanDefinition value = (GenericBeanDefinition) bd.getPropertyValues().get("inner");
|
||||
assertThat(value.hasBeanClass()).isTrue();
|
||||
assertThat(value.getBeanClass()).isEqualTo(Integer.class);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -299,6 +303,7 @@ class GenericApplicationContextTests {
|
||||
context.addBeanFactoryPostProcessor(bfpp);
|
||||
context.refreshForAotProcessing();
|
||||
verify(bfpp).postProcessBeanFactory(context.getBeanFactory());
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -310,6 +315,7 @@ class GenericApplicationContextTests {
|
||||
context.refreshForAotProcessing();
|
||||
verify(bpp).postProcessMergedBeanDefinition(getBeanDefinition(context, "test"), String.class, "test");
|
||||
verify(bpp).postProcessMergedBeanDefinition(getBeanDefinition(context, "number"), Integer.class, "number");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -326,6 +332,7 @@ class GenericApplicationContextTests {
|
||||
verify(bpp).postProcessMergedBeanDefinition(getBeanDefinition(context, "test"), BeanD.class, "test");
|
||||
verify(bpp).postProcessMergedBeanDefinition(any(RootBeanDefinition.class), eq(Integer.class), captor.capture());
|
||||
assertThat(captor.getValue()).startsWith("(inner bean)");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -342,6 +349,7 @@ class GenericApplicationContextTests {
|
||||
verify(bpp).postProcessMergedBeanDefinition(getBeanDefinition(context, "test"), BeanD.class, "test");
|
||||
verify(bpp).postProcessMergedBeanDefinition(any(RootBeanDefinition.class), eq(Integer.class), captor.capture());
|
||||
assertThat(captor.getValue()).startsWith("(inner bean)");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -350,6 +358,7 @@ class GenericApplicationContextTests {
|
||||
context.refresh();
|
||||
assertThatIllegalStateException().isThrownBy(context::refreshForAotProcessing)
|
||||
.withMessageContaining("does not support multiple refresh attempts");
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -358,6 +367,7 @@ class GenericApplicationContextTests {
|
||||
context.registerBeanDefinition("genericFactoryBean",
|
||||
new RootBeanDefinition(TestAotFactoryBean.class));
|
||||
context.refreshForAotProcessing();
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -367,6 +377,7 @@ class GenericApplicationContextTests {
|
||||
throw new IllegalStateException("Should not be invoked");
|
||||
}).getBeanDefinition());
|
||||
context.refreshForAotProcessing();
|
||||
context.close();
|
||||
}
|
||||
|
||||
private MergedBeanDefinitionPostProcessor registerMockMergedBeanDefinitionPostProcessor(GenericApplicationContext context) {
|
||||
@@ -377,7 +388,6 @@ class GenericApplicationContextTests {
|
||||
return bpp;
|
||||
}
|
||||
|
||||
|
||||
private RootBeanDefinition getBeanDefinition(GenericApplicationContext context, String name) {
|
||||
return (RootBeanDefinition) context.getBeanFactory().getMergedBeanDefinition(name);
|
||||
}
|
||||
@@ -411,6 +421,7 @@ class GenericApplicationContextTests {
|
||||
|
||||
static class BeanD {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private Integer counter;
|
||||
|
||||
BeanD(Integer counter) {
|
||||
|
||||
@@ -61,7 +61,7 @@ class Spr7816Tests {
|
||||
|
||||
}
|
||||
|
||||
abstract static class DomainEntity {
|
||||
abstract static sealed class DomainEntity permits Building, Entrance, Dwelling {
|
||||
}
|
||||
|
||||
static final class Building extends DomainEntity {
|
||||
|
||||
Reference in New Issue
Block a user