Skip to content

Commit fbac428

Browse files
Wesley Hallrstoyanchev
Wesley Hall
authored andcommitted
Fix DefaultMockMvcBuilder fluent API generic type
Changed upper bound of generic parameter for DefaultMockMvcBuilder from MockMvcBuilder to DefaultMockMvcBuilder to allow for ongoing method chaining in the fluent API style. Issue: SPR-10277
1 parent c611083 commit fbac428

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

spring-test-mvc/src/main/java/org/springframework/test/web/servlet/setup/DefaultMockMvcBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* @author Rob Winch
4343
* @since 3.2
4444
*/
45-
public class DefaultMockMvcBuilder<Self extends MockMvcBuilder> extends MockMvcBuilderSupport
45+
public class DefaultMockMvcBuilder<Self extends DefaultMockMvcBuilder> extends MockMvcBuilderSupport
4646
implements MockMvcBuilder {
4747

4848
private final WebApplicationContext webAppContext;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.springframework.test.web.servlet.setup;
2+
3+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
4+
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.context.annotation.Configuration;
9+
import org.springframework.test.context.ContextConfiguration;
10+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
11+
import org.springframework.test.context.web.WebAppConfiguration;
12+
import org.springframework.web.context.WebApplicationContext;
13+
import org.springframework.web.filter.CharacterEncodingFilter;
14+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
15+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
16+
17+
/**
18+
* Test for SPR-10277 (Multiple method chaining when building MockMvc).
19+
*
20+
* @author Wesley Hall
21+
*/
22+
@RunWith(SpringJUnit4ClassRunner.class)
23+
@WebAppConfiguration
24+
@ContextConfiguration
25+
public class Spr10277Tests {
26+
27+
@Autowired
28+
private WebApplicationContext wac;
29+
30+
@Test
31+
public void chainMultiple() {
32+
MockMvcBuilders
33+
.webAppContextSetup(wac)
34+
.addFilter(new CharacterEncodingFilter() )
35+
.defaultRequest(get("/").contextPath("/mywebapp"))
36+
.build();
37+
}
38+
39+
@Configuration
40+
@EnableWebMvc
41+
static class WebConfig extends WebMvcConfigurerAdapter {
42+
}
43+
}

0 commit comments

Comments
 (0)