Skip to content

Commit ee41ebc

Browse files
committed
Polish MockMvcReuseTests
1 parent 885f6db commit ee41ebc

File tree

1 file changed

+19
-26
lines changed

1 file changed

+19
-26
lines changed

spring-test/src/test/java/org/springframework/test/web/servlet/MockMvcReuseTests.java

+19-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,17 +16,14 @@
1616

1717
package org.springframework.test.web.servlet;
1818

19-
import org.junit.jupiter.api.BeforeEach;
2019
import org.junit.jupiter.api.Test;
21-
import org.junit.jupiter.api.extension.ExtendWith;
20+
import org.junit.jupiter.api.TestInstance;
21+
import org.junit.jupiter.api.TestInstance.Lifecycle;
2222

23-
import org.springframework.beans.factory.annotation.Autowired;
2423
import org.springframework.context.annotation.Bean;
2524
import org.springframework.context.annotation.Configuration;
26-
import org.springframework.test.context.ContextConfiguration;
27-
import org.springframework.test.context.junit.jupiter.SpringExtension;
28-
import org.springframework.test.context.web.WebAppConfiguration;
29-
import org.springframework.web.bind.annotation.RequestMapping;
25+
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
26+
import org.springframework.web.bind.annotation.GetMapping;
3027
import org.springframework.web.bind.annotation.RestController;
3128
import org.springframework.web.context.WebApplicationContext;
3229
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@@ -47,29 +44,25 @@
4744
* @author Rob Winch
4845
* @since 4.2
4946
*/
50-
@ExtendWith(SpringExtension.class)
51-
@ContextConfiguration
52-
@WebAppConfiguration
53-
public class MockMvcReuseTests {
47+
@SpringJUnitWebConfig
48+
@TestInstance(Lifecycle.PER_CLASS)
49+
class MockMvcReuseTests {
5450

5551
private static final String HELLO = "hello";
5652
private static final String ENIGMA = "enigma";
5753
private static final String FOO = "foo";
5854
private static final String BAR = "bar";
5955

60-
@Autowired
61-
private WebApplicationContext wac;
56+
private final MockMvc mvc;
6257

63-
private MockMvc mvc;
6458

65-
66-
@BeforeEach
67-
public void setUp() {
68-
this.mvc = webAppContextSetup(this.wac).build();
59+
MockMvcReuseTests(WebApplicationContext wac) {
60+
this.mvc = webAppContextSetup(wac).build();
6961
}
7062

63+
7164
@Test
72-
public void sessionAttributesAreClearedBetweenInvocations() throws Exception {
65+
void sessionAttributesAreClearedBetweenInvocations() throws Exception {
7366

7467
this.mvc.perform(get("/"))
7568
.andExpect(content().string(HELLO))
@@ -85,7 +78,7 @@ public void sessionAttributesAreClearedBetweenInvocations() throws Exception {
8578
}
8679

8780
@Test
88-
public void requestParametersAreClearedBetweenInvocations() throws Exception {
81+
void requestParametersAreClearedBetweenInvocations() throws Exception {
8982
this.mvc.perform(get("/"))
9083
.andExpect(content().string(HELLO));
9184

@@ -102,21 +95,21 @@ public void requestParametersAreClearedBetweenInvocations() throws Exception {
10295
static class Config {
10396

10497
@Bean
105-
public MyController myController() {
98+
MyController myController() {
10699
return new MyController();
107100
}
108101
}
109102

110103
@RestController
111104
static class MyController {
112105

113-
@RequestMapping("/")
114-
public String hello() {
106+
@GetMapping("/")
107+
String hello() {
115108
return HELLO;
116109
}
117110

118-
@RequestMapping(path = "/", params = ENIGMA)
119-
public String enigma() {
111+
@GetMapping(path = "/", params = ENIGMA)
112+
String enigma() {
120113
return ENIGMA;
121114
}
122115
}

0 commit comments

Comments
 (0)