Browse Source

Clean up Spring MVC Test Framework code

- Formatting
 - Suppress warnings
 - Remove unused imports
pull/602/head
Sam Brannen 11 years ago
parent
commit
b75eb60943
  1. 2
      spring-test/src/main/java/org/springframework/test/web/servlet/SmartRequestBuilder.java
  2. 2
      spring-test/src/main/java/org/springframework/test/web/servlet/setup/AbstractMockMvcBuilder.java
  3. 2
      spring-test/src/main/java/org/springframework/test/web/servlet/setup/MockMvcConfigurerAdapter.java
  4. 22
      spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/FrameworkExtensionTests.java

2
spring-test/src/main/java/org/springframework/test/web/servlet/SmartRequestBuilder.java

@ -13,10 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.test.web.servlet; package org.springframework.test.web.servlet;
import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.test.web.servlet.request.RequestPostProcessor;
/** /**
* Extended variant of a {@link RequestBuilder} that applies its * Extended variant of a {@link RequestBuilder} that applies its

2
spring-test/src/main/java/org/springframework/test/web/servlet/setup/AbstractMockMvcBuilder.java

@ -30,6 +30,7 @@ import org.springframework.web.context.WebApplicationContext;
import javax.servlet.Filter; import javax.servlet.Filter;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -121,6 +122,7 @@ public abstract class AbstractMockMvcBuilder<B extends AbstractMockMvcBuilder<B>
* Build a {@link org.springframework.test.web.servlet.MockMvc} instance. * Build a {@link org.springframework.test.web.servlet.MockMvc} instance.
*/ */
@Override @Override
@SuppressWarnings("rawtypes")
public final MockMvc build() { public final MockMvc build() {
WebApplicationContext wac = initWebAppContext(); WebApplicationContext wac = initWebAppContext();

2
spring-test/src/main/java/org/springframework/test/web/servlet/setup/MockMvcConfigurerAdapter.java

@ -16,11 +16,9 @@
package org.springframework.test.web.servlet.setup; package org.springframework.test.web.servlet.setup;
import org.springframework.test.web.servlet.RequestBuilder;
import org.springframework.test.web.servlet.request.RequestPostProcessor; import org.springframework.test.web.servlet.request.RequestPostProcessor;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
/** /**
* An empty method implementation of {@link MockMvcConfigurer}. * An empty method implementation of {@link MockMvcConfigurer}.
* *

22
spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/FrameworkExtensionTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -13,18 +13,14 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.springframework.test.web.servlet.samples.standalone; package org.springframework.test.web.servlet.samples.standalone;
import static org.mockito.Mockito.mock; import java.security.Principal;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
@ -36,7 +32,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import java.security.Principal; import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*;
/** /**
* Demonstrates use of SPI extension points: * Demonstrates use of SPI extension points:
@ -48,6 +47,7 @@ import java.security.Principal;
* </ul> * </ul>
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @since 4.1
*/ */
public class FrameworkExtensionTests { public class FrameworkExtensionTests {
@ -59,7 +59,6 @@ public class FrameworkExtensionTests {
this.mockMvc = standaloneSetup(new SampleController()).apply(defaultSetup()).build(); this.mockMvc = standaloneSetup(new SampleController()).apply(defaultSetup()).build();
} }
@Test @Test
public void fooHeader() throws Exception { public void fooHeader() throws Exception {
this.mockMvc.perform(get("/").with(headers().foo("a=b"))).andExpect(content().string("Foo")); this.mockMvc.perform(get("/").with(headers().foo("a=b"))).andExpect(content().string("Foo"));
@ -70,7 +69,6 @@ public class FrameworkExtensionTests {
this.mockMvc.perform(get("/").with(headers().bar("a=b"))).andExpect(content().string("Bar")); this.mockMvc.perform(get("/").with(headers().bar("a=b"))).andExpect(content().string("Bar"));
} }
private static TestMockMvcConfigurer defaultSetup() { private static TestMockMvcConfigurer defaultSetup() {
return new TestMockMvcConfigurer(); return new TestMockMvcConfigurer();
} }
@ -80,7 +78,6 @@ public class FrameworkExtensionTests {
} }
/** /**
* Test {@code RequestPostProcessor}. * Test {@code RequestPostProcessor}.
*/ */
@ -119,7 +116,8 @@ public class FrameworkExtensionTests {
} }
@Override @Override
public RequestPostProcessor beforeMockMvcCreated(ConfigurableMockMvcBuilder<?> builder, WebApplicationContext context) { public RequestPostProcessor beforeMockMvcCreated(ConfigurableMockMvcBuilder<?> builder,
WebApplicationContext context) {
return request -> { return request -> {
request.setUserPrincipal(mock(Principal.class)); request.setUserPrincipal(mock(Principal.class));
return request; return request;

Loading…
Cancel
Save