Skip to content

Commit ca1808e

Browse files
dreis2211philwebb
authored andcommitted
Migrate to MockRestServiceServer
Migrate `RestClientTestWithoutJacksonIntegrationTests` to use Spring's `MockRestServiceServer`. See gh-17491
1 parent 1bc9c85 commit ca1808e

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/client/RestClientTestWithoutJacksonIntegrationTests.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@
1717
package org.springframework.boot.test.autoconfigure.web.client;
1818

1919
import org.junit.Test;
20-
import org.junit.runner.JUnitCore;
21-
import org.junit.runner.Result;
2220
import org.junit.runner.RunWith;
2321

22+
import org.springframework.beans.factory.annotation.Autowired;
2423
import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions;
2524
import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner;
25+
import org.springframework.http.MediaType;
26+
import org.springframework.test.web.client.MockRestServiceServer;
2627
import org.springframework.util.ClassUtils;
2728

2829
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;
2932

3033
/**
3134
* Tests for {@link RestClientTest @RestClientTest} without Jackson.
@@ -34,15 +37,21 @@
3437
*/
3538
@RunWith(ModifiedClassPathRunner.class)
3639
@ClassPathExclusions("jackson-*.jar")
40+
@RestClientTest(ExampleRestClient.class)
3741
public class RestClientTestWithoutJacksonIntegrationTests {
3842

43+
@Autowired
44+
private MockRestServiceServer server;
45+
46+
@Autowired
47+
private ExampleRestClient client;
48+
3949
@Test
4050
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");
4655
}
4756

4857
}

0 commit comments

Comments
 (0)