Commit 1a0d53de authored by Stephane Nicoll's avatar Stephane Nicoll

Replace ReflectionTestUtils usage by hasFieldOrPropertyWithValue

Closes gh-14696
parent cfa130b2
...@@ -111,9 +111,8 @@ public class ReactiveTokenValidatorTests { ...@@ -111,9 +111,8 @@ public class ReactiveTokenValidatorTests {
assertThat(((CloudFoundryAuthorizationException) ex).getReason()) assertThat(((CloudFoundryAuthorizationException) ex).getReason())
.isEqualTo(Reason.INVALID_KEY_ID); .isEqualTo(Reason.INVALID_KEY_ID);
}).verify(); }).verify();
Object cachedTokenKeys = ReflectionTestUtils.getField(this.tokenValidator, assertThat(this.tokenValidator).hasFieldOrPropertyWithValue("cachedTokenKeys",
"cachedTokenKeys"); VALID_KEYS);
assertThat(cachedTokenKeys).isEqualTo(VALID_KEYS);
fetchTokenKeys.assertWasSubscribed(); fetchTokenKeys.assertWasSubscribed();
} }
...@@ -133,9 +132,8 @@ public class ReactiveTokenValidatorTests { ...@@ -133,9 +132,8 @@ public class ReactiveTokenValidatorTests {
.create(this.tokenValidator.validate( .create(this.tokenValidator.validate(
new Token(getSignedToken(header.getBytes(), claims.getBytes())))) new Token(getSignedToken(header.getBytes(), claims.getBytes()))))
.verifyComplete(); .verifyComplete();
Object cachedTokenKeys = ReflectionTestUtils.getField(this.tokenValidator, assertThat(this.tokenValidator).hasFieldOrPropertyWithValue("cachedTokenKeys",
"cachedTokenKeys"); VALID_KEYS);
assertThat(cachedTokenKeys).isEqualTo(VALID_KEYS);
fetchTokenKeys.assertWasSubscribed(); fetchTokenKeys.assertWasSubscribed();
} }
...@@ -152,9 +150,8 @@ public class ReactiveTokenValidatorTests { ...@@ -152,9 +150,8 @@ public class ReactiveTokenValidatorTests {
.create(this.tokenValidator.validate( .create(this.tokenValidator.validate(
new Token(getSignedToken(header.getBytes(), claims.getBytes())))) new Token(getSignedToken(header.getBytes(), claims.getBytes()))))
.verifyComplete(); .verifyComplete();
Object cachedTokenKeys = ReflectionTestUtils.getField(this.tokenValidator, assertThat(this.tokenValidator).hasFieldOrPropertyWithValue("cachedTokenKeys",
"cachedTokenKeys"); VALID_KEYS);
assertThat(cachedTokenKeys).isEqualTo(VALID_KEYS);
fetchTokenKeys.assertWasSubscribed(); fetchTokenKeys.assertWasSubscribed();
} }
...@@ -177,9 +174,8 @@ public class ReactiveTokenValidatorTests { ...@@ -177,9 +174,8 @@ public class ReactiveTokenValidatorTests {
assertThat(((CloudFoundryAuthorizationException) ex).getReason()) assertThat(((CloudFoundryAuthorizationException) ex).getReason())
.isEqualTo(Reason.INVALID_KEY_ID); .isEqualTo(Reason.INVALID_KEY_ID);
}).verify(); }).verify();
Object cachedTokenKeys = ReflectionTestUtils.getField(this.tokenValidator, assertThat(this.tokenValidator).hasFieldOrPropertyWithValue("cachedTokenKeys",
"cachedTokenKeys"); VALID_KEYS);
assertThat(cachedTokenKeys).isEqualTo(VALID_KEYS);
fetchTokenKeys.assertWasSubscribed(); fetchTokenKeys.assertWasSubscribed();
} }
......
...@@ -31,7 +31,6 @@ import org.springframework.boot.test.context.runner.WebApplicationContextRunner; ...@@ -31,7 +31,6 @@ import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
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.web.servlet.DispatcherServlet; import org.springframework.web.servlet.DispatcherServlet;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -54,8 +53,7 @@ public class ServletEndpointManagementContextConfigurationTests { ...@@ -54,8 +53,7 @@ public class ServletEndpointManagementContextConfigurationTests {
assertThat(context).hasSingleBean(ServletEndpointRegistrar.class); assertThat(context).hasSingleBean(ServletEndpointRegistrar.class);
ServletEndpointRegistrar bean = context ServletEndpointRegistrar bean = context
.getBean(ServletEndpointRegistrar.class); .getBean(ServletEndpointRegistrar.class);
String basePath = (String) ReflectionTestUtils.getField(bean, "basePath"); assertThat(bean).hasFieldOrPropertyWithValue("basePath", "/test/actuator");
assertThat(basePath).isEqualTo("/test/actuator");
}); });
} }
...@@ -67,8 +65,7 @@ public class ServletEndpointManagementContextConfigurationTests { ...@@ -67,8 +65,7 @@ public class ServletEndpointManagementContextConfigurationTests {
assertThat(context).hasSingleBean(ServletEndpointRegistrar.class); assertThat(context).hasSingleBean(ServletEndpointRegistrar.class);
ServletEndpointRegistrar bean = context ServletEndpointRegistrar bean = context
.getBean(ServletEndpointRegistrar.class); .getBean(ServletEndpointRegistrar.class);
String basePath = (String) ReflectionTestUtils.getField(bean, "basePath"); assertThat(bean).hasFieldOrPropertyWithValue("basePath", "/actuator");
assertThat(basePath).isEqualTo("/actuator");
}); });
} }
......
...@@ -326,8 +326,8 @@ public class RabbitAutoConfigurationTests { ...@@ -326,8 +326,8 @@ public class RabbitAutoConfigurationTests {
.withPropertyValues("spring.rabbitmq.template.queue:default-queue") .withPropertyValues("spring.rabbitmq.template.queue:default-queue")
.run((context) -> { .run((context) -> {
RabbitTemplate rabbitTemplate = context.getBean(RabbitTemplate.class); RabbitTemplate rabbitTemplate = context.getBean(RabbitTemplate.class);
assertThat(ReflectionTestUtils.getField(rabbitTemplate, "queue")) assertThat(rabbitTemplate).hasFieldOrPropertyWithValue("queue",
.isEqualTo("default-queue"); "default-queue");
}); });
} }
......
...@@ -32,7 +32,6 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean; ...@@ -32,7 +32,6 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletContext; import org.springframework.mock.web.MockServletContext;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.View; import org.springframework.web.servlet.View;
import org.springframework.web.servlet.resource.ResourceUrlEncodingFilter; import org.springframework.web.servlet.resource.ResourceUrlEncodingFilter;
...@@ -131,8 +130,8 @@ public class FreeMarkerAutoConfigurationServletIntegrationTests { ...@@ -131,8 +130,8 @@ public class FreeMarkerAutoConfigurationServletIntegrationTests {
registerAndRefreshContext("spring.freemarker.allow-session-override:true"); registerAndRefreshContext("spring.freemarker.allow-session-override:true");
AbstractTemplateViewResolver viewResolver = this.context AbstractTemplateViewResolver viewResolver = this.context
.getBean(FreeMarkerViewResolver.class); .getBean(FreeMarkerViewResolver.class);
assertThat(ReflectionTestUtils.getField(viewResolver, "allowSessionOverride")) assertThat(viewResolver).hasFieldOrPropertyWithValue("allowSessionOverride",
.isEqualTo(true); true);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
......
...@@ -28,7 +28,6 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner; ...@@ -28,7 +28,6 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner;
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.jms.connection.CachingConnectionFactory; import org.springframework.jms.connection.CachingConnectionFactory;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -82,10 +81,10 @@ public class ActiveMQAutoConfigurationTests { ...@@ -82,10 +81,10 @@ public class ActiveMQAutoConfigurationTests {
.getBean(CachingConnectionFactory.class); .getBean(CachingConnectionFactory.class);
assertThat(connectionFactory.getTargetConnectionFactory()) assertThat(connectionFactory.getTargetConnectionFactory())
.isInstanceOf(ActiveMQConnectionFactory.class); .isInstanceOf(ActiveMQConnectionFactory.class);
assertThat(ReflectionTestUtils.getField(connectionFactory, assertThat(connectionFactory)
"cacheConsumers")).isEqualTo(false); .hasFieldOrPropertyWithValue("cacheConsumers", false);
assertThat(ReflectionTestUtils.getField(connectionFactory, assertThat(connectionFactory)
"cacheProducers")).isEqualTo(true); .hasFieldOrPropertyWithValue("cacheProducers", true);
assertThat(connectionFactory.getSessionCacheSize()).isEqualTo(1); assertThat(connectionFactory.getSessionCacheSize()).isEqualTo(1);
}); });
} }
...@@ -101,10 +100,10 @@ public class ActiveMQAutoConfigurationTests { ...@@ -101,10 +100,10 @@ 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(ReflectionTestUtils.getField(connectionFactory, assertThat(connectionFactory)
"cacheConsumers")).isEqualTo(true); .hasFieldOrPropertyWithValue("cacheConsumers", true);
assertThat(ReflectionTestUtils.getField(connectionFactory, assertThat(connectionFactory)
"cacheProducers")).isEqualTo(false); .hasFieldOrPropertyWithValue("cacheProducers", false);
assertThat(connectionFactory.getSessionCacheSize()).isEqualTo(10); assertThat(connectionFactory.getSessionCacheSize()).isEqualTo(10);
}); });
} }
......
...@@ -53,7 +53,6 @@ import org.springframework.jms.core.JmsTemplate; ...@@ -53,7 +53,6 @@ import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.SessionCallback; import org.springframework.jms.core.SessionCallback;
import org.springframework.jms.support.destination.DestinationResolver; import org.springframework.jms.support.destination.DestinationResolver;
import org.springframework.jms.support.destination.DynamicDestinationResolver; import org.springframework.jms.support.destination.DynamicDestinationResolver;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -82,10 +81,10 @@ public class ArtemisAutoConfigurationTests { ...@@ -82,10 +81,10 @@ public class ArtemisAutoConfigurationTests {
.getBean(CachingConnectionFactory.class); .getBean(CachingConnectionFactory.class);
assertThat(connectionFactory.getTargetConnectionFactory()) assertThat(connectionFactory.getTargetConnectionFactory())
.isInstanceOf(ActiveMQConnectionFactory.class); .isInstanceOf(ActiveMQConnectionFactory.class);
assertThat(ReflectionTestUtils.getField(connectionFactory, assertThat(connectionFactory)
"cacheConsumers")).isEqualTo(false); .hasFieldOrPropertyWithValue("cacheConsumers", false);
assertThat(ReflectionTestUtils.getField(connectionFactory, assertThat(connectionFactory)
"cacheProducers")).isEqualTo(true); .hasFieldOrPropertyWithValue("cacheProducers", true);
assertThat(connectionFactory.getSessionCacheSize()).isEqualTo(1); assertThat(connectionFactory.getSessionCacheSize()).isEqualTo(1);
}); });
} }
...@@ -101,10 +100,10 @@ public class ArtemisAutoConfigurationTests { ...@@ -101,10 +100,10 @@ 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(ReflectionTestUtils.getField(connectionFactory, assertThat(connectionFactory)
"cacheConsumers")).isEqualTo(true); .hasFieldOrPropertyWithValue("cacheConsumers", true);
assertThat(ReflectionTestUtils.getField(connectionFactory, assertThat(connectionFactory)
"cacheProducers")).isEqualTo(false); .hasFieldOrPropertyWithValue("cacheProducers", false);
assertThat(connectionFactory.getSessionCacheSize()).isEqualTo(10); assertThat(connectionFactory.getSessionCacheSize()).isEqualTo(10);
}); });
} }
......
...@@ -102,10 +102,9 @@ public class JmxAutoConfigurationTests { ...@@ -102,10 +102,9 @@ public class JmxAutoConfigurationTests {
assertThat(mBeanExporter).isNotNull(); assertThat(mBeanExporter).isNotNull();
MetadataNamingStrategy naming = (MetadataNamingStrategy) ReflectionTestUtils MetadataNamingStrategy naming = (MetadataNamingStrategy) ReflectionTestUtils
.getField(mBeanExporter, "namingStrategy"); .getField(mBeanExporter, "namingStrategy");
assertThat(ReflectionTestUtils.getField(naming, "defaultDomain")) assertThat(naming).hasFieldOrPropertyWithValue("defaultDomain", "my-test-domain");
.isEqualTo("my-test-domain"); assertThat(naming).hasFieldOrPropertyWithValue("ensureUniqueRuntimeObjectNames",
assertThat(ReflectionTestUtils.getField(naming, "ensureUniqueRuntimeObjectNames")) true);
.isEqualTo(true);
} }
@Test @Test
......
...@@ -48,8 +48,7 @@ public class LdapAutoConfigurationTests { ...@@ -48,8 +48,7 @@ public class LdapAutoConfigurationTests {
public void contextSourceWithDefaultUrl() { public void contextSourceWithDefaultUrl() {
this.contextRunner.run((context) -> { this.contextRunner.run((context) -> {
LdapContextSource contextSource = context.getBean(LdapContextSource.class); LdapContextSource contextSource = context.getBean(LdapContextSource.class);
String[] urls = (String[]) ReflectionTestUtils.getField(contextSource, String[] urls = getUrls(contextSource);
"urls");
assertThat(urls).containsExactly("ldap://localhost:389"); assertThat(urls).containsExactly("ldap://localhost:389");
assertThat(contextSource.isAnonymousReadOnly()).isFalse(); assertThat(contextSource.isAnonymousReadOnly()).isFalse();
}); });
...@@ -61,8 +60,7 @@ public class LdapAutoConfigurationTests { ...@@ -61,8 +60,7 @@ public class LdapAutoConfigurationTests {
.run((context) -> { .run((context) -> {
ContextSource contextSource = context ContextSource contextSource = context
.getBean(LdapContextSource.class); .getBean(LdapContextSource.class);
String[] urls = (String[]) ReflectionTestUtils.getField(contextSource, String[] urls = getUrls(contextSource);
"urls");
assertThat(urls).containsExactly("ldap://localhost:123"); assertThat(urls).containsExactly("ldap://localhost:123");
}); });
} }
...@@ -76,8 +74,7 @@ public class LdapAutoConfigurationTests { ...@@ -76,8 +74,7 @@ public class LdapAutoConfigurationTests {
ContextSource contextSource = context ContextSource contextSource = context
.getBean(LdapContextSource.class); .getBean(LdapContextSource.class);
LdapProperties ldapProperties = context.getBean(LdapProperties.class); LdapProperties ldapProperties = context.getBean(LdapProperties.class);
String[] urls = (String[]) ReflectionTestUtils.getField(contextSource, String[] urls = getUrls(contextSource);
"urls");
assertThat(urls).containsExactly("ldap://localhost:123", assertThat(urls).containsExactly("ldap://localhost:123",
"ldap://mycompany:123"); "ldap://mycompany:123");
assertThat(ldapProperties.getUrls()).hasSize(2); assertThat(ldapProperties.getUrls()).hasSize(2);
...@@ -117,13 +114,16 @@ public class LdapAutoConfigurationTests { ...@@ -117,13 +114,16 @@ public class LdapAutoConfigurationTests {
.run((context) -> { .run((context) -> {
LdapContextSource contextSource = context LdapContextSource contextSource = context
.getBean(LdapContextSource.class); .getBean(LdapContextSource.class);
String[] urls = (String[]) ReflectionTestUtils.getField(contextSource, String[] urls = getUrls(contextSource);
"urls");
assertThat(urls).containsExactly("ldap://localhost:389"); assertThat(urls).containsExactly("ldap://localhost:389");
assertThat(contextSource.isAnonymousReadOnly()).isFalse(); assertThat(contextSource.isAnonymousReadOnly()).isFalse();
}); });
} }
private String[] getUrls(ContextSource contextSource) {
return (String[]) ReflectionTestUtils.getField(contextSource, "urls");
}
@Configuration @Configuration
static class PooledContextSourceConfig { static class PooledContextSourceConfig {
......
...@@ -180,9 +180,8 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat ...@@ -180,9 +180,8 @@ public class SessionAutoConfigurationTests extends AbstractSessionAutoConfigurat
.getField(filter, "httpSessionIdResolver"); .getField(filter, "httpSessionIdResolver");
DefaultCookieSerializer cookieSerializer = (DefaultCookieSerializer) ReflectionTestUtils DefaultCookieSerializer cookieSerializer = (DefaultCookieSerializer) ReflectionTestUtils
.getField(sessionIdResolver, "cookieSerializer"); .getField(sessionIdResolver, "cookieSerializer");
String cookieName = (String) ReflectionTestUtils.getField(cookieSerializer, assertThat(cookieSerializer).hasFieldOrPropertyWithValue("cookieName",
"cookieName"); "testname");
assertThat(cookieName).isEqualTo("testname");
}); });
} }
......
/* /*
* 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.
...@@ -63,8 +63,7 @@ public class RestartApplicationListenerTests { ...@@ -63,8 +63,7 @@ public class RestartApplicationListenerTests {
@Test @Test
public void initializeWithReady() { public void initializeWithReady() {
testInitialize(false); testInitialize(false);
assertThat(ReflectionTestUtils.getField(Restarter.getInstance(), "args")) assertThat(Restarter.getInstance()).hasFieldOrPropertyWithValue("args", ARGS);
.isEqualTo(ARGS);
assertThat(Restarter.getInstance().isFinished()).isTrue(); assertThat(Restarter.getInstance().isFinished()).isTrue();
assertThat((List<?>) ReflectionTestUtils.getField(Restarter.getInstance(), assertThat((List<?>) ReflectionTestUtils.getField(Restarter.getInstance(),
"rootContexts")).isNotEmpty(); "rootContexts")).isNotEmpty();
...@@ -73,8 +72,7 @@ public class RestartApplicationListenerTests { ...@@ -73,8 +72,7 @@ public class RestartApplicationListenerTests {
@Test @Test
public void initializeWithFail() { public void initializeWithFail() {
testInitialize(true); testInitialize(true);
assertThat(ReflectionTestUtils.getField(Restarter.getInstance(), "args")) assertThat(Restarter.getInstance()).hasFieldOrPropertyWithValue("args", ARGS);
.isEqualTo(ARGS);
assertThat(Restarter.getInstance().isFinished()).isTrue(); assertThat(Restarter.getInstance().isFinished()).isTrue();
assertThat((List<?>) ReflectionTestUtils.getField(Restarter.getInstance(), assertThat((List<?>) ReflectionTestUtils.getField(Restarter.getInstance(),
"rootContexts")).isEmpty(); "rootContexts")).isEmpty();
...@@ -84,8 +82,7 @@ public class RestartApplicationListenerTests { ...@@ -84,8 +82,7 @@ public class RestartApplicationListenerTests {
public void disableWithSystemProperty() { public void disableWithSystemProperty() {
System.setProperty(ENABLED_PROPERTY, "false"); System.setProperty(ENABLED_PROPERTY, "false");
testInitialize(false); testInitialize(false);
assertThat(ReflectionTestUtils.getField(Restarter.getInstance(), "enabled")) assertThat(Restarter.getInstance()).hasFieldOrPropertyWithValue("enabled", false);
.isEqualTo(false);
} }
private void testInitialize(boolean failed) { private void testInitialize(boolean failed) {
......
/* /*
* 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.
...@@ -29,7 +29,6 @@ import org.springframework.context.annotation.Configuration; ...@@ -29,7 +29,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.RequestContextHolder;
...@@ -78,8 +77,8 @@ public class SpringBootTestWebEnvironmentMockTests { ...@@ -78,8 +77,8 @@ public class SpringBootTestWebEnvironmentMockTests {
@Test @Test
public void resourcePath() { public void resourcePath() {
assertThat(ReflectionTestUtils.getField(this.servletContext, "resourceBasePath")) assertThat(this.servletContext).hasFieldOrPropertyWithValue("resourceBasePath",
.isEqualTo("src/main/webapp"); "src/main/webapp");
} }
@Configuration @Configuration
......
/* /*
* 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.
...@@ -29,7 +29,6 @@ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; ...@@ -29,7 +29,6 @@ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
...@@ -51,8 +50,8 @@ public class SpringBootTestWebEnvironmentMockWithWebAppConfigurationTests { ...@@ -51,8 +50,8 @@ public class SpringBootTestWebEnvironmentMockWithWebAppConfigurationTests {
@Test @Test
public void resourcePath() { public void resourcePath() {
assertThat(ReflectionTestUtils.getField(this.servletContext, "resourceBasePath")) assertThat(this.servletContext).hasFieldOrPropertyWithValue("resourceBasePath",
.isEqualTo("src/mymain/mywebapp"); "src/mymain/mywebapp");
} }
@Configuration @Configuration
......
...@@ -372,10 +372,8 @@ public class TestRestTemplateTests { ...@@ -372,10 +372,8 @@ public class TestRestTemplateTests {
assertThat(requestFactoryInterceptors).hasSize(1); assertThat(requestFactoryInterceptors).hasSize(1);
ClientHttpRequestInterceptor interceptor = requestFactoryInterceptors.get(0); ClientHttpRequestInterceptor interceptor = requestFactoryInterceptors.get(0);
assertThat(interceptor).isInstanceOf(BasicAuthorizationInterceptor.class); assertThat(interceptor).isInstanceOf(BasicAuthorizationInterceptor.class);
assertThat(ReflectionTestUtils.getField(interceptor, "username")) assertThat(interceptor).hasFieldOrPropertyWithValue("username", username);
.isEqualTo(username); assertThat(interceptor).hasFieldOrPropertyWithValue("password", password);
assertThat(ReflectionTestUtils.getField(interceptor, "password"))
.isEqualTo(password);
} }
......
...@@ -25,7 +25,6 @@ import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions ...@@ -25,7 +25,6 @@ import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions
import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner; import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner;
import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.ws.transport.WebServiceMessageSender; import org.springframework.ws.transport.WebServiceMessageSender;
import org.springframework.ws.transport.http.ClientHttpRequestMessageSender; import org.springframework.ws.transport.http.ClientHttpRequestMessageSender;
...@@ -56,10 +55,8 @@ public class HttpWebServiceMessageSenderBuilderSimpleIntegrationTests { ...@@ -56,10 +55,8 @@ public class HttpWebServiceMessageSenderBuilderSimpleIntegrationTests {
.setReadTimeout(Duration.ofSeconds(2)).build(); .setReadTimeout(Duration.ofSeconds(2)).build();
SimpleClientHttpRequestFactory requestFactory = assertSimpleClientRequestFactory( SimpleClientHttpRequestFactory requestFactory = assertSimpleClientRequestFactory(
messageSender); messageSender);
assertThat(ReflectionTestUtils.getField(requestFactory, "connectTimeout")) assertThat(requestFactory).hasFieldOrPropertyWithValue("connectTimeout", 5000);
.isEqualTo(5000); assertThat(requestFactory).hasFieldOrPropertyWithValue("readTimeout", 2000);
assertThat(ReflectionTestUtils.getField(requestFactory, "readTimeout"))
.isEqualTo(2000);
} }
private SimpleClientHttpRequestFactory assertSimpleClientRequestFactory( private SimpleClientHttpRequestFactory assertSimpleClientRequestFactory(
......
...@@ -56,10 +56,8 @@ public class HttpWebServiceMessageSenderBuilderTests { ...@@ -56,10 +56,8 @@ public class HttpWebServiceMessageSenderBuilderTests {
.setReadTimeout(Duration.ofSeconds(2))); .setReadTimeout(Duration.ofSeconds(2)));
SimpleClientHttpRequestFactory requestFactory = (SimpleClientHttpRequestFactory) messageSender SimpleClientHttpRequestFactory requestFactory = (SimpleClientHttpRequestFactory) messageSender
.getRequestFactory(); .getRequestFactory();
assertThat(ReflectionTestUtils.getField(requestFactory, "connectTimeout")) assertThat(requestFactory).hasFieldOrPropertyWithValue("connectTimeout", 5000);
.isEqualTo(5000); assertThat(requestFactory).hasFieldOrPropertyWithValue("readTimeout", 2000);
assertThat(ReflectionTestUtils.getField(requestFactory, "readTimeout"))
.isEqualTo(2000);
} }
@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