See gh-20226
This commit is contained in:
Johnny Lim
2020-02-19 11:16:46 +09:00
committed by Stephane Nicoll
parent 0c76c0acb9
commit 8be8a8421d
17 changed files with 39 additions and 55 deletions

View File

@@ -79,8 +79,7 @@ class CassandraDataAutoConfigurationTests {
void userTypeResolverShouldBeSet() {
load();
CassandraMappingContext mappingContext = this.context.getBean(CassandraMappingContext.class);
assertThat(ReflectionTestUtils.getField(mappingContext, "userTypeResolver"))
.isInstanceOf(SimpleUserTypeResolver.class);
assertThat(mappingContext).extracting("userTypeResolver").isInstanceOf(SimpleUserTypeResolver.class);
}
@Test

View File

@@ -75,8 +75,7 @@ class CassandraReactiveDataAutoConfigurationTests {
void userTypeResolverShouldBeSet() {
load("spring.data.cassandra.keyspaceName:boot_test");
CassandraMappingContext mappingContext = this.context.getBean(CassandraMappingContext.class);
assertThat(ReflectionTestUtils.getField(mappingContext, "userTypeResolver"))
.isInstanceOf(SimpleUserTypeResolver.class);
assertThat(mappingContext).extracting("userTypeResolver").isInstanceOf(SimpleUserTypeResolver.class);
}
private void load(String... environment) {

View File

@@ -389,7 +389,7 @@ class KafkaAutoConfigurationTests {
assertThat(containerProperties.getMonitorInterval()).isEqualTo(45);
assertThat(containerProperties.isLogContainerConfig()).isTrue();
assertThat(containerProperties.isMissingTopicsFatal()).isFalse();
assertThat(ReflectionTestUtils.getField(kafkaListenerContainerFactory, "concurrency")).isEqualTo(3);
assertThat(kafkaListenerContainerFactory).extracting("concurrency").isEqualTo(3);
assertThat(kafkaListenerContainerFactory.isBatchListener()).isTrue();
assertThat(context.getBeansOfType(KafkaJaasLoginModuleInitializer.class)).hasSize(1);
KafkaJaasLoginModuleInitializer jaas = context.getBean(KafkaJaasLoginModuleInitializer.class);

View File

@@ -41,7 +41,6 @@ import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -92,8 +91,7 @@ class TaskExecutionAutoConfigurationTests {
this.contextRunner.withUserConfiguration(TaskDecoratorConfig.class).run((context) -> {
assertThat(context).hasSingleBean(TaskExecutorBuilder.class);
ThreadPoolTaskExecutor executor = context.getBean(TaskExecutorBuilder.class).build();
assertThat(ReflectionTestUtils.getField(executor, "taskDecorator"))
.isSameAs(context.getBean(TaskDecorator.class));
assertThat(executor).extracting("taskDecorator").isSameAs(context.getBean(TaskDecorator.class));
});
}

View File

@@ -380,16 +380,15 @@ class WebMvcAutoConfigurationTests {
@Test
void defaultAsyncRequestTimeout() {
this.contextRunner.run((context) -> assertThat(ReflectionTestUtils
.getField(context.getBean(RequestMappingHandlerAdapter.class), "asyncRequestTimeout")).isNull());
this.contextRunner.run((context) -> assertThat(context.getBean(RequestMappingHandlerAdapter.class))
.extracting("asyncRequestTimeout").isNull());
}
@Test
void customAsyncRequestTimeout() {
this.contextRunner.withPropertyValues("spring.mvc.async.request-timeout:12345")
.run((context) -> assertThat(ReflectionTestUtils
.getField(context.getBean(RequestMappingHandlerAdapter.class), "asyncRequestTimeout"))
.isEqualTo(12345L));
.run((context) -> assertThat(context.getBean(RequestMappingHandlerAdapter.class))
.extracting("asyncRequestTimeout").isEqualTo(12345L));
}
@Test
@@ -397,8 +396,8 @@ class WebMvcAutoConfigurationTests {
this.contextRunner.withConfiguration(AutoConfigurations.of(TaskExecutionAutoConfiguration.class))
.run((context) -> {
assertThat(context).hasSingleBean(AsyncTaskExecutor.class);
assertThat(ReflectionTestUtils.getField(context.getBean(RequestMappingHandlerAdapter.class),
"taskExecutor")).isSameAs(context.getBean("applicationTaskExecutor"));
assertThat(context.getBean(RequestMappingHandlerAdapter.class)).extracting("taskExecutor")
.isSameAs(context.getBean("applicationTaskExecutor"));
});
}
@@ -407,8 +406,8 @@ class WebMvcAutoConfigurationTests {
this.contextRunner.withUserConfiguration(CustomApplicationTaskExecutorConfig.class)
.withConfiguration(AutoConfigurations.of(TaskExecutionAutoConfiguration.class)).run((context) -> {
assertThat(context).doesNotHaveBean(AsyncTaskExecutor.class);
assertThat(ReflectionTestUtils.getField(context.getBean(RequestMappingHandlerAdapter.class),
"taskExecutor")).isNotSameAs(context.getBean("applicationTaskExecutor"));
assertThat(context.getBean(RequestMappingHandlerAdapter.class)).extracting("taskExecutor")
.isNotSameAs(context.getBean("applicationTaskExecutor"));
});
}
@@ -416,9 +415,9 @@ class WebMvcAutoConfigurationTests {
void asyncTaskExecutorWithMvcConfigurerCanOverrideExecutor() {
this.contextRunner.withUserConfiguration(CustomAsyncTaskExecutorConfigurer.class)
.withConfiguration(AutoConfigurations.of(TaskExecutionAutoConfiguration.class))
.run((context) -> assertThat(ReflectionTestUtils
.getField(context.getBean(RequestMappingHandlerAdapter.class), "taskExecutor"))
.isSameAs(context.getBean(CustomAsyncTaskExecutorConfigurer.class).taskExecutor));
.run((context) -> assertThat(context.getBean(RequestMappingHandlerAdapter.class))
.extracting("taskExecutor")
.isSameAs(context.getBean(CustomAsyncTaskExecutorConfigurer.class).taskExecutor));
}
@Test
@@ -426,8 +425,8 @@ class WebMvcAutoConfigurationTests {
this.contextRunner.withUserConfiguration(CustomAsyncTaskExecutorConfig.class)
.withConfiguration(AutoConfigurations.of(TaskExecutionAutoConfiguration.class)).run((context) -> {
assertThat(context).hasSingleBean(AsyncTaskExecutor.class);
assertThat(ReflectionTestUtils.getField(context.getBean(RequestMappingHandlerAdapter.class),
"taskExecutor")).isNotSameAs(context.getBean("customTaskExecutor"));
assertThat(context.getBean(RequestMappingHandlerAdapter.class)).extracting("taskExecutor")
.isNotSameAs(context.getBean("customTaskExecutor"));
});
}
@@ -643,8 +642,7 @@ class WebMvcAutoConfigurationTests {
Validator validator = context.getBean(Validator.class);
assertThat(validator).isInstanceOf(ValidatorAdapter.class);
Validator target = ((ValidatorAdapter) validator).getTarget();
assertThat(ReflectionTestUtils.getField(target, "targetValidator"))
.isSameAs(context.getBean("customJsr303Validator"));
assertThat(target).extracting("targetValidator").isSameAs(context.getBean("customJsr303Validator"));
});
}

View File

@@ -25,7 +25,6 @@ import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition;
import org.springframework.xml.xsd.SimpleXsdSchema;
@@ -72,7 +71,7 @@ class WebServicesAutoConfigurationTests {
void customLoadOnStartup() {
this.contextRunner.withPropertyValues("spring.webservices.servlet.load-on-startup=1").run((context) -> {
ServletRegistrationBean<?> registrationBean = context.getBean(ServletRegistrationBean.class);
assertThat(ReflectionTestUtils.getField(registrationBean, "loadOnStartup")).isEqualTo(1);
assertThat(registrationBean).extracting("loadOnStartup").isEqualTo(1);
});
}