Skip to content

Commit 81d6921

Browse files
committed
Rename to MockMvcRestTestClientTests and remove use of SpringExtension
The MockMvcClientHttpRequestFactoryTests variant for RestTestClient was copied from MockMvcClientHttpRequestFactoryTests which actually uses MockMvcClientHttpRequestFactory. In addition, MockMvcClientHttpRequestFactoryTests unnecessarily used the SpringExtension. This commit therefore renames the class to MockMvcRestTestClientTests and removes the use of the SpringExtension. See gh-29122
1 parent 80b7a34 commit 81d6921

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed
Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,34 @@
2020

2121
import jakarta.servlet.http.Cookie;
2222
import jakarta.servlet.http.HttpServletResponse;
23-
import org.junit.jupiter.api.BeforeEach;
2423
import org.junit.jupiter.api.Test;
25-
import org.junit.jupiter.api.extension.ExtendWith;
2624

27-
import org.springframework.test.context.junit.jupiter.SpringExtension;
28-
import org.springframework.test.web.client.MockMvcClientHttpRequestFactory;
2925
import org.springframework.test.web.servlet.MockMvc;
3026
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
3127
import org.springframework.web.bind.annotation.CookieValue;
3228
import org.springframework.web.bind.annotation.GetMapping;
3329
import org.springframework.web.bind.annotation.RestController;
3430

3531
/**
36-
* Tests that use a {@link RestTestClient} configured with a
37-
* {@link MockMvcClientHttpRequestFactory} that is in turn configured with a
38-
* {@link MockMvc} instance that uses a standalone controller
32+
* Tests that use a {@link RestTestClient} configured with a {@link MockMvc} instance
33+
* that uses a standalone controller.
3934
*
4035
* @author Rob Worsnop
36+
* @author Sam Brannen
37+
* @since 7.0
4138
*/
42-
@ExtendWith(SpringExtension.class)
43-
public class MockMvcClientHttpRequestFactoryTests {
39+
class MockMvcRestTestClientTests {
4440

45-
private RestTestClient client;
41+
private final RestTestClient client;
4642

47-
@BeforeEach
48-
public void setup() {
43+
MockMvcRestTestClientTests() {
4944
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new TestController()).build();
5045
this.client = RestTestClient.bindTo(mockMvc).build();
5146
}
5247

48+
5349
@Test
54-
public void withResult() {
50+
void withResult() {
5551
client.get()
5652
.uri("/foo")
5753
.cookie("session", "12345")
@@ -62,7 +58,7 @@ public void withResult() {
6258
}
6359

6460
@Test
65-
public void withError() {
61+
void withError() {
6662
client.get()
6763
.uri("/error")
6864
.exchange()
@@ -71,7 +67,7 @@ public void withError() {
7167
}
7268

7369
@Test
74-
public void withErrorAndBody() {
70+
void withErrorAndBody() {
7571
client.get().uri("/errorbody")
7672
.exchange()
7773
.expectStatus().isBadRequest()
@@ -82,19 +78,19 @@ public void withErrorAndBody() {
8278
@RestController
8379
static class TestController {
8480

85-
@GetMapping(value = "/foo")
86-
public void foo(@CookieValue("session") String session, HttpServletResponse response) throws IOException {
81+
@GetMapping("/foo")
82+
void foo(@CookieValue("session") String session, HttpServletResponse response) throws IOException {
8783
response.getWriter().write("bar");
8884
response.addCookie(new Cookie("session", session));
8985
}
9086

91-
@GetMapping(value = "/error")
92-
public void handleError(HttpServletResponse response) throws Exception {
87+
@GetMapping("/error")
88+
void handleError(HttpServletResponse response) throws Exception {
9389
response.sendError(400);
9490
}
9591

96-
@GetMapping(value = "/errorbody")
97-
public void handleErrorWithBody(HttpServletResponse response) throws Exception {
92+
@GetMapping("/errorbody")
93+
void handleErrorWithBody(HttpServletResponse response) throws Exception {
9894
response.sendError(400);
9995
response.getWriter().write("some really bad request");
10096
}

0 commit comments

Comments
 (0)