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