|
17 | 17 | package org.springframework.boot.test.autoconfigure.web.client;
|
18 | 18 |
|
19 | 19 | import org.junit.Test;
|
20 |
| -import org.junit.runner.JUnitCore; |
21 |
| -import org.junit.runner.Result; |
22 | 20 | import org.junit.runner.RunWith;
|
23 | 21 |
|
| 22 | +import org.springframework.beans.factory.annotation.Autowired; |
24 | 23 | import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions;
|
25 | 24 | import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner;
|
| 25 | +import org.springframework.http.MediaType; |
| 26 | +import org.springframework.test.web.client.MockRestServiceServer; |
26 | 27 | import org.springframework.util.ClassUtils;
|
27 | 28 |
|
28 | 29 | import static org.assertj.core.api.Assertions.assertThat;
|
| 30 | +import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; |
| 31 | +import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; |
29 | 32 |
|
30 | 33 | /**
|
31 | 34 | * Tests for {@link RestClientTest @RestClientTest} without Jackson.
|
|
34 | 37 | */
|
35 | 38 | @RunWith(ModifiedClassPathRunner.class)
|
36 | 39 | @ClassPathExclusions("jackson-*.jar")
|
| 40 | +@RestClientTest(ExampleRestClient.class) |
37 | 41 | public class RestClientTestWithoutJacksonIntegrationTests {
|
38 | 42 |
|
| 43 | + @Autowired |
| 44 | + private MockRestServiceServer server; |
| 45 | + |
| 46 | + @Autowired |
| 47 | + private ExampleRestClient client; |
| 48 | + |
39 | 49 | @Test
|
40 | 50 | public void restClientTestCanBeUsedWhenJacksonIsNotOnTheClassPath() {
|
41 |
| - assertThat(ClassUtils.isPresent("com.fasterxml.jackson.databind.Module", getClass().getClassLoader())) |
42 |
| - .isFalse(); |
43 |
| - Result result = JUnitCore.runClasses(RestClientTestWithComponentIntegrationTests.class); |
44 |
| - assertThat(result.getFailureCount()).isEqualTo(0); |
45 |
| - assertThat(result.getRunCount()).isGreaterThan(0); |
| 51 | + ClassLoader classLoader = getClass().getClassLoader(); |
| 52 | + assertThat(ClassUtils.isPresent("com.fasterxml.jackson.databind.Module", classLoader)).isFalse(); |
| 53 | + this.server.expect(requestTo("/test")).andRespond(withSuccess("hello", MediaType.TEXT_HTML)); |
| 54 | + assertThat(this.client.test()).isEqualTo("hello"); |
46 | 55 | }
|
47 | 56 |
|
48 | 57 | }
|
0 commit comments