Commit 17f04b8b authored by dreis2211's avatar dreis2211 Committed by Stephane Nicoll

Replace DirectFieldAccessor usages by hasFieldOrPropertyWithValue

Closes gh-15312
parent d28d9e7e
...@@ -18,7 +18,6 @@ package org.springframework.boot.actuate.autoconfigure.system; ...@@ -18,7 +18,6 @@ package org.springframework.boot.actuate.autoconfigure.system;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.health.HealthIndicatorAutoConfiguration;
import org.springframework.boot.actuate.health.ApplicationHealthIndicator; import org.springframework.boot.actuate.health.ApplicationHealthIndicator;
import org.springframework.boot.actuate.system.DiskSpaceHealthIndicator; import org.springframework.boot.actuate.system.DiskSpaceHealthIndicator;
...@@ -63,10 +62,9 @@ public class DiskSpaceHealthIndicatorAutoConfigurationTests { ...@@ -63,10 +62,9 @@ public class DiskSpaceHealthIndicatorAutoConfigurationTests {
.withPropertyValues("management.health.diskspace.threshold=20MB") .withPropertyValues("management.health.diskspace.threshold=20MB")
.run((context) -> { .run((context) -> {
assertThat(context).hasSingleBean(DiskSpaceHealthIndicator.class); assertThat(context).hasSingleBean(DiskSpaceHealthIndicator.class);
DirectFieldAccessor dfa = new DirectFieldAccessor( assertThat(context.getBean(DiskSpaceHealthIndicator.class))
context.getBean(DiskSpaceHealthIndicator.class)); .hasFieldOrPropertyWithValue("threshold",
assertThat(dfa.getPropertyValue("threshold")) DataSize.ofMegabytes(20));
.isEqualTo(DataSize.ofMegabytes(20));
}); });
} }
......
...@@ -22,7 +22,6 @@ import org.springframework.amqp.rabbit.config.DirectRabbitListenerContainerFacto ...@@ -22,7 +22,6 @@ import org.springframework.amqp.rabbit.config.DirectRabbitListenerContainerFacto
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer; import org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.beans.DirectFieldAccessor;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -237,24 +236,22 @@ public class RabbitPropertiesTests { ...@@ -237,24 +236,22 @@ public class RabbitPropertiesTests {
public void simpleContainerUseConsistentDefaultValues() { public void simpleContainerUseConsistentDefaultValues() {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
SimpleMessageListenerContainer container = factory.createListenerContainer(); SimpleMessageListenerContainer container = factory.createListenerContainer();
DirectFieldAccessor dfa = new DirectFieldAccessor(container);
RabbitProperties.SimpleContainer simple = this.properties.getListener() RabbitProperties.SimpleContainer simple = this.properties.getListener()
.getSimple(); .getSimple();
assertThat(simple.isAutoStartup()).isEqualTo(container.isAutoStartup()); assertThat(simple.isAutoStartup()).isEqualTo(container.isAutoStartup());
assertThat(simple.isMissingQueuesFatal()) assertThat(container).hasFieldOrPropertyWithValue("missingQueuesFatal",
.isEqualTo(dfa.getPropertyValue("missingQueuesFatal")); simple.isMissingQueuesFatal());
} }
@Test @Test
public void directContainerUseConsistentDefaultValues() { public void directContainerUseConsistentDefaultValues() {
DirectRabbitListenerContainerFactory factory = new DirectRabbitListenerContainerFactory(); DirectRabbitListenerContainerFactory factory = new DirectRabbitListenerContainerFactory();
DirectMessageListenerContainer container = factory.createListenerContainer(); DirectMessageListenerContainer container = factory.createListenerContainer();
DirectFieldAccessor dfa = new DirectFieldAccessor(container);
RabbitProperties.DirectContainer direct = this.properties.getListener() RabbitProperties.DirectContainer direct = this.properties.getListener()
.getDirect(); .getDirect();
assertThat(direct.isAutoStartup()).isEqualTo(container.isAutoStartup()); assertThat(direct.isAutoStartup()).isEqualTo(container.isAutoStartup());
assertThat(direct.isMissingQueuesFatal()) assertThat(container).hasFieldOrPropertyWithValue("missingQueuesFatal",
.isEqualTo(dfa.getPropertyValue("missingQueuesFatal")); direct.isMissingQueuesFatal());
} }
} }
...@@ -43,7 +43,6 @@ import org.infinispan.spring.provider.SpringEmbeddedCacheManager; ...@@ -43,7 +43,6 @@ import org.infinispan.spring.provider.SpringEmbeddedCacheManager;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
...@@ -69,8 +68,10 @@ import org.springframework.context.annotation.Configuration; ...@@ -69,8 +68,10 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager; import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
...@@ -284,8 +285,8 @@ public class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationT ...@@ -284,8 +285,8 @@ public class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationT
RedisCacheManager cacheManager = getCacheManager(context, RedisCacheManager cacheManager = getCacheManager(context,
RedisCacheManager.class); RedisCacheManager.class);
assertThat(cacheManager.getCacheNames()).isEmpty(); assertThat(cacheManager.getCacheNames()).isEmpty();
org.springframework.data.redis.cache.RedisCacheConfiguration redisCacheConfiguration = (org.springframework.data.redis.cache.RedisCacheConfiguration) new DirectFieldAccessor( RedisCacheConfiguration redisCacheConfiguration = getDefaultRedisCacheConfiguration(
cacheManager).getPropertyValue("defaultCacheConfig"); cacheManager);
assertThat(redisCacheConfiguration.getTtl()) assertThat(redisCacheConfiguration.getTtl())
.isEqualTo(java.time.Duration.ofSeconds(15)); .isEqualTo(java.time.Duration.ofSeconds(15));
assertThat(redisCacheConfiguration.getAllowCacheNullValues()) assertThat(redisCacheConfiguration.getAllowCacheNullValues())
...@@ -307,8 +308,8 @@ public class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationT ...@@ -307,8 +308,8 @@ public class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationT
RedisCacheManager cacheManager = getCacheManager(context, RedisCacheManager cacheManager = getCacheManager(context,
RedisCacheManager.class); RedisCacheManager.class);
assertThat(cacheManager.getCacheNames()).isEmpty(); assertThat(cacheManager.getCacheNames()).isEmpty();
org.springframework.data.redis.cache.RedisCacheConfiguration redisCacheConfiguration = (org.springframework.data.redis.cache.RedisCacheConfiguration) new DirectFieldAccessor( RedisCacheConfiguration redisCacheConfiguration = getDefaultRedisCacheConfiguration(
cacheManager).getPropertyValue("defaultCacheConfig"); cacheManager);
assertThat(redisCacheConfiguration.getTtl()) assertThat(redisCacheConfiguration.getTtl())
.isEqualTo(java.time.Duration.ofSeconds(30)); .isEqualTo(java.time.Duration.ofSeconds(30));
assertThat(redisCacheConfiguration.getKeyPrefixFor("")) assertThat(redisCacheConfiguration.getKeyPrefixFor(""))
...@@ -333,8 +334,8 @@ public class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationT ...@@ -333,8 +334,8 @@ public class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationT
RedisCacheManager cacheManager = getCacheManager(context, RedisCacheManager cacheManager = getCacheManager(context,
RedisCacheManager.class); RedisCacheManager.class);
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar"); assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
org.springframework.data.redis.cache.RedisCacheConfiguration redisCacheConfiguration = (org.springframework.data.redis.cache.RedisCacheConfiguration) new DirectFieldAccessor( RedisCacheConfiguration redisCacheConfiguration = getDefaultRedisCacheConfiguration(
cacheManager).getPropertyValue("defaultCacheConfig"); cacheManager);
assertThat(redisCacheConfiguration.getTtl()) assertThat(redisCacheConfiguration.getTtl())
.isEqualTo(java.time.Duration.ofMinutes(0)); .isEqualTo(java.time.Duration.ofMinutes(0));
assertThat(redisCacheConfiguration.getAllowCacheNullValues()) assertThat(redisCacheConfiguration.getAllowCacheNullValues())
...@@ -786,6 +787,12 @@ public class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationT ...@@ -786,6 +787,12 @@ public class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationT
.isEqualTo(1L); .isEqualTo(1L);
} }
private RedisCacheConfiguration getDefaultRedisCacheConfiguration(
RedisCacheManager cacheManager) {
return (RedisCacheConfiguration) ReflectionTestUtils.getField(cacheManager,
"defaultCacheConfig");
}
@Configuration @Configuration
static class EmptyConfiguration { static class EmptyConfiguration {
......
...@@ -21,7 +21,6 @@ import java.util.Locale; ...@@ -21,7 +21,6 @@ import java.util.Locale;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext; import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
...@@ -99,8 +98,8 @@ public class MessageSourceAutoConfigurationTests { ...@@ -99,8 +98,8 @@ public class MessageSourceAutoConfigurationTests {
private ContextConsumer<AssertableApplicationContext> assertCache(long expected) { private ContextConsumer<AssertableApplicationContext> assertCache(long expected) {
return (context) -> { return (context) -> {
assertThat(context).hasSingleBean(MessageSource.class); assertThat(context).hasSingleBean(MessageSource.class);
assertThat(new DirectFieldAccessor(context.getBean(MessageSource.class)) assertThat(context.getBean(MessageSource.class))
.getPropertyValue("cacheMillis")).isEqualTo(expected); .hasFieldOrPropertyWithValue("cacheMillis", expected);
}; };
} }
...@@ -138,9 +137,8 @@ public class MessageSourceAutoConfigurationTests { ...@@ -138,9 +137,8 @@ public class MessageSourceAutoConfigurationTests {
@Test @Test
public void testFallbackDefault() { public void testFallbackDefault() {
this.contextRunner.withPropertyValues("spring.messages.basename:test/messages") this.contextRunner.withPropertyValues("spring.messages.basename:test/messages")
.run((context) -> assertThat( .run((context) -> assertThat(context.getBean(MessageSource.class))
isFallbackToSystemLocale(context.getBean(MessageSource.class))) .hasFieldOrPropertyWithValue("fallbackToSystemLocale", true));
.isTrue());
} }
@Test @Test
...@@ -148,17 +146,15 @@ public class MessageSourceAutoConfigurationTests { ...@@ -148,17 +146,15 @@ public class MessageSourceAutoConfigurationTests {
this.contextRunner this.contextRunner
.withPropertyValues("spring.messages.basename:test/messages", .withPropertyValues("spring.messages.basename:test/messages",
"spring.messages.fallback-to-system-locale:false") "spring.messages.fallback-to-system-locale:false")
.run((context) -> assertThat( .run((context) -> assertThat(context.getBean(MessageSource.class))
isFallbackToSystemLocale(context.getBean(MessageSource.class))) .hasFieldOrPropertyWithValue("fallbackToSystemLocale", false));
.isFalse());
} }
@Test @Test
public void testFormatMessageDefault() { public void testFormatMessageDefault() {
this.contextRunner.withPropertyValues("spring.messages.basename:test/messages") this.contextRunner.withPropertyValues("spring.messages.basename:test/messages")
.run((context) -> assertThat( .run((context) -> assertThat(context.getBean(MessageSource.class))
isAlwaysUseMessageFormat(context.getBean(MessageSource.class))) .hasFieldOrPropertyWithValue("alwaysUseMessageFormat", false));
.isFalse());
} }
@Test @Test
...@@ -166,27 +162,15 @@ public class MessageSourceAutoConfigurationTests { ...@@ -166,27 +162,15 @@ public class MessageSourceAutoConfigurationTests {
this.contextRunner this.contextRunner
.withPropertyValues("spring.messages.basename:test/messages", .withPropertyValues("spring.messages.basename:test/messages",
"spring.messages.always-use-message-format:true") "spring.messages.always-use-message-format:true")
.run((context) -> assertThat( .run((context) -> assertThat(context.getBean(MessageSource.class))
isAlwaysUseMessageFormat(context.getBean(MessageSource.class))) .hasFieldOrPropertyWithValue("alwaysUseMessageFormat", true));
.isTrue());
}
private boolean isFallbackToSystemLocale(MessageSource messageSource) {
return (boolean) new DirectFieldAccessor(messageSource)
.getPropertyValue("fallbackToSystemLocale");
}
private boolean isAlwaysUseMessageFormat(MessageSource messageSource) {
return (boolean) new DirectFieldAccessor(messageSource)
.getPropertyValue("alwaysUseMessageFormat");
} }
@Test @Test
public void testUseCodeAsDefaultMessageDefault() { public void testUseCodeAsDefaultMessageDefault() {
this.contextRunner.withPropertyValues("spring.messages.basename:test/messages") this.contextRunner.withPropertyValues("spring.messages.basename:test/messages")
.run((context) -> assertThat( .run((context) -> assertThat(context.getBean(MessageSource.class))
isUseCodeAsDefaultMessage(context.getBean(MessageSource.class))) .hasFieldOrPropertyWithValue("useCodeAsDefaultMessage", false));
.isFalse());
} }
@Test @Test
...@@ -194,14 +178,8 @@ public class MessageSourceAutoConfigurationTests { ...@@ -194,14 +178,8 @@ public class MessageSourceAutoConfigurationTests {
this.contextRunner this.contextRunner
.withPropertyValues("spring.messages.basename:test/messages", .withPropertyValues("spring.messages.basename:test/messages",
"spring.messages.use-code-as-default-message:true") "spring.messages.use-code-as-default-message:true")
.run((context) -> assertThat( .run((context) -> assertThat(context.getBean(MessageSource.class))
isUseCodeAsDefaultMessage(context.getBean(MessageSource.class))) .hasFieldOrPropertyWithValue("useCodeAsDefaultMessage", true));
.isTrue());
}
private boolean isUseCodeAsDefaultMessage(MessageSource messageSource) {
return (boolean) new DirectFieldAccessor(messageSource)
.getPropertyValue("useCodeAsDefaultMessage");
} }
@Test @Test
......
...@@ -21,7 +21,6 @@ import java.util.List; ...@@ -21,7 +21,6 @@ import java.util.List;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.FatalBeanException; import org.springframework.beans.FatalBeanException;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoUniqueBeanDefinitionException; import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
...@@ -38,6 +37,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext ...@@ -38,6 +37,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -227,8 +227,8 @@ public class NoSuchBeanDefinitionFailureAnalyzerTests { ...@@ -227,8 +227,8 @@ public class NoSuchBeanDefinitionFailureAnalyzerTests {
private static void addExclusions(NoSuchBeanDefinitionFailureAnalyzer analyzer, private static void addExclusions(NoSuchBeanDefinitionFailureAnalyzer analyzer,
Class<?>... classes) { Class<?>... classes) {
ConditionEvaluationReport report = (ConditionEvaluationReport) new DirectFieldAccessor( ConditionEvaluationReport report = (ConditionEvaluationReport) ReflectionTestUtils
analyzer).getPropertyValue("report"); .getField(analyzer, "report");
List<String> exclusions = new ArrayList<>(report.getExclusions()); List<String> exclusions = new ArrayList<>(report.getExclusions());
for (Class<?> c : classes) { for (Class<?> c : classes) {
exclusions.add(c.getName()); exclusions.add(c.getName());
......
...@@ -24,13 +24,13 @@ import org.junit.Rule; ...@@ -24,13 +24,13 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import retrofit2.Retrofit; import retrofit2.Retrofit;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext; import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.test.rule.OutputCapture; import org.springframework.boot.test.rule.OutputCapture;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -118,10 +118,8 @@ public class InfluxDbAutoConfigurationTests { ...@@ -118,10 +118,8 @@ public class InfluxDbAutoConfigurationTests {
private int getReadTimeoutProperty(AssertableApplicationContext context) { private int getReadTimeoutProperty(AssertableApplicationContext context) {
InfluxDB influxDB = context.getBean(InfluxDB.class); InfluxDB influxDB = context.getBean(InfluxDB.class);
Retrofit retrofit = (Retrofit) new DirectFieldAccessor(influxDB) Retrofit retrofit = (Retrofit) ReflectionTestUtils.getField(influxDB, "retrofit");
.getPropertyValue("retrofit"); OkHttpClient callFactory = (OkHttpClient) retrofit.callFactory();
OkHttpClient callFactory = (OkHttpClient) new DirectFieldAccessor(retrofit)
.getPropertyValue("callFactory");
return callFactory.readTimeoutMillis(); return callFactory.readTimeoutMillis();
} }
......
...@@ -20,7 +20,6 @@ import javax.management.MBeanServer; ...@@ -20,7 +20,6 @@ import javax.management.MBeanServer;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration.IntegrationComponentScanConfiguration; import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration.IntegrationComponentScanConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
...@@ -213,8 +212,8 @@ public class IntegrationAutoConfigurationTests { ...@@ -213,8 +212,8 @@ public class IntegrationAutoConfigurationTests {
this.contextRunner.withUserConfiguration(MessageSourceConfiguration.class) this.contextRunner.withUserConfiguration(MessageSourceConfiguration.class)
.run((context) -> { .run((context) -> {
assertThat(context).hasBean("myMessageSource"); assertThat(context).hasBean("myMessageSource");
assertThat(new DirectFieldAccessor(context.getBean("myMessageSource")) assertThat(((MessageProcessorMessageSource) context
.getPropertyValue("countsEnabled")).isEqualTo(true); .getBean("myMessageSource")).isCountsEnabled()).isTrue();
}); });
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -27,13 +27,13 @@ import org.junit.After; ...@@ -27,13 +27,13 @@ import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.autoconfigure.jndi.JndiPropertiesHidingClassLoader; import org.springframework.boot.autoconfigure.jndi.JndiPropertiesHidingClassLoader;
import org.springframework.boot.autoconfigure.jndi.TestableInitialContextFactory; import org.springframework.boot.autoconfigure.jndi.TestableInitialContextFactory;
import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.jmx.export.MBeanExporter; import org.springframework.jmx.export.MBeanExporter;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -110,8 +110,8 @@ public class JndiDataSourceAutoConfigurationTests { ...@@ -110,8 +110,8 @@ public class JndiDataSourceAutoConfigurationTests {
assertThat(this.context.getBean(DataSource.class)).isEqualTo(dataSource); assertThat(this.context.getBean(DataSource.class)).isEqualTo(dataSource);
MBeanExporter exporter = this.context.getBean(MBeanExporter.class); MBeanExporter exporter = this.context.getBean(MBeanExporter.class);
Set<String> excludedBeans = (Set<String>) new DirectFieldAccessor(exporter) Set<String> excludedBeans = (Set<String>) ReflectionTestUtils.getField(exporter,
.getPropertyValue("excludedBeans"); "excludedBeans");
assertThat(excludedBeans).containsExactly("dataSource"); assertThat(excludedBeans).containsExactly("dataSource");
} }
...@@ -130,8 +130,8 @@ public class JndiDataSourceAutoConfigurationTests { ...@@ -130,8 +130,8 @@ public class JndiDataSourceAutoConfigurationTests {
assertThat(this.context.getBean(DataSource.class)).isEqualTo(dataSource); assertThat(this.context.getBean(DataSource.class)).isEqualTo(dataSource);
for (MBeanExporter exporter : this.context.getBeansOfType(MBeanExporter.class) for (MBeanExporter exporter : this.context.getBeansOfType(MBeanExporter.class)
.values()) { .values()) {
Set<String> excludedBeans = (Set<String>) new DirectFieldAccessor(exporter) Set<String> excludedBeans = (Set<String>) ReflectionTestUtils
.getPropertyValue("excludedBeans"); .getField(exporter, "excludedBeans");
assertThat(excludedBeans).containsExactly("dataSource"); assertThat(excludedBeans).containsExactly("dataSource");
} }
} }
...@@ -151,8 +151,8 @@ public class JndiDataSourceAutoConfigurationTests { ...@@ -151,8 +151,8 @@ public class JndiDataSourceAutoConfigurationTests {
assertThat(this.context.getBean(DataSource.class)).isEqualTo(dataSource); assertThat(this.context.getBean(DataSource.class)).isEqualTo(dataSource);
MBeanExporter exporter = this.context.getBean(MBeanExporter.class); MBeanExporter exporter = this.context.getBean(MBeanExporter.class);
Set<String> excludedBeans = (Set<String>) new DirectFieldAccessor(exporter) Set<String> excludedBeans = (Set<String>) ReflectionTestUtils.getField(exporter,
.getPropertyValue("excludedBeans"); "excludedBeans");
assertThat(excludedBeans).isEmpty(); assertThat(excludedBeans).isEmpty();
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -26,7 +26,6 @@ import org.glassfish.jersey.server.ResourceConfig; ...@@ -26,7 +26,6 @@ import org.glassfish.jersey.server.ResourceConfig;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration; import org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration;
...@@ -55,9 +54,8 @@ public class JerseyAutoConfigurationCustomLoadOnStartupTests { ...@@ -55,9 +54,8 @@ public class JerseyAutoConfigurationCustomLoadOnStartupTests {
@Test @Test
public void contextLoads() { public void contextLoads() {
assertThat( assertThat(this.context.getBean("jerseyServletRegistration"))
new DirectFieldAccessor(this.context.getBean("jerseyServletRegistration")) .hasFieldOrPropertyWithValue("loadOnStartup", 5);
.getPropertyValue("loadOnStartup")).isEqualTo(5);
} }
@MinimalWebConfiguration @MinimalWebConfiguration
......
...@@ -24,7 +24,6 @@ import org.junit.Test; ...@@ -24,7 +24,6 @@ import org.junit.Test;
import org.messaginghub.pooled.jms.JmsPoolConnectionFactory; import org.messaginghub.pooled.jms.JmsPoolConnectionFactory;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration; import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQAutoConfiguration;
...@@ -184,9 +183,9 @@ public class JmsAutoConfigurationTests { ...@@ -184,9 +183,9 @@ public class JmsAutoConfigurationTests {
DefaultMessageListenerContainer container = getContainer(context, DefaultMessageListenerContainer container = getContainer(context,
"jmsListenerContainerFactory"); "jmsListenerContainerFactory");
assertThat(container.isSessionTransacted()).isFalse(); assertThat(container.isSessionTransacted()).isFalse();
assertThat(new DirectFieldAccessor(container) assertThat(container).hasFieldOrPropertyWithValue(
.getPropertyValue("transactionManager")).isSameAs( "transactionManager",
context.getBean(JtaTransactionManager.class)); context.getBean(JtaTransactionManager.class));
}); });
} }
...@@ -197,8 +196,8 @@ public class JmsAutoConfigurationTests { ...@@ -197,8 +196,8 @@ public class JmsAutoConfigurationTests {
DefaultMessageListenerContainer container = getContainer(context, DefaultMessageListenerContainer container = getContainer(context,
"jmsListenerContainerFactory"); "jmsListenerContainerFactory");
assertThat(container.isSessionTransacted()).isTrue(); assertThat(container.isSessionTransacted()).isTrue();
assertThat(new DirectFieldAccessor(container) assertThat(container)
.getPropertyValue("transactionManager")).isNull(); .hasFieldOrPropertyWithValue("transactionManager", null);
}); });
} }
...@@ -209,8 +208,8 @@ public class JmsAutoConfigurationTests { ...@@ -209,8 +208,8 @@ public class JmsAutoConfigurationTests {
DefaultMessageListenerContainer container = getContainer(context, DefaultMessageListenerContainer container = getContainer(context,
"jmsListenerContainerFactory"); "jmsListenerContainerFactory");
assertThat(container.isSessionTransacted()).isTrue(); assertThat(container.isSessionTransacted()).isTrue();
assertThat(new DirectFieldAccessor(container) assertThat(container)
.getPropertyValue("transactionManager")).isNull(); .hasFieldOrPropertyWithValue("transactionManager", null);
}); });
} }
......
...@@ -81,10 +81,8 @@ public class ActiveMQAutoConfigurationTests { ...@@ -81,10 +81,8 @@ public class ActiveMQAutoConfigurationTests {
.getBean(CachingConnectionFactory.class); .getBean(CachingConnectionFactory.class);
assertThat(connectionFactory.getTargetConnectionFactory()) assertThat(connectionFactory.getTargetConnectionFactory())
.isInstanceOf(ActiveMQConnectionFactory.class); .isInstanceOf(ActiveMQConnectionFactory.class);
assertThat(connectionFactory) assertThat(connectionFactory.isCacheConsumers()).isFalse();
.hasFieldOrPropertyWithValue("cacheConsumers", false); assertThat(connectionFactory.isCacheProducers()).isTrue();
assertThat(connectionFactory)
.hasFieldOrPropertyWithValue("cacheProducers", true);
assertThat(connectionFactory.getSessionCacheSize()).isEqualTo(1); assertThat(connectionFactory.getSessionCacheSize()).isEqualTo(1);
}); });
} }
...@@ -100,10 +98,8 @@ public class ActiveMQAutoConfigurationTests { ...@@ -100,10 +98,8 @@ public class ActiveMQAutoConfigurationTests {
assertThat(context).hasSingleBean(CachingConnectionFactory.class); assertThat(context).hasSingleBean(CachingConnectionFactory.class);
CachingConnectionFactory connectionFactory = context CachingConnectionFactory connectionFactory = context
.getBean(CachingConnectionFactory.class); .getBean(CachingConnectionFactory.class);
assertThat(connectionFactory) assertThat(connectionFactory.isCacheConsumers()).isTrue();
.hasFieldOrPropertyWithValue("cacheConsumers", true); assertThat(connectionFactory.isCacheProducers()).isFalse();
assertThat(connectionFactory)
.hasFieldOrPropertyWithValue("cacheProducers", false);
assertThat(connectionFactory.getSessionCacheSize()).isEqualTo(10); assertThat(connectionFactory.getSessionCacheSize()).isEqualTo(10);
}); });
} }
......
...@@ -81,10 +81,8 @@ public class ArtemisAutoConfigurationTests { ...@@ -81,10 +81,8 @@ public class ArtemisAutoConfigurationTests {
.getBean(CachingConnectionFactory.class); .getBean(CachingConnectionFactory.class);
assertThat(connectionFactory.getTargetConnectionFactory()) assertThat(connectionFactory.getTargetConnectionFactory())
.isInstanceOf(ActiveMQConnectionFactory.class); .isInstanceOf(ActiveMQConnectionFactory.class);
assertThat(connectionFactory) assertThat(connectionFactory.isCacheConsumers()).isFalse();
.hasFieldOrPropertyWithValue("cacheConsumers", false); assertThat(connectionFactory.isCacheProducers()).isTrue();
assertThat(connectionFactory)
.hasFieldOrPropertyWithValue("cacheProducers", true);
assertThat(connectionFactory.getSessionCacheSize()).isEqualTo(1); assertThat(connectionFactory.getSessionCacheSize()).isEqualTo(1);
}); });
} }
...@@ -100,10 +98,8 @@ public class ArtemisAutoConfigurationTests { ...@@ -100,10 +98,8 @@ public class ArtemisAutoConfigurationTests {
assertThat(context).hasSingleBean(CachingConnectionFactory.class); assertThat(context).hasSingleBean(CachingConnectionFactory.class);
CachingConnectionFactory connectionFactory = context CachingConnectionFactory connectionFactory = context
.getBean(CachingConnectionFactory.class); .getBean(CachingConnectionFactory.class);
assertThat(connectionFactory) assertThat(connectionFactory.isCacheConsumers()).isTrue();
.hasFieldOrPropertyWithValue("cacheConsumers", true); assertThat(connectionFactory.isCacheProducers()).isFalse();
assertThat(connectionFactory)
.hasFieldOrPropertyWithValue("cacheProducers", false);
assertThat(connectionFactory.getSessionCacheSize()).isEqualTo(10); assertThat(connectionFactory.getSessionCacheSize()).isEqualTo(10);
}); });
} }
......
...@@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.jmx; ...@@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.jmx;
import org.junit.After; import org.junit.After;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration; import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
...@@ -139,8 +138,7 @@ public class JmxAutoConfigurationTests { ...@@ -139,8 +138,7 @@ public class JmxAutoConfigurationTests {
this.context.refresh(); this.context.refresh();
IntegrationMBeanExporter mbeanExporter = this.context IntegrationMBeanExporter mbeanExporter = this.context
.getBean(IntegrationMBeanExporter.class); .getBean(IntegrationMBeanExporter.class);
DirectFieldAccessor dfa = new DirectFieldAccessor(mbeanExporter); assertThat(mbeanExporter).hasFieldOrPropertyWithValue("domain", "foo.my");
assertThat(dfa.getPropertyValue("domain")).isEqualTo("foo.my");
} }
@Configuration @Configuration
......
...@@ -36,7 +36,6 @@ import org.apache.kafka.streams.StreamsBuilder; ...@@ -36,7 +36,6 @@ import org.apache.kafka.streams.StreamsBuilder;
import org.apache.kafka.streams.StreamsConfig; import org.apache.kafka.streams.StreamsConfig;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -44,6 +43,7 @@ import org.springframework.context.annotation.Configuration; ...@@ -44,6 +43,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.kafka.annotation.EnableKafkaStreams; import org.springframework.kafka.annotation.EnableKafkaStreams;
import org.springframework.kafka.annotation.KafkaStreamsDefaultConfiguration; import org.springframework.kafka.annotation.KafkaStreamsDefaultConfiguration;
import org.springframework.kafka.config.AbstractKafkaListenerContainerFactory;
import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory; import org.springframework.kafka.config.ConcurrentKafkaListenerContainerFactory;
import org.springframework.kafka.config.KafkaListenerContainerFactory; import org.springframework.kafka.config.KafkaListenerContainerFactory;
import org.springframework.kafka.config.KafkaStreamsConfiguration; import org.springframework.kafka.config.KafkaStreamsConfiguration;
...@@ -52,6 +52,7 @@ import org.springframework.kafka.core.DefaultKafkaProducerFactory; ...@@ -52,6 +52,7 @@ import org.springframework.kafka.core.DefaultKafkaProducerFactory;
import org.springframework.kafka.core.KafkaAdmin; import org.springframework.kafka.core.KafkaAdmin;
import org.springframework.kafka.core.KafkaTemplate; import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.listener.AfterRollbackProcessor; import org.springframework.kafka.listener.AfterRollbackProcessor;
import org.springframework.kafka.listener.ContainerProperties;
import org.springframework.kafka.listener.ContainerProperties.AckMode; import org.springframework.kafka.listener.ContainerProperties.AckMode;
import org.springframework.kafka.listener.SeekToCurrentErrorHandler; import org.springframework.kafka.listener.SeekToCurrentErrorHandler;
import org.springframework.kafka.security.jaas.KafkaJaasLoginModuleInitializer; import org.springframework.kafka.security.jaas.KafkaJaasLoginModuleInitializer;
...@@ -61,6 +62,7 @@ import org.springframework.kafka.test.utils.KafkaTestUtils; ...@@ -61,6 +62,7 @@ import org.springframework.kafka.test.utils.KafkaTestUtils;
import org.springframework.kafka.transaction.ChainedKafkaTransactionManager; import org.springframework.kafka.transaction.ChainedKafkaTransactionManager;
import org.springframework.kafka.transaction.KafkaAwareTransactionManager; import org.springframework.kafka.transaction.KafkaAwareTransactionManager;
import org.springframework.kafka.transaction.KafkaTransactionManager; import org.springframework.kafka.transaction.KafkaTransactionManager;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.PlatformTransactionManager;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -448,55 +450,43 @@ public class KafkaAutoConfigurationTests { ...@@ -448,55 +450,43 @@ public class KafkaAutoConfigurationTests {
.getBean(DefaultKafkaConsumerFactory.class); .getBean(DefaultKafkaConsumerFactory.class);
KafkaTemplate<?, ?> kafkaTemplate = context KafkaTemplate<?, ?> kafkaTemplate = context
.getBean(KafkaTemplate.class); .getBean(KafkaTemplate.class);
KafkaListenerContainerFactory<?> kafkaListenerContainerFactory = context AbstractKafkaListenerContainerFactory kafkaListenerContainerFactory = (AbstractKafkaListenerContainerFactory) context
.getBean(KafkaListenerContainerFactory.class); .getBean(KafkaListenerContainerFactory.class);
assertThat(kafkaTemplate.getMessageConverter()) assertThat(kafkaTemplate.getMessageConverter())
.isInstanceOf(MessagingMessageConverter.class); .isInstanceOf(MessagingMessageConverter.class);
assertThat(new DirectFieldAccessor(kafkaTemplate) assertThat(kafkaTemplate).hasFieldOrPropertyWithValue(
.getPropertyValue("producerFactory")) "producerFactory", producerFactory);
.isEqualTo(producerFactory);
assertThat(kafkaTemplate.getDefaultTopic()).isEqualTo("testTopic"); assertThat(kafkaTemplate.getDefaultTopic()).isEqualTo("testTopic");
DirectFieldAccessor dfa = new DirectFieldAccessor( assertThat(kafkaListenerContainerFactory.getConsumerFactory())
kafkaListenerContainerFactory);
assertThat(dfa.getPropertyValue("consumerFactory"))
.isEqualTo(consumerFactory); .isEqualTo(consumerFactory);
assertThat(dfa.getPropertyValue("containerProperties.ackMode")) ContainerProperties containerProperties = kafkaListenerContainerFactory
.getContainerProperties();
assertThat(containerProperties.getAckMode())
.isEqualTo(AckMode.MANUAL); .isEqualTo(AckMode.MANUAL);
assertThat(dfa.getPropertyValue("containerProperties.clientId")) assertThat(containerProperties.getClientId()).isEqualTo("client");
.isEqualTo("client"); assertThat(containerProperties.getAckCount()).isEqualTo(123);
assertThat(dfa.getPropertyValue("containerProperties.ackCount")) assertThat(containerProperties.getAckTime()).isEqualTo(456L);
.isEqualTo(123); assertThat(containerProperties.getPollTimeout()).isEqualTo(2000L);
assertThat(dfa.getPropertyValue("containerProperties.ackTime")) assertThat(containerProperties.getNoPollThreshold()).isEqualTo(2.5f);
.isEqualTo(456L); assertThat(containerProperties.getIdleEventInterval())
assertThat(dfa.getPropertyValue("concurrency")).isEqualTo(3); .isEqualTo(1000L);
assertThat(dfa.getPropertyValue("containerProperties.pollTimeout")) assertThat(containerProperties.getMonitorInterval()).isEqualTo(45);
.isEqualTo(2000L); assertThat(containerProperties.isLogContainerConfig()).isTrue();
assertThat( assertThat(ReflectionTestUtils.getField(kafkaListenerContainerFactory,
dfa.getPropertyValue("containerProperties.noPollThreshold")) "concurrency")).isEqualTo(3);
.isEqualTo(2.5f); assertThat(kafkaListenerContainerFactory.isBatchListener()).isTrue();
assertThat(
dfa.getPropertyValue("containerProperties.idleEventInterval"))
.isEqualTo(1000L);
assertThat(
dfa.getPropertyValue("containerProperties.monitorInterval"))
.isEqualTo(45);
assertThat(dfa
.getPropertyValue("containerProperties.logContainerConfig"))
.isEqualTo(Boolean.TRUE);
assertThat(dfa.getPropertyValue("batchListener")).isEqualTo(true);
assertThat( assertThat(
context.getBeansOfType(KafkaJaasLoginModuleInitializer.class)) context.getBeansOfType(KafkaJaasLoginModuleInitializer.class))
.hasSize(1); .hasSize(1);
KafkaJaasLoginModuleInitializer jaas = context KafkaJaasLoginModuleInitializer jaas = context
.getBean(KafkaJaasLoginModuleInitializer.class); .getBean(KafkaJaasLoginModuleInitializer.class);
dfa = new DirectFieldAccessor(jaas); assertThat(jaas).hasFieldOrPropertyWithValue("loginModule", "foo");
assertThat(dfa.getPropertyValue("loginModule")).isEqualTo("foo"); assertThat(jaas).hasFieldOrPropertyWithValue("controlFlag",
assertThat(dfa.getPropertyValue("controlFlag")).isEqualTo(
AppConfigurationEntry.LoginModuleControlFlag.REQUISITE); AppConfigurationEntry.LoginModuleControlFlag.REQUISITE);
assertThat(context.getBeansOfType(KafkaTransactionManager.class)) assertThat(context.getBeansOfType(KafkaTransactionManager.class))
.hasSize(1); .hasSize(1);
assertThat(((Map<String, String>) dfa.getPropertyValue("options"))) assertThat(((Map<String, String>) ReflectionTestUtils.getField(jaas,
.containsExactly(entry("useKeyTab", "true")); "options"))).containsExactly(entry("useKeyTab", "true"));
}); });
} }
...@@ -518,10 +508,8 @@ public class KafkaAutoConfigurationTests { ...@@ -518,10 +508,8 @@ public class KafkaAutoConfigurationTests {
.run((context) -> { .run((context) -> {
ConcurrentKafkaListenerContainerFactory<?, ?> kafkaListenerContainerFactory = context ConcurrentKafkaListenerContainerFactory<?, ?> kafkaListenerContainerFactory = context
.getBean(ConcurrentKafkaListenerContainerFactory.class); .getBean(ConcurrentKafkaListenerContainerFactory.class);
DirectFieldAccessor dfa = new DirectFieldAccessor( assertThat(kafkaListenerContainerFactory).hasFieldOrPropertyWithValue(
kafkaListenerContainerFactory); "messageConverter", context.getBean("myMessageConverter"));
assertThat(dfa.getPropertyValue("messageConverter"))
.isSameAs(context.getBean("myMessageConverter"));
}); });
} }
...@@ -569,9 +557,9 @@ public class KafkaAutoConfigurationTests { ...@@ -569,9 +557,9 @@ public class KafkaAutoConfigurationTests {
.run((context) -> { .run((context) -> {
ConcurrentKafkaListenerContainerFactory<?, ?> factory = context ConcurrentKafkaListenerContainerFactory<?, ?> factory = context
.getBean(ConcurrentKafkaListenerContainerFactory.class); .getBean(ConcurrentKafkaListenerContainerFactory.class);
DirectFieldAccessor dfa = new DirectFieldAccessor(factory); assertThat(factory).hasFieldOrPropertyWithValue(
assertThat(dfa.getPropertyValue("afterRollbackProcessor")) "afterRollbackProcessor",
.isSameAs(context.getBean("afterRollbackProcessor")); context.getBean("afterRollbackProcessor"));
}); });
} }
...@@ -580,10 +568,8 @@ public class KafkaAutoConfigurationTests { ...@@ -580,10 +568,8 @@ public class KafkaAutoConfigurationTests {
this.contextRunner.run((context) -> { this.contextRunner.run((context) -> {
ConcurrentKafkaListenerContainerFactory<?, ?> kafkaListenerContainerFactory = context ConcurrentKafkaListenerContainerFactory<?, ?> kafkaListenerContainerFactory = context
.getBean(ConcurrentKafkaListenerContainerFactory.class); .getBean(ConcurrentKafkaListenerContainerFactory.class);
DirectFieldAccessor dfa = new DirectFieldAccessor( assertThat(kafkaListenerContainerFactory).hasFieldOrPropertyWithValue(
kafkaListenerContainerFactory); "replyTemplate", context.getBean(KafkaTemplate.class));
assertThat(dfa.getPropertyValue("replyTemplate"))
.isSameAs(context.getBean(KafkaTemplate.class));
}); });
} }
......
...@@ -37,7 +37,6 @@ import org.quartz.impl.calendar.MonthlyCalendar; ...@@ -37,7 +37,6 @@ import org.quartz.impl.calendar.MonthlyCalendar;
import org.quartz.impl.calendar.WeeklyCalendar; import org.quartz.impl.calendar.WeeklyCalendar;
import org.quartz.simpl.RAMJobStore; import org.quartz.simpl.RAMJobStore;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
...@@ -233,16 +232,18 @@ public class QuartzAutoConfigurationTests { ...@@ -233,16 +232,18 @@ public class QuartzAutoConfigurationTests {
assertThat(context).hasSingleBean(SchedulerFactoryBean.class); assertThat(context).hasSingleBean(SchedulerFactoryBean.class);
SchedulerFactoryBean schedulerFactory = context SchedulerFactoryBean schedulerFactory = context
.getBean(SchedulerFactoryBean.class); .getBean(SchedulerFactoryBean.class);
DirectFieldAccessor dfa = new DirectFieldAccessor(schedulerFactory);
QuartzProperties properties = new QuartzProperties(); QuartzProperties properties = new QuartzProperties();
assertThat(properties.isAutoStartup()) assertThat(properties.isAutoStartup())
.isEqualTo(schedulerFactory.isAutoStartup()); .isEqualTo(schedulerFactory.isAutoStartup());
assertThat((int) properties.getStartupDelay().getSeconds()) assertThat(schedulerFactory).hasFieldOrPropertyWithValue(
.isEqualTo(dfa.getPropertyValue("startupDelay")); "startupDelay",
assertThat(properties.isWaitForJobsToCompleteOnShutdown()).isEqualTo( (int) properties.getStartupDelay().getSeconds());
dfa.getPropertyValue("waitForJobsToCompleteOnShutdown")); assertThat(schedulerFactory).hasFieldOrPropertyWithValue(
assertThat(properties.isOverwriteExistingJobs()) "waitForJobsToCompleteOnShutdown",
.isEqualTo(dfa.getPropertyValue("overwriteExistingJobs")); properties.isWaitForJobsToCompleteOnShutdown());
assertThat(schedulerFactory).hasFieldOrPropertyWithValue(
"overwriteExistingJobs",
properties.isOverwriteExistingJobs());
}); });
...@@ -257,13 +258,13 @@ public class QuartzAutoConfigurationTests { ...@@ -257,13 +258,13 @@ public class QuartzAutoConfigurationTests {
assertThat(context).hasSingleBean(SchedulerFactoryBean.class); assertThat(context).hasSingleBean(SchedulerFactoryBean.class);
SchedulerFactoryBean schedulerFactory = context SchedulerFactoryBean schedulerFactory = context
.getBean(SchedulerFactoryBean.class); .getBean(SchedulerFactoryBean.class);
DirectFieldAccessor dfa = new DirectFieldAccessor(schedulerFactory);
assertThat(schedulerFactory.isAutoStartup()).isFalse(); assertThat(schedulerFactory.isAutoStartup()).isFalse();
assertThat(dfa.getPropertyValue("startupDelay")).isEqualTo(60); assertThat(schedulerFactory)
assertThat(dfa.getPropertyValue("waitForJobsToCompleteOnShutdown")) .hasFieldOrPropertyWithValue("startupDelay", 60);
.isEqualTo(true); assertThat(schedulerFactory).hasFieldOrPropertyWithValue(
assertThat(dfa.getPropertyValue("overwriteExistingJobs")) "waitForJobsToCompleteOnShutdown", true);
.isEqualTo(true); assertThat(schedulerFactory)
.hasFieldOrPropertyWithValue("overwriteExistingJobs", true);
}); });
} }
...@@ -301,8 +302,8 @@ public class QuartzAutoConfigurationTests { ...@@ -301,8 +302,8 @@ public class QuartzAutoConfigurationTests {
assertThat(context).hasSingleBean(SchedulerFactoryBean.class); assertThat(context).hasSingleBean(SchedulerFactoryBean.class);
SchedulerFactoryBean schedulerFactory = context SchedulerFactoryBean schedulerFactory = context
.getBean(SchedulerFactoryBean.class); .getBean(SchedulerFactoryBean.class);
DirectFieldAccessor dfa = new DirectFieldAccessor(schedulerFactory); assertThat(schedulerFactory).hasFieldOrPropertyWithValue("schedulerName",
assertThat(dfa.getPropertyValue("schedulerName")).isEqualTo(schedulerName); schedulerName);
}; };
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
package org.springframework.boot.autoconfigure.session; package org.springframework.boot.autoconfigure.session;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.test.context.assertj.AssertableReactiveWebApplicationContext; import org.springframework.boot.test.context.assertj.AssertableReactiveWebApplicationContext;
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext; import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext;
import org.springframework.session.ReactiveSessionRepository; import org.springframework.session.ReactiveSessionRepository;
...@@ -42,11 +41,6 @@ public abstract class AbstractSessionAutoConfigurationTests { ...@@ -42,11 +41,6 @@ public abstract class AbstractSessionAutoConfigurationTests {
return type.cast(repository); return type.cast(repository);
} }
protected Integer getSessionTimeout(SessionRepository<?> sessionRepository) {
return (Integer) new DirectFieldAccessor(sessionRepository)
.getPropertyValue("defaultMaxInactiveInterval");
}
protected <T extends ReactiveSessionRepository<?>> T validateSessionRepository( protected <T extends ReactiveSessionRepository<?>> T validateSessionRepository(
AssertableReactiveWebApplicationContext context, Class<T> type) { AssertableReactiveWebApplicationContext context, Class<T> type) {
assertThat(context).hasSingleBean(WebSessionManager.class); assertThat(context).hasSingleBean(WebSessionManager.class);
...@@ -57,9 +51,4 @@ public abstract class AbstractSessionAutoConfigurationTests { ...@@ -57,9 +51,4 @@ public abstract class AbstractSessionAutoConfigurationTests {
return type.cast(repository); return type.cast(repository);
} }
protected Integer getSessionTimeout(ReactiveSessionRepository<?> sessionRepository) {
return (Integer) new DirectFieldAccessor(sessionRepository)
.getPropertyValue("defaultMaxInactiveInterval");
}
} }
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.session; ...@@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.session;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.data.mongo.MongoReactiveDataAutoConfiguration; import org.springframework.boot.autoconfigure.data.mongo.MongoReactiveDataAutoConfiguration;
...@@ -87,8 +86,7 @@ public class ReactiveSessionAutoConfigurationMongoTests ...@@ -87,8 +86,7 @@ public class ReactiveSessionAutoConfigurationMongoTests
return (context) -> { return (context) -> {
ReactiveMongoOperationsSessionRepository repository = validateSessionRepository( ReactiveMongoOperationsSessionRepository repository = validateSessionRepository(
context, ReactiveMongoOperationsSessionRepository.class); context, ReactiveMongoOperationsSessionRepository.class);
assertThat(new DirectFieldAccessor(repository) assertThat(repository.getCollectionName()).isEqualTo(collectionName);
.getPropertyValue("collectionName")).isEqualTo(collectionName);
}; };
} }
......
...@@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.session; ...@@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.session;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisReactiveAutoConfiguration; import org.springframework.boot.autoconfigure.data.redis.RedisReactiveAutoConfiguration;
...@@ -81,10 +80,9 @@ public class ReactiveSessionAutoConfigurationRedisTests ...@@ -81,10 +80,9 @@ public class ReactiveSessionAutoConfigurationRedisTests
return (context) -> { return (context) -> {
ReactiveRedisOperationsSessionRepository repository = validateSessionRepository( ReactiveRedisOperationsSessionRepository repository = validateSessionRepository(
context, ReactiveRedisOperationsSessionRepository.class); context, ReactiveRedisOperationsSessionRepository.class);
assertThat(new DirectFieldAccessor(repository).getPropertyValue("namespace")) assertThat(repository).hasFieldOrPropertyWithValue("namespace", namespace);
.isEqualTo(namespace); assertThat(repository).hasFieldOrPropertyWithValue("redisFlushMode",
assertThat(new DirectFieldAccessor(repository) flushMode);
.getPropertyValue("redisFlushMode")).isEqualTo(flushMode);
}; };
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -20,7 +20,6 @@ import com.hazelcast.core.HazelcastInstance; ...@@ -20,7 +20,6 @@ import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap; import com.hazelcast.core.IMap;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.FilteredClassLoader; import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext; import org.springframework.boot.test.context.assertj.AssertableWebApplicationContext;
...@@ -94,9 +93,8 @@ public class SessionAutoConfigurationHazelcastTests ...@@ -94,9 +93,8 @@ public class SessionAutoConfigurationHazelcastTests
.run((context) -> { .run((context) -> {
HazelcastSessionRepository repository = validateSessionRepository( HazelcastSessionRepository repository = validateSessionRepository(
context, HazelcastSessionRepository.class); context, HazelcastSessionRepository.class);
assertThat(new DirectFieldAccessor(repository) assertThat(repository).hasFieldOrPropertyWithValue(
.getPropertyValue("hazelcastFlushMode")) "hazelcastFlushMode", HazelcastFlushMode.IMMEDIATE);
.isEqualTo(HazelcastFlushMode.IMMEDIATE);
}); });
} }
......
...@@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.session; ...@@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.session;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
...@@ -72,16 +71,15 @@ public class SessionAutoConfigurationJdbcTests ...@@ -72,16 +71,15 @@ public class SessionAutoConfigurationJdbcTests
private void validateDefaultConfig(AssertableWebApplicationContext context) { private void validateDefaultConfig(AssertableWebApplicationContext context) {
JdbcOperationsSessionRepository repository = validateSessionRepository(context, JdbcOperationsSessionRepository repository = validateSessionRepository(context,
JdbcOperationsSessionRepository.class); JdbcOperationsSessionRepository.class);
assertThat(new DirectFieldAccessor(repository).getPropertyValue("tableName")) assertThat(repository).hasFieldOrPropertyWithValue("tableName", "SPRING_SESSION");
.isEqualTo("SPRING_SESSION");
assertThat(context.getBean(JdbcSessionProperties.class).getInitializeSchema()) assertThat(context.getBean(JdbcSessionProperties.class).getInitializeSchema())
.isEqualTo(DataSourceInitializationMode.EMBEDDED); .isEqualTo(DataSourceInitializationMode.EMBEDDED);
assertThat(context.getBean(JdbcOperations.class) assertThat(context.getBean(JdbcOperations.class)
.queryForList("select * from SPRING_SESSION")).isEmpty(); .queryForList("select * from SPRING_SESSION")).isEmpty();
SpringBootJdbcHttpSessionConfiguration configuration = context SpringBootJdbcHttpSessionConfiguration configuration = context
.getBean(SpringBootJdbcHttpSessionConfiguration.class); .getBean(SpringBootJdbcHttpSessionConfiguration.class);
assertThat(new DirectFieldAccessor(configuration).getPropertyValue("cleanupCron")) assertThat(configuration).hasFieldOrPropertyWithValue("cleanupCron",
.isEqualTo("0 * * * * *"); "0 * * * * *");
} }
@Test @Test
...@@ -100,8 +98,8 @@ public class SessionAutoConfigurationJdbcTests ...@@ -100,8 +98,8 @@ public class SessionAutoConfigurationJdbcTests
"spring.session.jdbc.initialize-schema=never").run((context) -> { "spring.session.jdbc.initialize-schema=never").run((context) -> {
JdbcOperationsSessionRepository repository = validateSessionRepository( JdbcOperationsSessionRepository repository = validateSessionRepository(
context, JdbcOperationsSessionRepository.class); context, JdbcOperationsSessionRepository.class);
assertThat(new DirectFieldAccessor(repository) assertThat(repository).hasFieldOrPropertyWithValue("tableName",
.getPropertyValue("tableName")).isEqualTo("SPRING_SESSION"); "SPRING_SESSION");
assertThat(context.getBean(JdbcSessionProperties.class) assertThat(context.getBean(JdbcSessionProperties.class)
.getInitializeSchema()) .getInitializeSchema())
.isEqualTo(DataSourceInitializationMode.NEVER); .isEqualTo(DataSourceInitializationMode.NEVER);
...@@ -119,8 +117,8 @@ public class SessionAutoConfigurationJdbcTests ...@@ -119,8 +117,8 @@ public class SessionAutoConfigurationJdbcTests
.run((context) -> { .run((context) -> {
JdbcOperationsSessionRepository repository = validateSessionRepository( JdbcOperationsSessionRepository repository = validateSessionRepository(
context, JdbcOperationsSessionRepository.class); context, JdbcOperationsSessionRepository.class);
assertThat(new DirectFieldAccessor(repository) assertThat(repository).hasFieldOrPropertyWithValue("tableName",
.getPropertyValue("tableName")).isEqualTo("FOO_BAR"); "FOO_BAR");
assertThat(context.getBean(JdbcSessionProperties.class) assertThat(context.getBean(JdbcSessionProperties.class)
.getInitializeSchema()) .getInitializeSchema())
.isEqualTo(DataSourceInitializationMode.EMBEDDED); .isEqualTo(DataSourceInitializationMode.EMBEDDED);
...@@ -140,8 +138,8 @@ public class SessionAutoConfigurationJdbcTests ...@@ -140,8 +138,8 @@ public class SessionAutoConfigurationJdbcTests
.isEqualTo("0 0 12 * * *"); .isEqualTo("0 0 12 * * *");
SpringBootJdbcHttpSessionConfiguration configuration = context SpringBootJdbcHttpSessionConfiguration configuration = context
.getBean(SpringBootJdbcHttpSessionConfiguration.class); .getBean(SpringBootJdbcHttpSessionConfiguration.class);
assertThat(new DirectFieldAccessor(configuration) assertThat(configuration).hasFieldOrPropertyWithValue("cleanupCron",
.getPropertyValue("cleanupCron")).isEqualTo("0 0 12 * * *"); "0 0 12 * * *");
}); });
} }
......
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.session; ...@@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.session;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration; import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration; import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
...@@ -82,8 +81,8 @@ public class SessionAutoConfigurationMongoTests ...@@ -82,8 +81,8 @@ public class SessionAutoConfigurationMongoTests
return (context) -> { return (context) -> {
MongoOperationsSessionRepository repository = validateSessionRepository( MongoOperationsSessionRepository repository = validateSessionRepository(
context, MongoOperationsSessionRepository.class); context, MongoOperationsSessionRepository.class);
assertThat(new DirectFieldAccessor(repository) assertThat(repository).hasFieldOrPropertyWithValue("collectionName",
.getPropertyValue("collectionName")).isEqualTo(collectionName); collectionName);
}; };
} }
......
...@@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.session; ...@@ -19,7 +19,6 @@ package org.springframework.boot.autoconfigure.session;
import org.junit.ClassRule; import org.junit.ClassRule;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.autoconfigure.session.RedisSessionConfiguration.SpringBootRedisHttpSessionConfiguration; import org.springframework.boot.autoconfigure.session.RedisSessionConfiguration.SpringBootRedisHttpSessionConfiguration;
...@@ -94,12 +93,12 @@ public class SessionAutoConfigurationRedisTests ...@@ -94,12 +93,12 @@ public class SessionAutoConfigurationRedisTests
context, RedisOperationsSessionRepository.class); context, RedisOperationsSessionRepository.class);
assertThat(repository.getSessionCreatedChannelPrefix()) assertThat(repository.getSessionCreatedChannelPrefix())
.isEqualTo(sessionCreatedChannelPrefix); .isEqualTo(sessionCreatedChannelPrefix);
assertThat(new DirectFieldAccessor(repository) assertThat(repository).hasFieldOrPropertyWithValue("redisFlushMode",
.getPropertyValue("redisFlushMode")).isEqualTo(flushMode); flushMode);
SpringBootRedisHttpSessionConfiguration configuration = context SpringBootRedisHttpSessionConfiguration configuration = context
.getBean(SpringBootRedisHttpSessionConfiguration.class); .getBean(SpringBootRedisHttpSessionConfiguration.class);
assertThat(new DirectFieldAccessor(configuration) assertThat(configuration).hasFieldOrPropertyWithValue("cleanupCron",
.getPropertyValue("cleanupCron")).isEqualTo(cleanupCron); cleanupCron);
}; };
} }
......
...@@ -23,7 +23,6 @@ import java.util.function.Consumer; ...@@ -23,7 +23,6 @@ import java.util.function.Consumer;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.task.TaskExecutorBuilder; import org.springframework.boot.task.TaskExecutorBuilder;
import org.springframework.boot.task.TaskExecutorCustomizer; import org.springframework.boot.task.TaskExecutorCustomizer;
...@@ -70,12 +69,12 @@ public class TaskExecutionAutoConfigurationTests { ...@@ -70,12 +69,12 @@ public class TaskExecutionAutoConfigurationTests {
"spring.task.execution.pool.keep-alive=5s", "spring.task.execution.pool.keep-alive=5s",
"spring.task.execution.thread-name-prefix=mytest-") "spring.task.execution.thread-name-prefix=mytest-")
.run(assertTaskExecutor((taskExecutor) -> { .run(assertTaskExecutor((taskExecutor) -> {
DirectFieldAccessor dfa = new DirectFieldAccessor(taskExecutor); assertThat(taskExecutor).hasFieldOrPropertyWithValue("queueCapacity",
assertThat(dfa.getPropertyValue("queueCapacity")).isEqualTo(10); 10);
assertThat(taskExecutor.getCorePoolSize()).isEqualTo(2); assertThat(taskExecutor.getCorePoolSize()).isEqualTo(2);
assertThat(taskExecutor.getMaxPoolSize()).isEqualTo(4); assertThat(taskExecutor.getMaxPoolSize()).isEqualTo(4);
assertThat(dfa.getPropertyValue("allowCoreThreadTimeOut")) assertThat(taskExecutor)
.isEqualTo(true); .hasFieldOrPropertyWithValue("allowCoreThreadTimeOut", true);
assertThat(taskExecutor.getKeepAliveSeconds()).isEqualTo(5); assertThat(taskExecutor.getKeepAliveSeconds()).isEqualTo(5);
assertThat(taskExecutor.getThreadNamePrefix()).isEqualTo("mytest-"); assertThat(taskExecutor.getThreadNamePrefix()).isEqualTo("mytest-");
})); }));
......
...@@ -27,7 +27,6 @@ import javax.validation.constraints.Size; ...@@ -27,7 +27,6 @@ import javax.validation.constraints.Size;
import org.junit.After; import org.junit.After;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfigurationTests.CustomValidatorConfiguration.TestBeanPostProcessor; import org.springframework.boot.autoconfigure.validation.ValidationAutoConfigurationTests.CustomValidatorConfiguration.TestBeanPostProcessor;
import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.boot.test.util.TestPropertyValues;
...@@ -35,6 +34,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext ...@@ -35,6 +34,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.validation.beanvalidation.CustomValidatorBean; import org.springframework.validation.beanvalidation.CustomValidatorBean;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
...@@ -195,9 +195,8 @@ public class ValidationAutoConfigurationTests { ...@@ -195,9 +195,8 @@ public class ValidationAutoConfigurationTests {
.isSameAs(userMethodValidationPostProcessor); .isSameAs(userMethodValidationPostProcessor);
assertThat(this.context.getBeansOfType(MethodValidationPostProcessor.class)) assertThat(this.context.getBeansOfType(MethodValidationPostProcessor.class))
.hasSize(1); .hasSize(1);
assertThat(this.context.getBean(Validator.class)) assertThat(this.context.getBean(Validator.class)).isNotSameAs(ReflectionTestUtils
.isNotSameAs(new DirectFieldAccessor(userMethodValidationPostProcessor) .getField(userMethodValidationPostProcessor, "validator"));
.getPropertyValue("validator"));
} }
@Test @Test
......
...@@ -27,7 +27,6 @@ import javax.validation.ValidatorFactory; ...@@ -27,7 +27,6 @@ import javax.validation.ValidatorFactory;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration; import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration;
import org.springframework.boot.autoconfigure.validation.ValidatorAdapter; import org.springframework.boot.autoconfigure.validation.ValidatorAdapter;
...@@ -355,9 +354,8 @@ public class WebFluxAutoConfigurationTests { ...@@ -355,9 +354,8 @@ public class WebFluxAutoConfigurationTests {
Validator validator = context.getBean(Validator.class); Validator validator = context.getBean(Validator.class);
assertThat(validator).isInstanceOf(ValidatorAdapter.class); assertThat(validator).isInstanceOf(ValidatorAdapter.class);
Validator target = ((ValidatorAdapter) validator).getTarget(); Validator target = ((ValidatorAdapter) validator).getTarget();
assertThat(new DirectFieldAccessor(target) assertThat(target).hasFieldOrPropertyWithValue("targetValidator",
.getPropertyValue("targetValidator")) context.getBean("customValidator"));
.isSameAs(context.getBean("customValidator"));
}); });
} }
......
...@@ -21,7 +21,6 @@ import javax.servlet.http.HttpServletRequest; ...@@ -21,7 +21,6 @@ import javax.servlet.http.HttpServletRequest;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner; import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.boot.web.servlet.MultipartConfigFactory; import org.springframework.boot.web.servlet.MultipartConfigFactory;
...@@ -178,9 +177,8 @@ public class DispatcherServletAutoConfigurationTests { ...@@ -178,9 +177,8 @@ public class DispatcherServletAutoConfigurationTests {
.containsExactly(false); .containsExactly(false);
assertThat(dispatcherServlet).extracting("enableLoggingRequestDetails") assertThat(dispatcherServlet).extracting("enableLoggingRequestDetails")
.containsExactly(false); .containsExactly(false);
assertThat(new DirectFieldAccessor( assertThat(context.getBean("dispatcherServletRegistration"))
context.getBean("dispatcherServletRegistration")) .hasFieldOrPropertyWithValue("loadOnStartup", -1);
.getPropertyValue("loadOnStartup")).isEqualTo(-1);
}); });
} }
...@@ -201,9 +199,8 @@ public class DispatcherServletAutoConfigurationTests { ...@@ -201,9 +199,8 @@ public class DispatcherServletAutoConfigurationTests {
.containsExactly(false); .containsExactly(false);
assertThat(dispatcherServlet).extracting("dispatchTraceRequest") assertThat(dispatcherServlet).extracting("dispatchTraceRequest")
.containsExactly(true); .containsExactly(true);
assertThat(new DirectFieldAccessor( assertThat(context.getBean("dispatcherServletRegistration"))
context.getBean("dispatcherServletRegistration")) .hasFieldOrPropertyWithValue("loadOnStartup", 5);
.getPropertyValue("loadOnStartup")).isEqualTo(5);
}); });
} }
......
...@@ -21,7 +21,7 @@ import java.util.List; ...@@ -21,7 +21,7 @@ import java.util.List;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor; import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -174,10 +174,8 @@ public class DeferredLogTests { ...@@ -174,10 +174,8 @@ public class DeferredLogTests {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Test @Test
public void switchTo() { public void switchTo() {
DirectFieldAccessor deferredLogFieldAccessor = new DirectFieldAccessor( List<String> lines = (List<String>) ReflectionTestUtils.getField(this.deferredLog,
this.deferredLog); "lines");
List<String> lines = (List<String>) deferredLogFieldAccessor
.getPropertyValue("lines");
assertThat(lines).isEmpty(); assertThat(lines).isEmpty();
this.deferredLog.error(this.message, this.throwable); this.deferredLog.error(this.message, this.throwable);
......
...@@ -22,7 +22,6 @@ import java.util.Set; ...@@ -22,7 +22,6 @@ import java.util.Set;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.core.task.TaskDecorator; import org.springframework.core.task.TaskDecorator;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.test.util.ReflectionTestUtils; import org.springframework.test.util.ReflectionTestUtils;
...@@ -48,11 +47,10 @@ public class TaskExecutorBuilderTests { ...@@ -48,11 +47,10 @@ public class TaskExecutorBuilderTests {
ThreadPoolTaskExecutor executor = this.builder.queueCapacity(10).corePoolSize(4) ThreadPoolTaskExecutor executor = this.builder.queueCapacity(10).corePoolSize(4)
.maxPoolSize(8).allowCoreThreadTimeOut(true) .maxPoolSize(8).allowCoreThreadTimeOut(true)
.keepAlive(Duration.ofMinutes(1)).build(); .keepAlive(Duration.ofMinutes(1)).build();
DirectFieldAccessor dfa = new DirectFieldAccessor(executor); assertThat(executor).hasFieldOrPropertyWithValue("queueCapacity", 10);
assertThat(dfa.getPropertyValue("queueCapacity")).isEqualTo(10);
assertThat(executor.getCorePoolSize()).isEqualTo(4); assertThat(executor.getCorePoolSize()).isEqualTo(4);
assertThat(executor.getMaxPoolSize()).isEqualTo(8); assertThat(executor.getMaxPoolSize()).isEqualTo(8);
assertThat(dfa.getPropertyValue("allowCoreThreadTimeOut")).isEqualTo(true); assertThat(executor).hasFieldOrPropertyWithValue("allowCoreThreadTimeOut", true);
assertThat(executor.getKeepAliveSeconds()).isEqualTo(60); assertThat(executor.getKeepAliveSeconds()).isEqualTo(60);
} }
......
...@@ -25,7 +25,6 @@ import org.junit.After; ...@@ -25,7 +25,6 @@ import org.junit.After;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
...@@ -100,13 +99,11 @@ public class SpringBootServletInitializerTests { ...@@ -100,13 +99,11 @@ public class SpringBootServletInitializerTests {
} }
@Test @Test
@SuppressWarnings("rawtypes")
public void mainClassHasSensibleDefault() { public void mainClassHasSensibleDefault() {
new WithConfigurationAnnotation() new WithConfigurationAnnotation()
.createRootApplicationContext(this.servletContext); .createRootApplicationContext(this.servletContext);
Class mainApplicationClass = (Class<?>) new DirectFieldAccessor(this.application) assertThat(this.application).hasFieldOrPropertyWithValue("mainApplicationClass",
.getPropertyValue("mainApplicationClass"); WithConfigurationAnnotation.class);
assertThat(mainApplicationClass).isEqualTo(WithConfigurationAnnotation.class);
} }
@Test @Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment