Skip to content

Commit 960df8e

Browse files
committed
Merge branch '6.2.x'
2 parents 0912497 + 661dca5 commit 960df8e

File tree

2 files changed

+20
-36
lines changed

2 files changed

+20
-36
lines changed

spring-test/src/test/java/org/springframework/test/context/web/ServletContextAwareBeanWacTests.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717
package org.springframework.test.context.web;
1818

1919
import org.junit.jupiter.api.Test;
20-
import org.junit.jupiter.api.extension.ExtendWith;
2120
import org.junit.platform.testkit.engine.EngineTestKit;
2221

23-
import org.springframework.test.context.junit.jupiter.SpringExtension;
24-
2522
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
2623

2724
/**
@@ -32,7 +29,6 @@
3229
* @author Sam Brannen
3330
* @since 4.0.2
3431
*/
35-
@ExtendWith(SpringExtension.class)
3632
class ServletContextAwareBeanWacTests {
3733

3834
@Test

spring-test/src/test/java/org/springframework/test/web/client/samples/MockMvcClientHttpRequestFactoryTests.java

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,16 @@
1717
package org.springframework.test.web.client.samples;
1818

1919
import jakarta.servlet.http.HttpServletResponse;
20-
import org.junit.jupiter.api.BeforeEach;
2120
import org.junit.jupiter.api.Test;
22-
import org.junit.jupiter.api.extension.ExtendWith;
2321

24-
import org.springframework.beans.factory.annotation.Autowired;
25-
import org.springframework.context.annotation.ComponentScan;
2622
import org.springframework.context.annotation.Configuration;
23+
import org.springframework.context.annotation.Import;
2724
import org.springframework.stereotype.Controller;
28-
import org.springframework.test.context.ContextConfiguration;
29-
import org.springframework.test.context.junit.jupiter.SpringExtension;
30-
import org.springframework.test.context.web.WebAppConfiguration;
25+
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
3126
import org.springframework.test.web.client.MockMvcClientHttpRequestFactory;
3227
import org.springframework.test.web.servlet.MockMvc;
3328
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
34-
import org.springframework.web.bind.annotation.RequestMapping;
35-
import org.springframework.web.bind.annotation.RequestMethod;
29+
import org.springframework.web.bind.annotation.GetMapping;
3630
import org.springframework.web.bind.annotation.ResponseBody;
3731
import org.springframework.web.client.HttpClientErrorException;
3832
import org.springframework.web.client.RestTemplate;
@@ -52,39 +46,33 @@
5246
* @author Rossen Stoyanchev
5347
* @author Juergen Hoeller
5448
*/
55-
@ExtendWith(SpringExtension.class)
56-
@WebAppConfiguration
57-
@ContextConfiguration
49+
@SpringJUnitWebConfig
5850
@SuppressWarnings("deprecation")
59-
public class MockMvcClientHttpRequestFactoryTests {
51+
class MockMvcClientHttpRequestFactoryTests {
6052

61-
@Autowired
62-
private WebApplicationContext wac;
53+
private final RestTemplate template;
6354

64-
private RestTemplate template;
65-
66-
67-
@BeforeEach
68-
public void setup() {
69-
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
55+
MockMvcClientHttpRequestFactoryTests(WebApplicationContext wac) {
56+
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
7057
this.template = new RestTemplate(new MockMvcClientHttpRequestFactory(mockMvc));
7158
}
7259

60+
7361
@Test
74-
public void withResult() {
62+
void withResult() {
7563
assertThat(template.getForObject("/foo", String.class)).isEqualTo("bar");
7664
}
7765

7866
@Test
79-
public void withError() {
67+
void withError() {
8068
assertThatExceptionOfType(HttpClientErrorException.class)
8169
.isThrownBy(() -> template.getForEntity("/error", String.class))
8270
.withMessageContaining("400")
8371
.withMessageContaining("some bad request");
8472
}
8573

8674
@Test
87-
public void withErrorAndBody() {
75+
void withErrorAndBody() {
8876
assertThatExceptionOfType(HttpClientErrorException.class)
8977
.isThrownBy(() -> template.getForEntity("/errorbody", String.class))
9078
.withMessageContaining("400")
@@ -93,27 +81,27 @@ public void withErrorAndBody() {
9381

9482

9583
@EnableWebMvc
96-
@Configuration
97-
@ComponentScan(basePackageClasses = MockMvcClientHttpRequestFactoryTests.class)
84+
@Configuration(proxyBeanMethods = false)
85+
@Import(MyController.class)
9886
static class MyWebConfig implements WebMvcConfigurer {
9987
}
10088

10189
@Controller
10290
static class MyController {
10391

104-
@RequestMapping(value = "/foo", method = RequestMethod.GET)
92+
@GetMapping("/foo")
10593
@ResponseBody
106-
public String handle() {
94+
String handle() {
10795
return "bar";
10896
}
10997

110-
@RequestMapping(value = "/error", method = RequestMethod.GET)
111-
public void handleError(HttpServletResponse response) throws Exception {
98+
@GetMapping("/error")
99+
void handleError(HttpServletResponse response) throws Exception {
112100
response.sendError(400, "some bad request");
113101
}
114102

115-
@RequestMapping(value = "/errorbody", method = RequestMethod.GET)
116-
public void handleErrorWithBody(HttpServletResponse response) throws Exception {
103+
@GetMapping("/errorbody")
104+
void handleErrorWithBody(HttpServletResponse response) throws Exception {
117105
response.sendError(400, "some bad request");
118106
response.getWriter().write("some really bad request");
119107
}

0 commit comments

Comments
 (0)