Replace ReflectionTestUtils usage by hasFieldOrPropertyWithValue

Closes gh-14783
pull/14497/merge
artsiom 6 years ago committed by Stephane Nicoll
parent d37df3d718
commit 8f3b58fa98

@ -30,7 +30,6 @@ import org.springframework.boot.actuate.endpoint.invoke.OperationInvoker;
import org.springframework.boot.actuate.endpoint.invoke.OperationParameters; import org.springframework.boot.actuate.endpoint.invoke.OperationParameters;
import org.springframework.boot.actuate.endpoint.invoke.reflect.OperationMethod; import org.springframework.boot.actuate.endpoint.invoke.reflect.OperationMethod;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -124,9 +123,8 @@ public class CachingOperationInvokerAdvisorTests {
OperationInvoker advised = this.advisor.apply("foo", OperationType.READ, OperationInvoker advised = this.advisor.apply("foo", OperationType.READ,
parameters, this.invoker); parameters, this.invoker);
assertThat(advised).isInstanceOf(CachingOperationInvoker.class); assertThat(advised).isInstanceOf(CachingOperationInvoker.class);
assertThat(ReflectionTestUtils.getField(advised, "invoker")) assertThat(advised).hasFieldOrPropertyWithValue("invoker", this.invoker);
.isEqualTo(this.invoker); assertThat(advised).hasFieldOrPropertyWithValue("timeToLive", 100L);
assertThat(ReflectionTestUtils.getField(advised, "timeToLive")).isEqualTo(100L);
} }
private OperationParameters getParameters(String methodName, private OperationParameters getParameters(String methodName,

@ -59,7 +59,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
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;
@ -478,8 +477,8 @@ public class JacksonAutoConfigurationTests {
.getBean(ObjectMapper.class).getDeserializationConfig(); .getBean(ObjectMapper.class).getDeserializationConfig();
AnnotationIntrospector annotationIntrospector = deserializationConfig AnnotationIntrospector annotationIntrospector = deserializationConfig
.getAnnotationIntrospector().allIntrospectors().iterator().next(); .getAnnotationIntrospector().allIntrospectors().iterator().next();
assertThat(ReflectionTestUtils.getField(annotationIntrospector, assertThat(annotationIntrospector)
"creatorBinding")).isEqualTo(expectedMode); .hasFieldOrPropertyWithValue("creatorBinding", expectedMode);
}); });
} }

