Update RestTestClient builder hierarchy

Add concrete classes with specified generics for each MockMvc setup
Ensure Builder methods return the concrete class

See gh-34428
This commit is contained in:
rstoyanchev
2025-07-30 07:13:48 +01:00
parent db4696ceae
commit 2732b603dc
13 changed files with 131 additions and 100 deletions
@@ -48,7 +48,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
class JsonPathAssertionTests {
private final RestTestClient client =
RestTestClient.standaloneSetup(new MusicController())
RestTestClient.bindToController(new MusicController())
.configureServer(builder ->
builder.alwaysExpect(status().isOk())
.alwaysExpect(content().contentType(MediaType.APPLICATION_JSON))
@@ -30,7 +30,7 @@ import org.springframework.web.bind.annotation.RestController;
*/
class ErrorTests {
private final RestTestClient client = RestTestClient.standaloneSetup(new TestController()).build();
private final RestTestClient client = RestTestClient.bindToController(new TestController()).build();
@Test
@@ -34,7 +34,7 @@ import org.springframework.web.bind.annotation.RestController;
*/
class HeaderAndCookieTests {
private final RestTestClient client = RestTestClient.standaloneSetup(new TestController()).build();
private final RestTestClient client = RestTestClient.bindToController(new TestController()).build();
@Test
void requestResponseHeaderPair() {
@@ -42,7 +42,7 @@ import static org.hamcrest.Matchers.containsString;
*/
class JsonContentTests {
private final RestTestClient client = RestTestClient.standaloneSetup(new PersonController()).build();
private final RestTestClient client = RestTestClient.bindToController(new PersonController()).build();
@Test
@@ -43,7 +43,7 @@ import static org.hamcrest.Matchers.startsWith;
* @author Rob Worsnop
*/
class ResponseEntityTests {
private final RestTestClient client = RestTestClient.standaloneSetup(new PersonController())
private final RestTestClient client = RestTestClient.bindToController(new PersonController())
.baseUrl("/persons")
.build();
@@ -53,7 +53,7 @@ class RestTestClientTests {
@BeforeEach
void setUp() {
this.client = RestTestClient.standaloneSetup(new TestController()).build();
this.client = RestTestClient.bindToController(new TestController()).build();
}
@Nested
@@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
*/
class SoftAssertionTests {
private final RestTestClient restTestClient = RestTestClient.standaloneSetup(new TestController()).build();
private final RestTestClient restTestClient = RestTestClient.bindToController(new TestController()).build();
@Test
@@ -58,7 +58,7 @@ class XmlContentTests {
""";
private final RestTestClient client = RestTestClient.standaloneSetup(new PersonController()).build();
private final RestTestClient client = RestTestClient.bindToController(new PersonController()).build();
@Test
@@ -36,7 +36,7 @@ class ControllerTests {
@BeforeEach
void setUp() {
this.client = RestTestClient.standaloneSetup(new TestController()).build();
this.client = RestTestClient.bindToController(new TestController()).build();
}