diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/mongo/MongoMetricsAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/mongo/MongoMetricsAutoConfigurationTests.java index 8cd2eb6bfd..2e92c944cd 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/mongo/MongoMetricsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/mongo/MongoMetricsAutoConfigurationTests.java @@ -20,6 +20,7 @@ import java.util.List; import com.mongodb.MongoClientSettings; import com.mongodb.client.MongoClient; +import com.mongodb.client.internal.MongoClientImpl; import com.mongodb.connection.ConnectionPoolSettings; import com.mongodb.event.ConnectionPoolListener; import io.micrometer.core.instrument.binder.mongodb.DefaultMongoCommandTagsProvider; @@ -176,18 +177,15 @@ class MongoMetricsAutoConfigurationTests { private MongoClientSettings getActualMongoClientSettingsUsedToConstructClient( final AssertableApplicationContext context) { - final MongoClient mongoClient = context.getBean(MongoClient.class); - return (MongoClientSettings) ReflectionTestUtils.getField(mongoClient, "settings"); + final MongoClientImpl mongoClient = (MongoClientImpl) context.getBean(MongoClient.class); + return mongoClient.getSettings(); } private List getConnectionPoolListenersFromClient( final AssertableApplicationContext context) { MongoClientSettings mongoClientSettings = getActualMongoClientSettingsUsedToConstructClient(context); ConnectionPoolSettings connectionPoolSettings = mongoClientSettings.getConnectionPoolSettings(); - @SuppressWarnings("unchecked") - List listeners = (List) ReflectionTestUtils - .getField(connectionPoolSettings, "connectionPoolListeners"); - return listeners; + return connectionPoolSettings.getConnectionPoolListeners(); } private MongoCommandTagsProvider getMongoCommandTagsProviderUsedToConstructListener( diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationLettuceWithoutCommonsPool2Tests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationLettuceWithoutCommonsPool2Tests.java index 2e8c0d6481..54491ee294 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationLettuceWithoutCommonsPool2Tests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationLettuceWithoutCommonsPool2Tests.java @@ -23,7 +23,6 @@ import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.boot.testsupport.classpath.ClassPathExclusions; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration; -import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -43,8 +42,7 @@ public class RedisAutoConfigurationLettuceWithoutCommonsPool2Tests { this.contextRunner.withPropertyValues("spring.redis.host:foo").run((context) -> { LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class); assertThat(cf.getHostName()).isEqualTo("foo"); - assertThat(ReflectionTestUtils.getField(cf, "clientConfiguration")) - .isNotInstanceOf(LettucePoolingClientConfiguration.class); + assertThat(cf.getClientConfiguration()).isNotInstanceOf(LettucePoolingClientConfiguration.class); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationTests.java index 0ff6c20939..38f87eb77d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/redis/RedisAutoConfigurationTests.java @@ -207,8 +207,7 @@ class RedisAutoConfigurationTests { .run((context) -> { LettuceConnectionFactory cf = context.getBean(LettuceConnectionFactory.class); assertThat(cf.getHostName()).isEqualTo("foo"); - assertThat(ReflectionTestUtils.getField(cf, "clientConfiguration")) - .isNotInstanceOf(LettucePoolingClientConfiguration.class); + assertThat(cf.getClientConfiguration()).isNotInstanceOf(LettucePoolingClientConfiguration.class); }); } @@ -439,7 +438,7 @@ class RedisAutoConfigurationTests { } private LettucePoolingClientConfiguration getPoolingClientConfiguration(LettuceConnectionFactory factory) { - return (LettucePoolingClientConfiguration) ReflectionTestUtils.getField(factory, "clientConfiguration"); + return (LettucePoolingClientConfiguration) factory.getClientConfiguration(); } private String getUserName(LettuceConnectionFactory factory) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/HttpMessageConvertersTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/HttpMessageConvertersTests.java index f8468fa85b..fb557cfc97 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/HttpMessageConvertersTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/http/HttpMessageConvertersTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 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. @@ -33,7 +33,6 @@ import org.springframework.http.converter.smile.MappingJackson2SmileHttpMessageC import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter; import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter; import org.springframework.http.converter.xml.SourceHttpMessageConverter; -import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -143,10 +142,9 @@ class HttpMessageConvertersTests { MappingJackson2HttpMessageConverter.class, MappingJackson2SmileHttpMessageConverter.class); } - @SuppressWarnings("unchecked") private List> extractFormPartConverters(List> converters) { AllEncompassingFormHttpMessageConverter formConverter = findFormConverter(converters); - return (List>) ReflectionTestUtils.getField(formConverter, "partConverters"); + return formConverter.getPartConverters(); } private AllEncompassingFormHttpMessageConverter findFormConverter(Collection> converters) { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfigurationTests.java index e44f4cce13..b6ff9c5521 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 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. @@ -21,6 +21,7 @@ import java.util.concurrent.TimeUnit; import com.mongodb.MongoClientSettings; import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; +import com.mongodb.client.internal.MongoClientImpl; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -28,7 +29,6 @@ import org.springframework.boot.test.context.assertj.AssertableApplicationContex import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -86,8 +86,8 @@ class MongoAutoConfigurationTests { private MongoClientSettings getSettings(AssertableApplicationContext context) { assertThat(context).hasSingleBean(MongoClient.class); - MongoClient client = context.getBean(MongoClient.class); - return (MongoClientSettings) ReflectionTestUtils.getField(client, "settings"); + MongoClientImpl client = (MongoClientImpl) context.getBean(MongoClient.class); + return client.getSettings(); } @Configuration(proxyBeanMethods = false) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactoryTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactoryTests.java index 7fbddedbcd..d793db83aa 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactoryTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 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. @@ -20,8 +20,7 @@ import java.util.List; import com.mongodb.MongoClientSettings; import com.mongodb.client.MongoClient; - -import org.springframework.test.util.ReflectionTestUtils; +import com.mongodb.client.internal.MongoClientImpl; /** * Tests for {@link MongoClientFactory}. @@ -42,7 +41,7 @@ class MongoClientFactoryTests extends MongoClientFactorySupportTests { WelcomePageHandlerMapping bean = context.getBean(WelcomePageHandlerMapping.class); - UrlBasedCorsConfigurationSource source = (UrlBasedCorsConfigurationSource) ReflectionTestUtils - .getField(bean, "corsConfigurationSource"); + UrlBasedCorsConfigurationSource source = (UrlBasedCorsConfigurationSource) bean + .getCorsConfigurationSource(); assertThat(source.getCorsConfigurations()).containsKey("/**"); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/servlet/WebSocketMessagingAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/servlet/WebSocketMessagingAutoConfigurationTests.java index b66b492d1c..7043d05f39 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/servlet/WebSocketMessagingAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/servlet/WebSocketMessagingAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 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. @@ -55,7 +55,6 @@ import org.springframework.messaging.simp.stomp.StompSession; import org.springframework.messaging.simp.stomp.StompSessionHandler; import org.springframework.messaging.simp.stomp.StompSessionHandlerAdapter; import org.springframework.stereotype.Controller; -import org.springframework.test.util.ReflectionTestUtils; import org.springframework.web.client.RestTemplate; import org.springframework.web.socket.client.standard.StandardWebSocketClient; import org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration; @@ -138,13 +137,10 @@ class WebSocketMessagingAutoConfigurationTests { return customizedConverters; } - @SuppressWarnings("unchecked") private List getDefaultConverters() { DelegatingWebSocketMessageBrokerConfiguration configuration = new DelegatingWebSocketMessageBrokerConfiguration(); - // We shouldn't usually call this method directly since it's on a non-proxy config - CompositeMessageConverter compositeDefaultConverter = ReflectionTestUtils.invokeMethod(configuration, - "brokerMessageConverter"); - return (List) ReflectionTestUtils.getField(compositeDefaultConverter, "converters"); + CompositeMessageConverter compositeDefaultConverter = configuration.brokerMessageConverter(); + return compositeDefaultConverter.getConverters(); } private Object performStompSubscription(String topic) throws Throwable {