diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockBodyContent.java b/spring-test/src/main/java/org/springframework/mock/web/MockBodyContent.java index 3b98e2edb5..4b29bafd08 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockBodyContent.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockBodyContent.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,9 +26,7 @@ import javax.servlet.jsp.tagext.BodyContent; /** * Mock implementation of the {@link javax.servlet.jsp.tagext.BodyContent} class. - * - *
Used for testing the web framework; only necessary for testing - * applications when testing custom JSP tags. + * Only necessary for testing applications when testing custom JSP tags. * * @author Juergen Hoeller * @since 2.5 diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockExpressionEvaluator.java b/spring-test/src/main/java/org/springframework/mock/web/MockExpressionEvaluator.java index 3672b52ed9..00334454f4 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockExpressionEvaluator.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockExpressionEvaluator.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,14 +20,13 @@ import javax.servlet.jsp.JspException; import javax.servlet.jsp.PageContext; import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager; + import org.springframework.util.Assert; /** * Mock implementation of the JSP 2.0 {@link javax.servlet.jsp.el.ExpressionEvaluator} * interface, delegating to the Apache JSTL ExpressionEvaluatorManager. - * - *
Used for testing the web framework; only necessary for testing applications - * when testing custom JSP tags. + * Only necessary for testing applications when testing custom JSP tags. * *
Note that the Apache JSTL implementation (jstl.jar, standard.jar) has to be * available on the class path to use this expression evaluator. diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockFilterChain.java b/spring-test/src/main/java/org/springframework/mock/web/MockFilterChain.java index 05db4a5bdd..1f2f775254 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockFilterChain.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockFilterChain.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,9 +33,7 @@ import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; /** - *
Mock implementation of the {@link javax.servlet.FilterChain} interface. Used - * for testing the web framework; also useful for testing custom - * {@link javax.servlet.Filter} implementations. + * Mock implementation of the {@link javax.servlet.FilterChain} interface. * *
A {@link MockFilterChain} can be configured with one or more filters and a * Servlet to invoke. The first time the chain is called, it invokes all filters diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockFilterConfig.java b/spring-test/src/main/java/org/springframework/mock/web/MockFilterConfig.java index 123214b66f..d9067f7d5c 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockFilterConfig.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockFilterConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java b/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java index 5f73abe401..b1593cf637 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletRequest.java @@ -70,7 +70,7 @@ import org.springframework.util.StringUtils; * is {@link Locale#ENGLISH}. This value can be changed via {@link #addPreferredLocale} * or {@link #setPreferredLocales}. * - *
As of Spring Framework 5.0, this set of mocks is designed on a Servlet 3.1 baseline. + *
As of Spring Framework 5.0, this set of mocks is designed on a Servlet 4.0 baseline. * * @author Juergen Hoeller * @author Rod Johnson diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java b/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java index 8b0967c5e6..1c278d1a10 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java @@ -45,7 +45,7 @@ import org.springframework.web.util.WebUtils; /** * Mock implementation of the {@link javax.servlet.http.HttpServletResponse} interface. * - *
As of Spring Framework 5.0, this set of mocks is designed on a Servlet 3.1 baseline. + *
As of Spring Framework 5.0, this set of mocks is designed on a Servlet 4.0 baseline. * * @author Juergen Hoeller * @author Rod Johnson diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockHttpSession.java b/spring-test/src/main/java/org/springframework/mock/web/MockHttpSession.java index 70d55da985..81f43bb150 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockHttpSession.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockHttpSession.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,10 +34,7 @@ import org.springframework.util.Assert; /** * Mock implementation of the {@link javax.servlet.http.HttpSession} interface. * - *
As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline. - * - *
Used for testing the web framework; also useful for testing application - * controllers. + *
As of Spring 5.0, this set of mocks is designed on a Servlet 4.0 baseline. * * @author Juergen Hoeller * @author Rod Johnson @@ -72,7 +69,6 @@ public class MockHttpSession implements HttpSession { /** * Create a new MockHttpSession with a default {@link MockServletContext}. - * * @see MockServletContext */ public MockHttpSession() { @@ -81,7 +77,6 @@ public class MockHttpSession implements HttpSession { /** * Create a new MockHttpSession. - * * @param servletContext the ServletContext that the session runs in */ public MockHttpSession(ServletContext servletContext) { @@ -90,7 +85,6 @@ public class MockHttpSession implements HttpSession { /** * Create a new MockHttpSession. - * * @param servletContext the ServletContext that the session runs in * @param id a unique identifier for this session */ @@ -99,6 +93,7 @@ public class MockHttpSession implements HttpSession { this.id = (id != null ? id : Integer.toString(nextId++)); } + @Override public long getCreationTime() { assertIsValid(); @@ -111,8 +106,8 @@ public class MockHttpSession implements HttpSession { } /** - * As of Servlet 3.1 the id of a session can be changed. - * @return the new session id. + * As of Servlet 3.1, the id of a session can be changed. + * @return the new session id * @since 4.0.3 */ public String changeSessionId() { @@ -227,7 +222,6 @@ public class MockHttpSession implements HttpSession { /** * Invalidates this session then unbinds any objects bound to it. - * * @throws IllegalStateException if this method is called on an already invalidated session */ @Override @@ -244,7 +238,6 @@ public class MockHttpSession implements HttpSession { /** * Convenience method for asserting that this session has not been * {@linkplain #invalidate() invalidated}. - * * @throws IllegalStateException if this session has been invalidated */ private void assertIsValid() { @@ -264,7 +257,6 @@ public class MockHttpSession implements HttpSession { /** * Serialize the attributes of this session into an object that can be * turned into a byte array with standard Java serialization. - * * @return a representation of this session's serialized state */ public Serializable serializeState() { @@ -291,7 +283,6 @@ public class MockHttpSession implements HttpSession { /** * Deserialize the attributes of this session from a state object created by * {@link #serializeState()}. - * * @param state a representation of this session's serialized state */ @SuppressWarnings("unchecked") diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockJspWriter.java b/spring-test/src/main/java/org/springframework/mock/web/MockJspWriter.java index 9fc585e59a..1245dbb5a8 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockJspWriter.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockJspWriter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,9 +24,7 @@ import javax.servlet.jsp.JspWriter; /** * Mock implementation of the {@link javax.servlet.jsp.JspWriter} class. - * - *
Used for testing the web framework; only necessary for testing - * applications when testing custom JSP tags. + * Only necessary for testing applications when testing custom JSP tags. * * @author Juergen Hoeller * @since 2.5 diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockMultipartHttpServletRequest.java b/spring-test/src/main/java/org/springframework/mock/web/MockMultipartHttpServletRequest.java index f1a0307836..bb47c6112d 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockMultipartHttpServletRequest.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockMultipartHttpServletRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,11 +35,10 @@ import org.springframework.web.multipart.MultipartHttpServletRequest; * Mock implementation of the * {@link org.springframework.web.multipart.MultipartHttpServletRequest} interface. * - *
As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline. + *
As of Spring 5.0, this set of mocks is designed on a Servlet 4.0 baseline. * *
Useful for testing application controllers that access multipart uploads.
- * The {@link MockMultipartFile} can be used to populate these mock requests
- * with files.
+ * {@link MockMultipartFile} can be used to populate these mock requests with files.
*
* @author Juergen Hoeller
* @author Eric Crampton
@@ -49,8 +48,7 @@ import org.springframework.web.multipart.MultipartHttpServletRequest;
*/
public class MockMultipartHttpServletRequest extends MockHttpServletRequest implements MultipartHttpServletRequest {
- private final MultiValueMap Used for testing the web framework; only necessary for testing
- * applications when testing custom JSP tags.
+ * Only necessary for testing applications when testing custom JSP tags.
*
* Note: Expects initialization via the constructor rather than via the
* {@code PageContext.initialize} method. Does not support writing to a
diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockRequestDispatcher.java b/spring-test/src/main/java/org/springframework/mock/web/MockRequestDispatcher.java
index 39a1e17f50..7fbae6f2ad 100644
--- a/spring-test/src/main/java/org/springframework/mock/web/MockRequestDispatcher.java
+++ b/spring-test/src/main/java/org/springframework/mock/web/MockRequestDispatcher.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,9 +29,6 @@ import org.springframework.util.Assert;
/**
* Mock implementation of the {@link javax.servlet.RequestDispatcher} interface.
*
- * Used for testing the web framework; typically not necessary for
- * testing application controllers.
- *
* @author Rod Johnson
* @author Juergen Hoeller
* @author Sam Brannen
@@ -50,7 +47,7 @@ public class MockRequestDispatcher implements RequestDispatcher {
* particular path or given by a particular name
*/
public MockRequestDispatcher(String resource) {
- Assert.notNull(resource, "resource must not be null");
+ Assert.notNull(resource, "Resource must not be null");
this.resource = resource;
}
diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockServletConfig.java b/spring-test/src/main/java/org/springframework/mock/web/MockServletConfig.java
index d5bb9f33aa..805e7b4635 100644
--- a/spring-test/src/main/java/org/springframework/mock/web/MockServletConfig.java
+++ b/spring-test/src/main/java/org/springframework/mock/web/MockServletConfig.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,9 +28,6 @@ import org.springframework.util.Assert;
/**
* Mock implementation of the {@link javax.servlet.ServletConfig} interface.
*
- * Used for testing the web framework; typically not necessary for
- * testing application controllers.
- *
* @author Rod Johnson
* @author Juergen Hoeller
* @since 1.0.2
diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java b/spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java
index e35ade005d..b0833b15a6 100644
--- a/spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java
+++ b/spring-test/src/main/java/org/springframework/mock/web/MockServletContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,37 +55,21 @@ import org.springframework.web.util.WebUtils;
/**
* Mock implementation of the {@link javax.servlet.ServletContext} interface.
*
- * As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline.
+ * As of Spring 5.0, this set of mocks is designed on a Servlet 4.0 baseline.
*
- * Compatible with Servlet 3.0 but can be configured to expose a specific version
- * through {@link #setMajorVersion}/{@link #setMinorVersion}; default is 3.0.
- * Note that Servlet 3.0 support is limited: servlet, filter and listener
+ * Compatible with Servlet 3.1 but can be configured to expose a specific version
+ * through {@link #setMajorVersion}/{@link #setMinorVersion}; default is 3.1.
+ * Note that Servlet 3.1 support is limited: servlet, filter and listener
* registration methods are not supported; neither is JSP configuration.
* We generally do not recommend to unit test your ServletContainerInitializers and
* WebApplicationInitializers which is where those registration methods would be used.
*
- * Used for testing the Spring web framework; only rarely necessary for testing
- * application controllers. As long as application components don't explicitly
- * access the {@code ServletContext}, {@code ClassPathXmlApplicationContext} or
- * {@code FileSystemXmlApplicationContext} can be used to load the context files
- * for testing, even for {@code DispatcherServlet} context definitions.
- *
- * For setting up a full {@code WebApplicationContext} in a test environment,
- * you can use {@code AnnotationConfigWebApplicationContext},
- * {@code XmlWebApplicationContext}, or {@code GenericWebApplicationContext},
- * passing in an appropriate {@code MockServletContext} instance. You might want
- * to configure your {@code MockServletContext} with a {@code FileSystemResourceLoader}
- * in that case to ensure that resource paths are interpreted as relative filesystem
- * locations.
- *
- * A common setup is to point your JVM working directory to the root of your
- * web application directory, in combination with filesystem-based resource loading.
- * This allows to load the context files as used in the web application, with
- * relative paths getting interpreted correctly. Such a setup will work with both
- * {@code FileSystemXmlApplicationContext} (which will load straight from the
- * filesystem) and {@code XmlWebApplicationContext} with an underlying
- * {@code MockServletContext} (as long as the {@code MockServletContext} has been
- * configured with a {@code FileSystemResourceLoader}).
+ * For setting up a full {@code WebApplicationContext} in a test environment, you can
+ * use {@code AnnotationConfigWebApplicationContext}, {@code XmlWebApplicationContext},
+ * or {@code GenericWebApplicationContext}, passing in a corresponding
+ * {@code MockServletContext} instance. Consider configuring your
+ * {@code MockServletContext} with a {@code FileSystemResourceLoader} in order to
+ * interpret resource paths as relative filesystem locations.
*
* @author Rod Johnson
* @author Juergen Hoeller
@@ -95,18 +79,15 @@ import org.springframework.web.util.WebUtils;
* @see org.springframework.web.context.support.AnnotationConfigWebApplicationContext
* @see org.springframework.web.context.support.XmlWebApplicationContext
* @see org.springframework.web.context.support.GenericWebApplicationContext
- * @see org.springframework.context.support.ClassPathXmlApplicationContext
- * @see org.springframework.context.support.FileSystemXmlApplicationContext
*/
public class MockServletContext implements ServletContext {
- /** Default Servlet name used by Tomcat, Jetty, JBoss, and GlassFish: {@value}. */
+ /** Default Servlet name used by Tomcat, Jetty, JBoss, and GlassFish: {@value} */
private static final String COMMON_DEFAULT_SERVLET_NAME = "default";
private static final String TEMP_DIR_SYSTEM_PROPERTY = "java.io.tmpdir";
- private static final Set Used for testing the web framework; only necessary for testing
- * applications when testing custom JSP tags.
+ * Only necessary for testing applications when testing custom JSP tags.
*
* @author Juergen Hoeller
* @since 2.5
diff --git a/spring-web/src/test/java/org/springframework/mock/web/test/MockExpressionEvaluator.java b/spring-web/src/test/java/org/springframework/mock/web/test/MockExpressionEvaluator.java
index 80b3365f47..ace4928ce2 100644
--- a/spring-web/src/test/java/org/springframework/mock/web/test/MockExpressionEvaluator.java
+++ b/spring-web/src/test/java/org/springframework/mock/web/test/MockExpressionEvaluator.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2015 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,12 +21,12 @@ import javax.servlet.jsp.PageContext;
import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
+import org.springframework.util.Assert;
+
/**
* Mock implementation of the JSP 2.0 {@link javax.servlet.jsp.el.ExpressionEvaluator}
* interface, delegating to the Apache JSTL ExpressionEvaluatorManager.
- *
- * Used for testing the web framework; only necessary for testing applications
- * when testing custom JSP tags.
+ * Only necessary for testing applications when testing custom JSP tags.
*
* Note that the Apache JSTL implementation (jstl.jar, standard.jar) has to be
* available on the class path to use this expression evaluator.
@@ -68,9 +68,7 @@ public class MockExpressionEvaluator extends javax.servlet.jsp.el.ExpressionEval
public Object evaluate(String expression, Class expectedType, javax.servlet.jsp.el.VariableResolver variableResolver,
javax.servlet.jsp.el.FunctionMapper functionMapper) throws javax.servlet.jsp.el.ELException {
- if (variableResolver != null) {
- throw new IllegalArgumentException("Custom VariableResolver not supported");
- }
+ Assert.isNull(variableResolver, "Custom VariableResolver not supported");
return doEvaluate(expression, expectedType, functionMapper);
}
@@ -78,9 +76,7 @@ public class MockExpressionEvaluator extends javax.servlet.jsp.el.ExpressionEval
protected Object doEvaluate(String expression, Class expectedType, javax.servlet.jsp.el.FunctionMapper functionMapper)
throws javax.servlet.jsp.el.ELException {
- if (functionMapper != null) {
- throw new IllegalArgumentException("Custom FunctionMapper not supported");
- }
+ Assert.isNull(functionMapper, "Custom FunctionMapper not supported");
try {
return ExpressionEvaluatorManager.evaluate("JSP EL expression", expression, expectedType, this.pageContext);
}
diff --git a/spring-web/src/test/java/org/springframework/mock/web/test/MockFilterChain.java b/spring-web/src/test/java/org/springframework/mock/web/test/MockFilterChain.java
index ac10e6e756..da4a909310 100644
--- a/spring-web/src/test/java/org/springframework/mock/web/test/MockFilterChain.java
+++ b/spring-web/src/test/java/org/springframework/mock/web/test/MockFilterChain.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,9 +33,7 @@ import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
/**
- * Mock implementation of the {@link javax.servlet.FilterChain} interface. Used
- * for testing the web framework; also useful for testing custom
- * {@link javax.servlet.Filter} implementations.
+ * Mock implementation of the {@link javax.servlet.FilterChain} interface.
*
* A {@link MockFilterChain} can be configured with one or more filters and a
* Servlet to invoke. The first time the chain is called, it invokes all filters
@@ -120,10 +118,7 @@ public class MockFilterChain implements FilterChain {
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
Assert.notNull(request, "Request must not be null");
Assert.notNull(response, "Response must not be null");
-
- if (this.request != null) {
- throw new IllegalStateException("This FilterChain has already been called!");
- }
+ Assert.state(this.request == null, "This FilterChain has already been called!");
if (this.iterator == null) {
this.iterator = this.filters.iterator();
diff --git a/spring-web/src/test/java/org/springframework/mock/web/test/MockFilterConfig.java b/spring-web/src/test/java/org/springframework/mock/web/test/MockFilterConfig.java
index 276d8759d3..fbfc1a17f3 100644
--- a/spring-web/src/test/java/org/springframework/mock/web/test/MockFilterConfig.java
+++ b/spring-web/src/test/java/org/springframework/mock/web/test/MockFilterConfig.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletRequest.java b/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletRequest.java
index 182df3af88..896c174288 100644
--- a/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletRequest.java
+++ b/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletRequest.java
@@ -70,7 +70,7 @@ import org.springframework.util.StringUtils;
* is {@link Locale#ENGLISH}. This value can be changed via {@link #addPreferredLocale}
* or {@link #setPreferredLocales}.
*
- * As of Spring Framework 5.0, this set of mocks is designed on a Servlet 3.1 baseline.
+ * As of Spring Framework 5.0, this set of mocks is designed on a Servlet 4.0 baseline.
*
* @author Juergen Hoeller
* @author Rod Johnson
diff --git a/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletResponse.java b/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletResponse.java
index 5c1dd308df..bc667a8e60 100644
--- a/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletResponse.java
+++ b/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletResponse.java
@@ -45,7 +45,7 @@ import org.springframework.web.util.WebUtils;
/**
* Mock implementation of the {@link javax.servlet.http.HttpServletResponse} interface.
*
- * As of Spring Framework 5.0, this set of mocks is designed on a Servlet 3.1 baseline.
+ * As of Spring Framework 5.0, this set of mocks is designed on a Servlet 4.0 baseline.
*
* @author Juergen Hoeller
* @author Rod Johnson
diff --git a/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpSession.java b/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpSession.java
index 2c8a411d40..a854fe9f43 100644
--- a/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpSession.java
+++ b/spring-web/src/test/java/org/springframework/mock/web/test/MockHttpSession.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,10 +34,7 @@ import org.springframework.util.Assert;
/**
* Mock implementation of the {@link javax.servlet.http.HttpSession} interface.
*
- * As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline.
- *
- * Used for testing the web framework; also useful for testing application
- * controllers.
+ * As of Spring 5.0, this set of mocks is designed on a Servlet 4.0 baseline.
*
* @author Juergen Hoeller
* @author Rod Johnson
@@ -72,7 +69,6 @@ public class MockHttpSession implements HttpSession {
/**
* Create a new MockHttpSession with a default {@link MockServletContext}.
- *
* @see MockServletContext
*/
public MockHttpSession() {
@@ -81,7 +77,6 @@ public class MockHttpSession implements HttpSession {
/**
* Create a new MockHttpSession.
- *
* @param servletContext the ServletContext that the session runs in
*/
public MockHttpSession(ServletContext servletContext) {
@@ -90,7 +85,6 @@ public class MockHttpSession implements HttpSession {
/**
* Create a new MockHttpSession.
- *
* @param servletContext the ServletContext that the session runs in
* @param id a unique identifier for this session
*/
@@ -99,6 +93,7 @@ public class MockHttpSession implements HttpSession {
this.id = (id != null ? id : Integer.toString(nextId++));
}
+
@Override
public long getCreationTime() {
assertIsValid();
@@ -111,8 +106,8 @@ public class MockHttpSession implements HttpSession {
}
/**
- * As of Servlet 3.1 the id of a session can be changed.
- * @return the new session id.
+ * As of Servlet 3.1, the id of a session can be changed.
+ * @return the new session id
* @since 4.0.3
*/
public String changeSessionId() {
@@ -227,7 +222,6 @@ public class MockHttpSession implements HttpSession {
/**
* Invalidates this session then unbinds any objects bound to it.
- *
* @throws IllegalStateException if this method is called on an already invalidated session
*/
@Override
@@ -244,13 +238,10 @@ public class MockHttpSession implements HttpSession {
/**
* Convenience method for asserting that this session has not been
* {@linkplain #invalidate() invalidated}.
- *
* @throws IllegalStateException if this session has been invalidated
*/
private void assertIsValid() {
- if (isInvalid()) {
- throw new IllegalStateException("The session has already been invalidated");
- }
+ Assert.state(!isInvalid(), "The session has already been invalidated");
}
public void setNew(boolean value) {
@@ -266,7 +257,6 @@ public class MockHttpSession implements HttpSession {
/**
* Serialize the attributes of this session into an object that can be
* turned into a byte array with standard Java serialization.
- *
* @return a representation of this session's serialized state
*/
public Serializable serializeState() {
@@ -293,7 +283,6 @@ public class MockHttpSession implements HttpSession {
/**
* Deserialize the attributes of this session from a state object created by
* {@link #serializeState()}.
- *
* @param state a representation of this session's serialized state
*/
@SuppressWarnings("unchecked")
diff --git a/spring-web/src/test/java/org/springframework/mock/web/test/MockJspWriter.java b/spring-web/src/test/java/org/springframework/mock/web/test/MockJspWriter.java
index e83ff23521..012e0978e5 100644
--- a/spring-web/src/test/java/org/springframework/mock/web/test/MockJspWriter.java
+++ b/spring-web/src/test/java/org/springframework/mock/web/test/MockJspWriter.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,9 +24,7 @@ import javax.servlet.jsp.JspWriter;
/**
* Mock implementation of the {@link javax.servlet.jsp.JspWriter} class.
- *
- * Used for testing the web framework; only necessary for testing
- * applications when testing custom JSP tags.
+ * Only necessary for testing applications when testing custom JSP tags.
*
* @author Juergen Hoeller
* @since 2.5
diff --git a/spring-web/src/test/java/org/springframework/mock/web/test/MockMultipartHttpServletRequest.java b/spring-web/src/test/java/org/springframework/mock/web/test/MockMultipartHttpServletRequest.java
index 8a92ffefe6..d74c24c077 100644
--- a/spring-web/src/test/java/org/springframework/mock/web/test/MockMultipartHttpServletRequest.java
+++ b/spring-web/src/test/java/org/springframework/mock/web/test/MockMultipartHttpServletRequest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,11 +35,10 @@ import org.springframework.web.multipart.MultipartHttpServletRequest;
* Mock implementation of the
* {@link org.springframework.web.multipart.MultipartHttpServletRequest} interface.
*
- * As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline.
+ * As of Spring 5.0, this set of mocks is designed on a Servlet 4.0 baseline.
*
* Useful for testing application controllers that access multipart uploads.
- * The {@link MockMultipartFile} can be used to populate these mock requests
- * with files.
+ * {@link MockMultipartFile} can be used to populate these mock requests with files.
*
* @author Juergen Hoeller
* @author Eric Crampton
@@ -49,8 +48,7 @@ import org.springframework.web.multipart.MultipartHttpServletRequest;
*/
public class MockMultipartHttpServletRequest extends MockHttpServletRequest implements MultipartHttpServletRequest {
- private final MultiValueMap Used for testing the web framework; only necessary for testing
- * applications when testing custom JSP tags.
+ * Only necessary for testing applications when testing custom JSP tags.
*
* Note: Expects initialization via the constructor rather than via the
* {@code PageContext.initialize} method. Does not support writing to a
diff --git a/spring-web/src/test/java/org/springframework/mock/web/test/MockRequestDispatcher.java b/spring-web/src/test/java/org/springframework/mock/web/test/MockRequestDispatcher.java
index b8679b8020..091b47b12e 100644
--- a/spring-web/src/test/java/org/springframework/mock/web/test/MockRequestDispatcher.java
+++ b/spring-web/src/test/java/org/springframework/mock/web/test/MockRequestDispatcher.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,9 +29,6 @@ import org.springframework.util.Assert;
/**
* Mock implementation of the {@link javax.servlet.RequestDispatcher} interface.
*
- * Used for testing the web framework; typically not necessary for
- * testing application controllers.
- *
* @author Rod Johnson
* @author Juergen Hoeller
* @author Sam Brannen
@@ -50,7 +47,7 @@ public class MockRequestDispatcher implements RequestDispatcher {
* particular path or given by a particular name
*/
public MockRequestDispatcher(String resource) {
- Assert.notNull(resource, "resource must not be null");
+ Assert.notNull(resource, "Resource must not be null");
this.resource = resource;
}
@@ -59,9 +56,7 @@ public class MockRequestDispatcher implements RequestDispatcher {
public void forward(ServletRequest request, ServletResponse response) {
Assert.notNull(request, "Request must not be null");
Assert.notNull(response, "Response must not be null");
- if (response.isCommitted()) {
- throw new IllegalStateException("Cannot perform forward - response is already committed");
- }
+ Assert.state(!response.isCommitted(), "Cannot perform forward - response is already committed");
getMockHttpServletResponse(response).setForwardedUrl(this.resource);
if (logger.isDebugEnabled()) {
logger.debug("MockRequestDispatcher: forwarding to [" + this.resource + "]");
diff --git a/spring-web/src/test/java/org/springframework/mock/web/test/MockServletConfig.java b/spring-web/src/test/java/org/springframework/mock/web/test/MockServletConfig.java
index 1da0f87349..c73d05d657 100644
--- a/spring-web/src/test/java/org/springframework/mock/web/test/MockServletConfig.java
+++ b/spring-web/src/test/java/org/springframework/mock/web/test/MockServletConfig.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,9 +28,6 @@ import org.springframework.util.Assert;
/**
* Mock implementation of the {@link javax.servlet.ServletConfig} interface.
*
- * Used for testing the web framework; typically not necessary for
- * testing application controllers.
- *
* @author Rod Johnson
* @author Juergen Hoeller
* @since 1.0.2
diff --git a/spring-web/src/test/java/org/springframework/mock/web/test/MockServletContext.java b/spring-web/src/test/java/org/springframework/mock/web/test/MockServletContext.java
index f6fff852b0..853f34a727 100644
--- a/spring-web/src/test/java/org/springframework/mock/web/test/MockServletContext.java
+++ b/spring-web/src/test/java/org/springframework/mock/web/test/MockServletContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,37 +55,21 @@ import org.springframework.web.util.WebUtils;
/**
* Mock implementation of the {@link javax.servlet.ServletContext} interface.
*
- * As of Spring 4.0, this set of mocks is designed on a Servlet 3.0 baseline.
+ * As of Spring 5.0, this set of mocks is designed on a Servlet 4.0 baseline.
*
- * Compatible with Servlet 3.0 but can be configured to expose a specific version
- * through {@link #setMajorVersion}/{@link #setMinorVersion}; default is 3.0.
- * Note that Servlet 3.0 support is limited: servlet, filter and listener
+ * Compatible with Servlet 3.1 but can be configured to expose a specific version
+ * through {@link #setMajorVersion}/{@link #setMinorVersion}; default is 3.1.
+ * Note that Servlet 3.1 support is limited: servlet, filter and listener
* registration methods are not supported; neither is JSP configuration.
* We generally do not recommend to unit test your ServletContainerInitializers and
* WebApplicationInitializers which is where those registration methods would be used.
*
- * Used for testing the Spring web framework; only rarely necessary for testing
- * application controllers. As long as application components don't explicitly
- * access the {@code ServletContext}, {@code ClassPathXmlApplicationContext} or
- * {@code FileSystemXmlApplicationContext} can be used to load the context files
- * for testing, even for {@code DispatcherServlet} context definitions.
- *
- * For setting up a full {@code WebApplicationContext} in a test environment,
- * you can use {@code AnnotationConfigWebApplicationContext},
- * {@code XmlWebApplicationContext}, or {@code GenericWebApplicationContext},
- * passing in an appropriate {@code MockServletContext} instance. You might want
- * to configure your {@code MockServletContext} with a {@code FileSystemResourceLoader}
- * in that case to ensure that resource paths are interpreted as relative filesystem
- * locations.
- *
- * A common setup is to point your JVM working directory to the root of your
- * web application directory, in combination with filesystem-based resource loading.
- * This allows to load the context files as used in the web application, with
- * relative paths getting interpreted correctly. Such a setup will work with both
- * {@code FileSystemXmlApplicationContext} (which will load straight from the
- * filesystem) and {@code XmlWebApplicationContext} with an underlying
- * {@code MockServletContext} (as long as the {@code MockServletContext} has been
- * configured with a {@code FileSystemResourceLoader}).
+ * For setting up a full {@code WebApplicationContext} in a test environment, you can
+ * use {@code AnnotationConfigWebApplicationContext}, {@code XmlWebApplicationContext},
+ * or {@code GenericWebApplicationContext}, passing in a corresponding
+ * {@code MockServletContext} instance. Consider configuring your
+ * {@code MockServletContext} with a {@code FileSystemResourceLoader} in order to
+ * interpret resource paths as relative filesystem locations.
*
* @author Rod Johnson
* @author Juergen Hoeller
@@ -95,18 +79,15 @@ import org.springframework.web.util.WebUtils;
* @see org.springframework.web.context.support.AnnotationConfigWebApplicationContext
* @see org.springframework.web.context.support.XmlWebApplicationContext
* @see org.springframework.web.context.support.GenericWebApplicationContext
- * @see org.springframework.context.support.ClassPathXmlApplicationContext
- * @see org.springframework.context.support.FileSystemXmlApplicationContext
*/
public class MockServletContext implements ServletContext {
- /** Default Servlet name used by Tomcat, Jetty, JBoss, and GlassFish: {@value}. */
+ /** Default Servlet name used by Tomcat, Jetty, JBoss, and GlassFish: {@value} */
private static final String COMMON_DEFAULT_SERVLET_NAME = "default";
private static final String TEMP_DIR_SYSTEM_PROPERTY = "java.io.tmpdir";
- private static final Set