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.reflect.OperationMethod;
import org.springframework.lang.Nullable;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
@ -124,9 +123,8 @@ public class CachingOperationInvokerAdvisorTests {
OperationInvoker advised = this.advisor.apply("foo", OperationType.READ,
parameters, this.invoker);
assertThat(advised).isInstanceOf(CachingOperationInvoker.class);
assertThat(ReflectionTestUtils.getField(advised, "invoker"))
.isEqualTo(this.invoker);
assertThat(ReflectionTestUtils.getField(advised, "timeToLive")).isEqualTo(100L);
assertThat(advised).hasFieldOrPropertyWithValue("invoker", this.invoker);
assertThat(advised).hasFieldOrPropertyWithValue("timeToLive", 100L);
}
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.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@ -478,8 +477,8 @@ public class JacksonAutoConfigurationTests {
.getBean(ObjectMapper.class).getDeserializationConfig();
AnnotationIntrospector annotationIntrospector = deserializationConfig
.getAnnotationIntrospector().allIntrospectors().iterator().next();
assertThat(ReflectionTestUtils.getField(annotationIntrospector,
"creatorBinding")).isEqualTo(expectedMode);
assertThat(annotationIntrospector)
.hasFieldOrPropertyWithValue("creatorBinding", expectedMode);
});
}

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

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

Loading…
Cancel
Save