3737import org .springframework .test .web .servlet .MockMvc ;
3838import org .springframework .test .web .servlet .MockMvcBuilder ;
3939import org .springframework .test .web .servlet .setup .DefaultMockMvcBuilder ;
40- import org .springframework .test .web .servlet .setup .MockMvcBuilders ;
4140import org .springframework .test .web .servlet .setup .RouterFunctionMockMvcBuilder ;
4241import org .springframework .test .web .servlet .setup .StandaloneMockMvcBuilder ;
4342import org .springframework .util .MultiValueMap ;
5150 * Client for testing web servers.
5251 *
5352 * @author Rob Worsnop
53+ * @author Rossen Stoyanchev
54+ * @since 7.0
5455 */
5556public interface RestTestClient {
5657
@@ -126,9 +127,8 @@ public interface RestTestClient {
126127 * {@link org.springframework.test.web.servlet.setup.MockMvcBuilders#standaloneSetup(Object...)}
127128 * to initialize {@link MockMvc}.
128129 */
129- static MockServerBuilder <StandaloneMockMvcBuilder > standaloneSetup (Object ... controllers ) {
130- StandaloneMockMvcBuilder builder = MockMvcBuilders .standaloneSetup (controllers );
131- return new DefaultMockServerBuilder <>(builder );
130+ static StandaloneSetupBuilder bindToController (Object ... controllers ) {
131+ return new DefaultRestTestClientBuilder .DefaultStandaloneSetupBuilder (controllers );
132132 }
133133
134134 /**
@@ -138,9 +138,8 @@ static MockServerBuilder<StandaloneMockMvcBuilder> standaloneSetup(Object... con
138138 * {@link org.springframework.test.web.servlet.setup.MockMvcBuilders#routerFunctions(RouterFunction[])}
139139 * to initialize {@link MockMvc}.
140140 */
141- static MockServerBuilder <RouterFunctionMockMvcBuilder > bindToRouterFunction (RouterFunction <?>... routerFunctions ) {
142- RouterFunctionMockMvcBuilder builder = MockMvcBuilders .routerFunctions (routerFunctions );
143- return new DefaultMockServerBuilder <>(builder );
141+ static RouterFunctionSetupBuilder bindToRouterFunction (RouterFunction <?>... routerFunctions ) {
142+ return new DefaultRestTestClientBuilder .DefaultRouterFunctionSetupBuilder (routerFunctions );
144143 }
145144
146145 /**
@@ -151,16 +150,15 @@ static MockServerBuilder<RouterFunctionMockMvcBuilder> bindToRouterFunction(Rout
151150 * {@link org.springframework.test.web.servlet.setup.MockMvcBuilders#webAppContextSetup(WebApplicationContext)}
152151 * to initialize {@code MockMvc}.
153152 */
154- static MockServerBuilder <DefaultMockMvcBuilder > bindToApplicationContext (WebApplicationContext context ) {
155- DefaultMockMvcBuilder builder = MockMvcBuilders .webAppContextSetup (context );
156- return new DefaultMockServerBuilder <>(builder );
153+ static WebAppContextSetupBuilder bindToApplicationContext (WebApplicationContext context ) {
154+ return new DefaultRestTestClientBuilder .DefaultWebAppContextSetupBuilder (context );
157155 }
158156
159157 /**
160158 * Begin creating a {@link RestTestClient} by providing an already
161159 * initialized {@link MockMvc} instance to use as the server.
162160 */
163- static < B extends Builder <B >> Builder < B > bindTo (MockMvc mockMvc ) {
161+ static Builder <? > bindTo (MockMvc mockMvc ) {
164162 ClientHttpRequestFactory requestFactory = new MockMvcClientHttpRequestFactory (mockMvc );
165163 return RestTestClient .bindToServer (requestFactory );
166164 }
@@ -175,15 +173,15 @@ static <B extends Builder<B>> Builder<B> bindTo(MockMvc mockMvc) {
175173 * </pre>
176174 * @return chained API to customize client config
177175 */
178- static < B extends Builder <B >> Builder < B > bindToServer () {
176+ static Builder <? > bindToServer () {
179177 return new DefaultRestTestClientBuilder <>();
180178 }
181179
182180 /**
183181 * A variant of {@link #bindToServer()} with a pre-configured request factory.
184182 * @return chained API to customize client config
185183 */
186- static < B extends Builder <B >> Builder < B > bindToServer (ClientHttpRequestFactory requestFactory ) {
184+ static Builder <? > bindToServer (ClientHttpRequestFactory requestFactory ) {
187185 return new DefaultRestTestClientBuilder <>(RestClient .builder ().requestFactory (requestFactory ));
188186 }
189187
@@ -195,20 +193,20 @@ interface Builder<B extends Builder<B>> {
195193 * {@link RestClient#create(String)
196194 * WebClient.create(String)}.
197195 */
198- Builder < B > baseUrl (String baseUrl );
196+ < T extends B > T baseUrl (String baseUrl );
199197
200198 /**
201199 * Provide a pre-configured {@link UriBuilderFactory} instance as an
202200 * alternative to and effectively overriding {@link #baseUrl(String)}.
203201 */
204- Builder < B > uriBuilderFactory (UriBuilderFactory uriBuilderFactory );
202+ < T extends B > T uriBuilderFactory (UriBuilderFactory uriBuilderFactory );
205203
206204 /**
207205 * Add the given header to all requests that haven't added it.
208206 * @param headerName the header name
209207 * @param headerValues the header values
210208 */
211- Builder < B > defaultHeader (String headerName , String ... headerValues );
209+ < T extends B > T defaultHeader (String headerName , String ... headerValues );
212210
213211 /**
214212 * Manipulate the default headers with the given consumer. The
@@ -219,14 +217,14 @@ interface Builder<B extends Builder<B>> {
219217 * @param headersConsumer a function that consumes the {@code HttpHeaders}
220218 * @return this builder
221219 */
222- Builder < B > defaultHeaders (Consumer <HttpHeaders > headersConsumer );
220+ < T extends B > T defaultHeaders (Consumer <HttpHeaders > headersConsumer );
223221
224222 /**
225223 * Add the given cookie to all requests.
226224 * @param cookieName the cookie name
227225 * @param cookieValues the cookie values
228226 */
229- Builder < B > defaultCookie (String cookieName , String ... cookieValues );
227+ < T extends B > T defaultCookie (String cookieName , String ... cookieValues );
230228
231229 /**
232230 * Manipulate the default cookies with the given consumer. The
@@ -237,29 +235,41 @@ interface Builder<B extends Builder<B>> {
237235 * @param cookiesConsumer a function that consumes the cookies map
238236 * @return this builder
239237 */
240- Builder < B > defaultCookies (Consumer <MultiValueMap <String , String >> cookiesConsumer );
238+ < T extends B > T defaultCookies (Consumer <MultiValueMap <String , String >> cookiesConsumer );
241239
242240 /**
243241 * Apply the given {@code Consumer} to this builder instance.
244242 * <p>This can be useful for applying pre-packaged customizations.
245243 * @param builderConsumer the consumer to apply
246244 */
247- Builder < B > apply (Consumer <Builder <B >> builderConsumer );
245+ < T extends B > T apply (Consumer <Builder <B >> builderConsumer );
248246
249247 /**
250248 * Build the {@link RestTestClient} instance.
251249 */
252250 RestTestClient build ();
251+ }
252+
253+
254+ interface MockMvcSetupBuilder <B extends Builder <B >, M extends MockMvcBuilder > extends Builder <B > {
255+
256+ <T extends B > T configureServer (Consumer <M > consumer );
257+ }
258+
259+
260+ interface StandaloneSetupBuilder extends MockMvcSetupBuilder <StandaloneSetupBuilder , StandaloneMockMvcBuilder > {
253261 }
254262
255263
256- interface MockServerBuilder <M extends MockMvcBuilder > extends Builder <MockServerBuilder <M >> {
264+ interface RouterFunctionSetupBuilder extends MockMvcSetupBuilder <RouterFunctionSetupBuilder , RouterFunctionMockMvcBuilder > {
265+ }
257266
258- MockServerBuilder <M > configureServer (Consumer <M > consumer );
259267
268+ interface WebAppContextSetupBuilder extends MockMvcSetupBuilder <WebAppContextSetupBuilder , DefaultMockMvcBuilder > {
260269 }
261270
262271
272+
263273 /**
264274 * Specification for providing the URI of a request.
265275 *
0 commit comments