diff --git a/spring-test/src/main/java/org/springframework/test/web/client/MockRestServiceServer.java b/spring-test/src/main/java/org/springframework/test/web/client/MockRestServiceServer.java index 8e0318bb253..779bc7408d3 100644 --- a/spring-test/src/main/java/org/springframework/test/web/client/MockRestServiceServer.java +++ b/spring-test/src/main/java/org/springframework/test/web/client/MockRestServiceServer.java @@ -33,9 +33,9 @@ import org.springframework.web.client.support.RestGatewaySupport; /** * Main entry point for client-side REST testing. Used for tests - * that involve direct or indirect use of the {@link RestTemplate}. Provides a + * that involve direct or indirect use of the {@link RestClient}. Provides a * way to set up expected requests that will be performed through the - * {@code RestTemplate} as well as mock responses to send back thus removing the + * {@code RestClient} as well as mock responses to send back thus removing the * need for an actual server. * *

Below is an example that assumes static imports from @@ -43,13 +43,14 @@ import org.springframework.web.client.support.RestGatewaySupport; * and {@code ExpectedCount}: * *

- * RestTemplate restTemplate = new RestTemplate()
- * MockRestServiceServer server = MockRestServiceServer.bindTo(restTemplate).build();
+ * RestClient.Builder clientBuilder = RestClient.builder();
+ * MockRestServiceServer server = MockRestServiceServer.bindTo(clientBuilder).build();
+ * RestClient restClient = clientBuilder.build();
  *
  * server.expect(manyTimes(), requestTo("/hotels/42")).andExpect(method(HttpMethod.GET))
  *     .andRespond(withSuccess("{ \"id\" : \"42\", \"name\" : \"Holiday Inn\"}", MediaType.APPLICATION_JSON));
  *
- * Hotel hotel = restTemplate.getForObject("/hotels/{id}", Hotel.class, 42);
+ * Hotel hotel = restClient.get().uri("/hotels/{id}", 42).retrieve().body(Hotel.class);
  * // Use the hotel instance...
  *
  * // Verify all expectations met
@@ -167,6 +168,16 @@ public final class MockRestServiceServer {
 	}
 
 
+	/**
+	 * A shortcut for {@code bindTo(clientBuilder).build()}.
+	 * @param clientBuilder the RestClient builder to set up for mock testing
+	 * @return the mock server
+	 * @since 7.0.7
+	 */
+	public static MockRestServiceServer createServer(RestClient.Builder clientBuilder) {
+		return bindTo(clientBuilder).build();
+	}
+
 	/**
 	 * A shortcut for {@code bindTo(restTemplate).build()}.
 	 * @param restTemplate the RestTemplate to set up for mock testing