@ -31,7 +31,6 @@ import org.springframework.boot.testsupport.rule.OutputCapture;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
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.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
@ -105,8 +104,7 @@ public class BannerTests {
application.setBanner(banner); application.setBanner(banner);
this.context = application.run(); this.context = application.run();
Banner printedBanner = (Banner) this.context.getBean("springBootBanner"); Banner printedBanner = (Banner) this.context.getBean("springBootBanner");
assertThat(ReflectionTestUtils.getField(printedBanner, "banner")) assertThat(printedBanner).hasFieldOrPropertyWithValue("banner", banner);
.isEqualTo(banner);
verify(banner).printBanner(any(Environment.class), verify(banner).printBanner(any(Environment.class),
this.sourceClassCaptor.capture(), any(PrintStream.class)); this.sourceClassCaptor.capture(), any(PrintStream.class));
reset(banner); reset(banner);

@ -414,8 +414,8 @@ public class RestTemplateBuilderTests {
.getRequestFactory(); .getRequestFactory();
assertThat(actualRequestFactory) assertThat(actualRequestFactory)
.isInstanceOf(InterceptingClientHttpRequestFactory.class); .isInstanceOf(InterceptingClientHttpRequestFactory.class);
assertThat(ReflectionTestUtils.getField(actualRequestFactory, assertThat(actualRequestFactory).hasFieldOrPropertyWithValue(
"requestFactory")).isSameAs(requestFactory); "requestFactory", requestFactory);
}).build(); }).build();
} }
@ -444,8 +444,7 @@ public class RestTemplateBuilderTests {
ClientHttpRequestFactory requestFactory = this.builder ClientHttpRequestFactory requestFactory = this.builder
.requestFactory(SimpleClientHttpRequestFactory.class) .requestFactory(SimpleClientHttpRequestFactory.class)
.setConnectTimeout(null).build().getRequestFactory(); .setConnectTimeout(null).build().getRequestFactory();
assertThat(ReflectionTestUtils.getField(requestFactory, "connectTimeout")) assertThat(requestFactory).hasFieldOrPropertyWithValue("connectTimeout", -1);
.isEqualTo(-1);
} }
@Test @Test
@ -453,8 +452,7 @@ public class RestTemplateBuilderTests {
ClientHttpRequestFactory requestFactory = this.builder ClientHttpRequestFactory requestFactory = this.builder
.requestFactory(SimpleClientHttpRequestFactory.class).setReadTimeout(null) .requestFactory(SimpleClientHttpRequestFactory.class).setReadTimeout(null)
.build().getRequestFactory(); .build().getRequestFactory();
assertThat(ReflectionTestUtils.getField(requestFactory, "readTimeout")) assertThat(requestFactory).hasFieldOrPropertyWithValue("readTimeout", -1);
.isEqualTo(-1);
} }
@Test @Test
@ -480,8 +478,7 @@ public class RestTemplateBuilderTests {
ClientHttpRequestFactory requestFactory = this.builder ClientHttpRequestFactory requestFactory = this.builder
.requestFactory(SimpleClientHttpRequestFactory.class) .requestFactory(SimpleClientHttpRequestFactory.class)
.setConnectTimeout(Duration.ofMillis(1234)).build().getRequestFactory(); .setConnectTimeout(Duration.ofMillis(1234)).build().getRequestFactory();
assertThat(ReflectionTestUtils.getField(requestFactory, "connectTimeout")) assertThat(requestFactory).hasFieldOrPropertyWithValue("connectTimeout", 1234);
.isEqualTo(1234);
} }
@Test @Test
@ -489,8 +486,7 @@ public class RestTemplateBuilderTests {
ClientHttpRequestFactory requestFactory = this.builder ClientHttpRequestFactory requestFactory = this.builder
.requestFactory(SimpleClientHttpRequestFactory.class) .requestFactory(SimpleClientHttpRequestFactory.class)
.setReadTimeout(Duration.ofMillis(1234)).build().getRequestFactory(); .setReadTimeout(Duration.ofMillis(1234)).build().getRequestFactory();
assertThat(ReflectionTestUtils.getField(requestFactory, "readTimeout")) assertThat(requestFactory).hasFieldOrPropertyWithValue("readTimeout", 1234);
.isEqualTo(1234);
} }
@Test @Test
@ -520,8 +516,7 @@ public class RestTemplateBuilderTests {
.requestFactory( .requestFactory(
() -> new BufferingClientHttpRequestFactory(requestFactory)) () -> new BufferingClientHttpRequestFactory(requestFactory))
.setConnectTimeout(Duration.ofMillis(1234)).build(); .setConnectTimeout(Duration.ofMillis(1234)).build();
assertThat(ReflectionTestUtils.getField(requestFactory, "connectTimeout")) assertThat(requestFactory).hasFieldOrPropertyWithValue("connectTimeout", 1234);
.isEqualTo(1234);
} }
@Test @Test
@ -531,8 +526,7 @@ public class RestTemplateBuilderTests {
.requestFactory( .requestFactory(
() -> new BufferingClientHttpRequestFactory(requestFactory)) () -> new BufferingClientHttpRequestFactory(requestFactory))
.setReadTimeout(Duration.ofMillis(1234)).build(); .setReadTimeout(Duration.ofMillis(1234)).build();
assertThat(ReflectionTestUtils.getField(requestFactory, "readTimeout")) assertThat(requestFactory).hasFieldOrPropertyWithValue("readTimeout", 1234);
.isEqualTo(1234);
} }
@Test @Test
@ -552,8 +546,7 @@ public class RestTemplateBuilderTests {
ClientHttpRequestFactory requestFactory = this.builder ClientHttpRequestFactory requestFactory = this.builder
.requestFactory(SimpleClientHttpRequestFactory.class) .requestFactory(SimpleClientHttpRequestFactory.class)
.setConnectTimeout(1234).build().getRequestFactory(); .setConnectTimeout(1234).build().getRequestFactory();
assertThat(ReflectionTestUtils.getField(requestFactory, "connectTimeout")) assertThat(requestFactory).hasFieldOrPropertyWithValue("connectTimeout", 1234);
.isEqualTo(1234);
} }
@Test @Test
@ -562,8 +555,7 @@ public class RestTemplateBuilderTests {
ClientHttpRequestFactory requestFactory = this.builder ClientHttpRequestFactory requestFactory = this.builder
.requestFactory(SimpleClientHttpRequestFactory.class).setReadTimeout(1234) .requestFactory(SimpleClientHttpRequestFactory.class).setReadTimeout(1234)
.build().getRequestFactory(); .build().getRequestFactory();
assertThat(ReflectionTestUtils.getField(requestFactory, "readTimeout")) assertThat(requestFactory).hasFieldOrPropertyWithValue("readTimeout", 1234);
.isEqualTo(1234);
} }
public static class RestTemplateSubclass extends RestTemplate { public static class RestTemplateSubclass extends RestTemplate {

Loading…
Cancel
Save