Skip to content

Commit

Permalink
Fix DefaultMockMvcBuilder fluent API generic type
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Wesley Hall authored and rstoyanchev committed Mar 1, 2013
1 parent c611083 commit fbac428
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* @author Rob Winch
* @since 3.2
*/
public class DefaultMockMvcBuilder<Self extends MockMvcBuilder> extends MockMvcBuilderSupport
public class DefaultMockMvcBuilder<Self extends DefaultMockMvcBuilder> extends MockMvcBuilderSupport
implements MockMvcBuilder {

private final WebApplicationContext webAppContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.springframework.test.web.servlet.setup;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
* Test for SPR-10277 (Multiple method chaining when building MockMvc).
*
* @author Wesley Hall
*/
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration
public class Spr10277Tests {

@Autowired
private WebApplicationContext wac;

@Test
public void chainMultiple() {
MockMvcBuilders
.webAppContextSetup(wac)
.addFilter(new CharacterEncodingFilter() )
.defaultRequest(get("/").contextPath("/mywebapp"))
.build();
}

@Configuration
@EnableWebMvc
static class WebConfig extends WebMvcConfigurerAdapter {
}
}

0 comments on commit fbac428

Please sign in to comment.