diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestWithoutJacksonIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestWithoutJacksonIntegrationTests.java index b2e89629da1..1c50e1a261c 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestWithoutJacksonIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestWithoutJacksonIntegrationTests.java @@ -17,15 +17,18 @@ package org.springframework.boot.test.autoconfigure.web.client; import org.junit.Test; -import org.junit.runner.JUnitCore; -import org.junit.runner.Result; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions; import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner; +import org.springframework.http.MediaType; +import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.util.ClassUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; /** * Tests for {@link RestClientTest @RestClientTest} without Jackson. @@ -34,15 +37,21 @@ import static org.assertj.core.api.Assertions.assertThat; */ @RunWith(ModifiedClassPathRunner.class) @ClassPathExclusions("jackson-*.jar") +@RestClientTest(ExampleRestClient.class) public class RestClientTestWithoutJacksonIntegrationTests { + @Autowired + private MockRestServiceServer server; + + @Autowired + private ExampleRestClient client; + @Test public void restClientTestCanBeUsedWhenJacksonIsNotOnTheClassPath() { - assertThat(ClassUtils.isPresent("com.fasterxml.jackson.databind.Module", getClass().getClassLoader())) - .isFalse(); - Result result = JUnitCore.runClasses(RestClientTestWithComponentIntegrationTests.class); - assertThat(result.getFailureCount()).isEqualTo(0); - assertThat(result.getRunCount()).isGreaterThan(0); + ClassLoader classLoader = getClass().getClassLoader(); + assertThat(ClassUtils.isPresent("com.fasterxml.jackson.databind.Module", classLoader)).isFalse(); + this.server.expect(requestTo("/test")).andRespond(withSuccess("hello", MediaType.TEXT_HTML)); + assertThat(this.client.test()).isEqualTo("hello"); } }