|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2019 the original author or authors. |
| 2 | + * Copyright 2002-2022 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
17 | 17 | package org.springframework.test.web.servlet.samples.spr;
|
18 | 18 |
|
19 | 19 | import org.junit.jupiter.api.Test;
|
20 |
| -import org.junit.jupiter.api.extension.ExtendWith; |
21 | 20 |
|
22 |
| -import org.springframework.beans.factory.annotation.Autowired; |
23 | 21 | import org.springframework.context.annotation.Configuration;
|
24 |
| -import org.springframework.test.context.ContextConfiguration; |
25 |
| -import org.springframework.test.context.junit.jupiter.SpringExtension; |
26 |
| -import org.springframework.test.context.web.WebAppConfiguration; |
| 22 | +import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig; |
27 | 23 | import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
28 | 24 | import org.springframework.web.context.WebApplicationContext;
|
29 | 25 | import org.springframework.web.filter.CharacterEncodingFilter;
|
30 | 26 | import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
31 |
| -import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
32 | 27 |
|
| 28 | +import static org.assertj.core.api.Assertions.assertThatNoException; |
33 | 29 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
34 | 30 |
|
35 | 31 | /**
|
36 | 32 | * Test for SPR-10277 (multiple method chaining when building MockMvc).
|
37 | 33 | *
|
38 | 34 | * @author Wesley Hall
|
39 | 35 | */
|
40 |
| -@ExtendWith(SpringExtension.class) |
41 |
| -@WebAppConfiguration |
42 |
| -@ContextConfiguration |
43 |
| -public class MockMvcBuilderMethodChainTests { |
44 |
| - |
45 |
| - @Autowired |
46 |
| - private WebApplicationContext wac; |
| 36 | +@SpringJUnitWebConfig |
| 37 | +class MockMvcBuilderMethodChainTests { |
47 | 38 |
|
48 | 39 | @Test
|
49 |
| - public void chainMultiple() { |
50 |
| - MockMvcBuilders |
| 40 | + void chainMultiple(WebApplicationContext wac) { |
| 41 | + assertThatNoException().isThrownBy(() -> |
| 42 | + MockMvcBuilders |
51 | 43 | .webAppContextSetup(wac)
|
52 | 44 | .addFilter(new CharacterEncodingFilter() )
|
53 | 45 | .defaultRequest(get("/").contextPath("/mywebapp"))
|
54 |
| - .build(); |
| 46 | + .build() |
| 47 | + ); |
55 | 48 | }
|
56 | 49 |
|
57 | 50 | @Configuration
|
58 | 51 | @EnableWebMvc
|
59 |
| - static class WebConfig implements WebMvcConfigurer { |
| 52 | + static class WebConfig { |
60 | 53 | }
|
61 | 54 |
|
62 | 55 | }
|
0 commit comments