Explicitly close ApplicationContexts and clean up warnings in tests
This commit is contained in:
parent
7f4e09e994
commit
3da7a48a17
|
|
@ -148,6 +148,7 @@ class AutowiredAnnotationBeanInstantiationContributionTests {
|
|||
public static class PrivateFieldInjectionSample {
|
||||
|
||||
@Autowired
|
||||
@SuppressWarnings("unused")
|
||||
private Environment environment;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -714,8 +714,10 @@ class BeanRegistrationBeanFactoryContributionTests {
|
|||
|
||||
static class NameAndCountersComponent {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String name;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private List<Integer> counters;
|
||||
|
||||
public void setName(String name) {
|
||||
|
|
|
|||
|
|
@ -362,8 +362,10 @@ class BeanDefinitionRegistrarTests {
|
|||
|
||||
static class MultiArgConstructorSample {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final String name;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final Integer counter;
|
||||
|
||||
public MultiArgConstructorSample(String name, Integer counter) {
|
||||
|
|
@ -377,8 +379,10 @@ class BeanDefinitionRegistrarTests {
|
|||
|
||||
private Environment environment;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String name;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private Integer counter;
|
||||
|
||||
void setEnvironment(Environment environment) {
|
||||
|
|
@ -439,6 +443,7 @@ class BeanDefinitionRegistrarTests {
|
|||
|
||||
static class NumberHolder<N extends Number> {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final N number;
|
||||
|
||||
public NumberHolder(N number) {
|
||||
|
|
@ -450,6 +455,7 @@ class BeanDefinitionRegistrarTests {
|
|||
static class NumberHolderSample {
|
||||
|
||||
@Autowired
|
||||
@SuppressWarnings("unused")
|
||||
private NumberHolder<Integer> numberHolder;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ class InjectedFieldResolverTests {
|
|||
|
||||
static class TestBean {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String string;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import java.io.Serializable;
|
|||
@SuppressWarnings("serial")
|
||||
public class NumberHolder<T extends Number> implements Serializable {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final T number;
|
||||
|
||||
public NumberHolder(T number) {
|
||||
|
|
|
|||
|
|
@ -18,8 +18,10 @@ package org.springframework.beans.testfixture.beans.factory.generator.property;
|
|||
|
||||
public class ConfigurableBean {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String name;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private Integer counter;
|
||||
|
||||
public void setName(String name) {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -29,10 +29,8 @@ import io.r2dbc.spi.test.MockRow;
|
|||
import io.r2dbc.spi.test.MockRowMetadata;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
import org.reactivestreams.Publisher;
|
||||
|
|
@ -66,12 +64,11 @@ import static org.mockito.BDDMockito.when;
|
|||
* @author Ferdinand Jacobs
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class DefaultDatabaseClientUnitTests {
|
||||
|
||||
@Mock
|
||||
Connection connection;
|
||||
private Connection connection;
|
||||
|
||||
private DatabaseClient.Builder databaseClientBuilder;
|
||||
|
||||
|
|
@ -147,6 +144,7 @@ class DefaultDatabaseClientUnitTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void executeShouldBindSettableValues() {
|
||||
Statement statement = mockStatementFor("SELECT * FROM table WHERE key = $1");
|
||||
|
||||
|
|
@ -197,6 +195,7 @@ class DefaultDatabaseClientUnitTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void executeShouldBindValues() {
|
||||
Statement statement = mockStatementFor("SELECT * FROM table WHERE key = $1");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue