2020
2121import jakarta .servlet .http .Cookie ;
2222import jakarta .servlet .http .HttpServletResponse ;
23- import org .junit .jupiter .api .BeforeEach ;
2423import 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 ;
2925import org .springframework .test .web .servlet .MockMvc ;
3026import org .springframework .test .web .servlet .setup .MockMvcBuilders ;
3127import org .springframework .web .bind .annotation .CookieValue ;
3228import org .springframework .web .bind .annotation .GetMapping ;
3329import 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