Suppressing warnings, polishing JavaDoc, etc.

This commit is contained in:
Sam Brannen
2011-02-08 22:50:45 +00:00
parent e7c2713fd4
commit 6926e0f563
41 changed files with 404 additions and 364 deletions

View File

@@ -27,19 +27,21 @@ import javax.servlet.jsp.el.VariableResolver;
import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
/**
* Mock implementation of the JSP 2.0 {@link javax.servlet.jsp.el.ExpressionEvaluator}
* interface, delegating to the Jakarta JSTL ExpressionEvaluatorManager.
*
* <p>Used for testing the web framework; only necessary for testing
* applications when testing custom JSP tags.
*
* <p>Note that the Jakarta JSTL implementation (jstl.jar, standard.jar)
* has to be available on the class path to use this expression evaluator.
*
* Mock implementation of the JSP 2.0
* {@link javax.servlet.jsp.el.ExpressionEvaluator} interface, delegating to the
* Jakarta JSTL ExpressionEvaluatorManager.
* <p>
* Used for testing the web framework; only necessary for testing applications
* when testing custom JSP tags.
* <p>
* Note that the Jakarta JSTL implementation (jstl.jar, standard.jar) has to be
* available on the class path to use this expression evaluator.
*
* @author Juergen Hoeller
* @since 1.1.5
* @see org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager
*/
@SuppressWarnings("deprecation")
public class MockExpressionEvaluator extends ExpressionEvaluator {
private final PageContext pageContext;
@@ -47,26 +49,28 @@ public class MockExpressionEvaluator extends ExpressionEvaluator {
/**
* Create a new MockExpressionEvaluator for the given PageContext.
*
* @param pageContext the JSP PageContext to run in
*/
public MockExpressionEvaluator(PageContext pageContext) {
this.pageContext = pageContext;
}
public Expression parseExpression(
final String expression, final Class expectedType, final FunctionMapper functionMapper)
throws ELException {
@SuppressWarnings("rawtypes")
public Expression parseExpression(final String expression, final Class expectedType,
final FunctionMapper functionMapper) throws ELException {
return new Expression() {
public Object evaluate(VariableResolver variableResolver) throws ELException {
return doEvaluate(expression, expectedType, functionMapper);
}
};
}
public Object evaluate(
String expression, Class expectedType, VariableResolver variableResolver, FunctionMapper functionMapper)
throws ELException {
@SuppressWarnings("rawtypes")
public Object evaluate(String expression, Class expectedType, VariableResolver variableResolver,
FunctionMapper functionMapper) throws ELException {
if (variableResolver != null) {
throw new IllegalArgumentException("Custom VariableResolver not supported");
@@ -74,8 +78,8 @@ public class MockExpressionEvaluator extends ExpressionEvaluator {
return doEvaluate(expression, expectedType, functionMapper);
}
protected Object doEvaluate(
String expression, Class expectedType, FunctionMapper functionMapper)
@SuppressWarnings("rawtypes")
protected Object doEvaluate(String expression, Class expectedType, FunctionMapper functionMapper)
throws ELException {
if (functionMapper != null) {

View File

@@ -35,6 +35,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletInputStream;
@@ -48,10 +49,10 @@ import org.springframework.util.LinkedCaseInsensitiveMap;
/**
* Mock implementation of the {@link javax.servlet.http.HttpServletRequest}
* interface. Supports the Servlet 2.5 API level.
*
* <p>Used for testing the web framework; also useful for testing
* application controllers.
*
* <p>
* Used for testing the web framework; also useful for testing application
* controllers.
*
* @author Juergen Hoeller
* @author Rod Johnson
* @author Rick Evans
@@ -90,13 +91,11 @@ public class MockHttpServletRequest implements HttpServletRequest {
*/
public static final String DEFAULT_REMOTE_HOST = "localhost";
private boolean active = true;
//---------------------------------------------------------------------
// ---------------------------------------------------------------------
// ServletRequest properties
//---------------------------------------------------------------------
// ---------------------------------------------------------------------
private final Map<String, Object> attributes = new LinkedHashMap<String, Object>();
@@ -135,10 +134,9 @@ public class MockHttpServletRequest implements HttpServletRequest {
private int localPort = DEFAULT_SERVER_PORT;
//---------------------------------------------------------------------
// ---------------------------------------------------------------------
// HttpServletRequest properties
//---------------------------------------------------------------------
// ---------------------------------------------------------------------
private String authType;
@@ -175,13 +173,14 @@ public class MockHttpServletRequest implements HttpServletRequest {
private boolean requestedSessionIdFromURL = false;
//---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Constructors
//---------------------------------------------------------------------
// ---------------------------------------------------------------------
/**
* Create a new MockHttpServletRequest with a default
* {@link MockServletContext}.
*
* @see MockServletContext
*/
public MockHttpServletRequest() {
@@ -191,6 +190,7 @@ public class MockHttpServletRequest implements HttpServletRequest {
/**
* Create a new MockHttpServletRequest with a default
* {@link MockServletContext}.
*
* @param method the request method (may be <code>null</code>)
* @param requestURI the request URI (may be <code>null</code>)
* @see #setMethod
@@ -203,8 +203,9 @@ public class MockHttpServletRequest implements HttpServletRequest {
/**
* Create a new MockHttpServletRequest.
* @param servletContext the ServletContext that the request runs in
* (may be <code>null</code> to use a default MockServletContext)
*
* @param servletContext the ServletContext that the request runs in (may be
* <code>null</code> to use a default MockServletContext)
* @see MockServletContext
*/
public MockHttpServletRequest(ServletContext servletContext) {
@@ -213,8 +214,9 @@ public class MockHttpServletRequest implements HttpServletRequest {
/**
* Create a new MockHttpServletRequest.
* @param servletContext the ServletContext that the request runs in
* (may be <code>null</code> to use a default MockServletContext)
*
* @param servletContext the ServletContext that the request runs in (may be
* <code>null</code> to use a default MockServletContext)
* @param method the request method (may be <code>null</code>)
* @param requestURI the request URI (may be <code>null</code>)
* @see #setMethod
@@ -228,14 +230,13 @@ public class MockHttpServletRequest implements HttpServletRequest {
this.locales.add(Locale.ENGLISH);
}
//---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Lifecycle methods
//---------------------------------------------------------------------
// ---------------------------------------------------------------------
/**
* Return the ServletContext that this request is associated with.
* (Not available in the standard HttpServletRequest interface for some reason.)
* Return the ServletContext that this request is associated with. (Not
* available in the standard HttpServletRequest interface for some reason.)
*/
public ServletContext getServletContext() {
return this.servletContext;
@@ -273,10 +274,9 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
}
//---------------------------------------------------------------------
// ---------------------------------------------------------------------
// ServletRequest interface
//---------------------------------------------------------------------
// ---------------------------------------------------------------------
public Object getAttribute(String name) {
checkActive();
@@ -323,16 +323,18 @@ public class MockHttpServletRequest implements HttpServletRequest {
/**
* Set a single value for the specified HTTP parameter.
* <p>If there are already one or more values registered for the given
* <p>
* If there are already one or more values registered for the given
* parameter name, they will be replaced.
*/
public void setParameter(String name, String value) {
setParameter(name, new String[] {value});
setParameter(name, new String[] { value });
}
/**
* Set an array of values for the specified HTTP parameter.
* <p>If there are already one or more values registered for the given
* <p>
* If there are already one or more values registered for the given
* parameter name, they will be replaced.
*/
public void setParameter(String name, String[] values) {
@@ -341,15 +343,15 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
/**
* Sets all provided parameters <emphasis>replacing</emphasis> any
* existing values for the provided parameter names. To add without
* replacing existing values, use {@link #addParameters(java.util.Map)}.
* Sets all provided parameters <emphasis>replacing</emphasis> any existing
* values for the provided parameter names. To add without replacing
* existing values, use {@link #addParameters(java.util.Map)}.
*/
@SuppressWarnings("rawtypes")
public void setParameters(Map params) {
Assert.notNull(params, "Parameter map must not be null");
for (Object key : params.keySet()) {
Assert.isInstanceOf(String.class, key,
"Parameter map key must be of type [" + String.class.getName() + "]");
Assert.isInstanceOf(String.class, key, "Parameter map key must be of type [" + String.class.getName() + "]");
Object value = params.get(key);
if (value instanceof String) {
this.setParameter((String) key, (String) value);
@@ -358,25 +360,26 @@ public class MockHttpServletRequest implements HttpServletRequest {
this.setParameter((String) key, (String[]) value);
}
else {
throw new IllegalArgumentException(
"Parameter map value must be single value " + " or array of type [" + String.class.getName() +
"]");
throw new IllegalArgumentException("Parameter map value must be single value " + " or array of type ["
+ String.class.getName() + "]");
}
}
}
/**
* Add a single value for the specified HTTP parameter.
* <p>If there are already one or more values registered for the given
* <p>
* If there are already one or more values registered for the given
* parameter name, the given value will be added to the end of the list.
*/
public void addParameter(String name, String value) {
addParameter(name, new String[] {value});
addParameter(name, new String[] { value });
}
/**
* Add an array of values for the specified HTTP parameter.
* <p>If there are already one or more values registered for the given
* <p>
* If there are already one or more values registered for the given
* parameter name, the given values will be added to the end of the list.
*/
public void addParameter(String name, String[] values) {
@@ -394,15 +397,15 @@ public class MockHttpServletRequest implements HttpServletRequest {
}
/**
* Adds all provided parameters <emphasis>without</emphasis> replacing
* any existing values. To replace existing values, use
* Adds all provided parameters <emphasis>without</emphasis> replacing any
* existing values. To replace existing values, use
* {@link #setParameters(java.util.Map)}.
*/
@SuppressWarnings("rawtypes")
public void addParameters(Map params) {
Assert.notNull(params, "Parameter map must not be null");
for (Object key : params.keySet()) {
Assert.isInstanceOf(String.class, key,
"Parameter map key must be of type [" + String.class.getName() + "]");
Assert.isInstanceOf(String.class, key, "Parameter map key must be of type [" + String.class.getName() + "]");
Object value = params.get(key);
if (value instanceof String) {
this.addParameter((String) key, (String) value);
@@ -411,14 +414,15 @@ public class MockHttpServletRequest implements HttpServletRequest {
this.addParameter((String) key, (String[]) value);
}
else {
throw new IllegalArgumentException("Parameter map value must be single value " +
" or array of type [" + String.class.getName() + "]");
throw new IllegalArgumentException("Parameter map value must be single value " + " or array of type ["
+ String.class.getName() + "]");
}
}
}
/**
* Remove already registered values for the specified HTTP parameter, if any.
* Remove already registered values for the specified HTTP parameter, if
* any.
*/
public void removeParameter(String name) {
Assert.notNull(name, "Parameter name must not be null");
@@ -486,8 +490,8 @@ public class MockHttpServletRequest implements HttpServletRequest {
public BufferedReader getReader() throws UnsupportedEncodingException {
if (this.content != null) {
InputStream sourceStream = new ByteArrayInputStream(this.content);
Reader sourceReader = (this.characterEncoding != null) ?
new InputStreamReader(sourceStream, this.characterEncoding) : new InputStreamReader(sourceStream);
Reader sourceReader = (this.characterEncoding != null) ? new InputStreamReader(sourceStream,
this.characterEncoding) : new InputStreamReader(sourceStream);
return new BufferedReader(sourceReader);
}
else {
@@ -599,10 +603,9 @@ public class MockHttpServletRequest implements HttpServletRequest {
return this.localPort;
}
//---------------------------------------------------------------------
// ---------------------------------------------------------------------
// HttpServletRequest interface
//---------------------------------------------------------------------
// ---------------------------------------------------------------------
public void setAuthType(String authType) {
this.authType = authType;
@@ -622,21 +625,25 @@ public class MockHttpServletRequest implements HttpServletRequest {
/**
* Add a header entry for the given name.
* <p>If there was no entry for that header name before,
* the value will be used as-is. In case of an existing entry,
* a String array will be created, adding the given value (more
* specifically, its toString representation) as further element.
* <p>Multiple values can only be stored as list of Strings,
* following the Servlet spec (see <code>getHeaders</code> accessor).
* As alternative to repeated <code>addHeader</code> calls for
* individual elements, you can use a single call with an entire
* array or Collection of values as parameter.
* <p>
* If there was no entry for that header name before, the value will be used
* as-is. In case of an existing entry, a String array will be created,
* adding the given value (more specifically, its toString representation)
* as further element.
* <p>
* Multiple values can only be stored as list of Strings, following the
* Servlet spec (see <code>getHeaders</code> accessor). As alternative to
* repeated <code>addHeader</code> calls for individual elements, you can
* use a single call with an entire array or Collection of values as
* parameter.
*
* @see #getHeaderNames
* @see #getHeader
* @see #getHeaders
* @see #getDateHeader
* @see #getIntHeader
*/
@SuppressWarnings("rawtypes")
public void addHeader(String name, Object value) {
HeaderValueHolder header = HeaderValueHolder.getByName(this.headers, name);
Assert.notNull(value, "Header value must not be null");
@@ -665,8 +672,8 @@ public class MockHttpServletRequest implements HttpServletRequest {
return ((Number) value).longValue();
}
else if (value != null) {
throw new IllegalArgumentException(
"Value for header '" + name + "' is neither a Date nor a Number: " + value);
throw new IllegalArgumentException("Value for header '" + name + "' is neither a Date nor a Number: "
+ value);
}
else {
return -1L;

View File

@@ -23,6 +23,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Vector;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionBindingEvent;
@@ -34,22 +35,22 @@ import org.springframework.util.Assert;
/**
* Mock implementation of the {@link javax.servlet.http.HttpSession} interface.
* Supports the Servlet 2.4 API level.
*
* <p>Used for testing the web framework; also useful for testing
* application controllers.
*
* <p>
* Used for testing the web framework; also useful for testing application
* controllers.
*
* @author Juergen Hoeller
* @author Rod Johnson
* @author Mark Fisher
* @since 1.0.2
*/
@SuppressWarnings("deprecation")
public class MockHttpSession implements HttpSession {
public static final String SESSION_COOKIE_NAME = "JSESSION";
private static int nextId = 1;
private final String id;
private final long creationTime = System.currentTimeMillis();
@@ -69,6 +70,7 @@ public class MockHttpSession implements HttpSession {
/**
* Create a new MockHttpSession with a default {@link MockServletContext}.
*
* @see MockServletContext
*/
public MockHttpSession() {
@@ -77,6 +79,7 @@ public class MockHttpSession implements HttpSession {
/**
* Create a new MockHttpSession.
*
* @param servletContext the ServletContext that the session runs in
*/
public MockHttpSession(ServletContext servletContext) {
@@ -85,6 +88,7 @@ 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
*/
@@ -93,7 +97,6 @@ public class MockHttpSession implements HttpSession {
this.id = (id != null ? id : Integer.toString(nextId++));
}
public long getCreationTime() {
return this.creationTime;
}
@@ -205,10 +208,10 @@ public class MockHttpSession implements HttpSession {
return this.isNew;
}
/**
* Serialize the attributes of this session into an object that can
* be turned into a byte array with standard Java serialization.
* 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() {
@@ -233,8 +236,9 @@ public class MockHttpSession implements HttpSession {
}
/**
* Deserialize the attributes of this session from a state object
* created by {@link #serializeState()}.
* 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")

View File

@@ -21,6 +21,7 @@ import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Vector;
import javax.el.ELContext;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
@@ -40,17 +41,18 @@ import org.springframework.util.Assert;
/**
* Mock implementation of the {@link javax.servlet.jsp.PageContext} interface.
*
* <p>Used for testing the web framework; only necessary for testing
* applications when testing custom JSP tags.
*
* <p>Note: Expects initialization via the constructor rather than via the
* <code>PageContext.initialize</code> method. Does not support writing to
* a JspWriter, request dispatching, and <code>handlePageException</code> calls.
*
* <p>
* Used for testing the web framework; only necessary for testing applications
* when testing custom JSP tags.
* <p>
* Note: Expects initialization via the constructor rather than via the
* <code>PageContext.initialize</code> method. Does not support writing to a
* JspWriter, request dispatching, and <code>handlePageException</code> calls.
*
* @author Juergen Hoeller
* @since 1.0.2
*/
@SuppressWarnings("deprecation")
public class MockPageContext extends PageContext {
private final ServletContext servletContext;
@@ -78,8 +80,9 @@ public class MockPageContext extends PageContext {
/**
* Create new MockPageContext with a default {@link MockHttpServletRequest},
* {@link MockHttpServletResponse}, {@link MockServletConfig}.
* @param servletContext the ServletContext that the JSP page runs in
* (only necessary when actually accessing the ServletContext)
*
* @param servletContext the ServletContext that the JSP page runs in (only
* necessary when actually accessing the ServletContext)
*/
public MockPageContext(ServletContext servletContext) {
this(servletContext, null, null, null);
@@ -88,9 +91,10 @@ public class MockPageContext extends PageContext {
/**
* Create new MockPageContext with a MockHttpServletResponse,
* MockServletConfig.
*
* @param servletContext the ServletContext that the JSP page runs in
* @param request the current HttpServletRequest
* (only necessary when actually accessing the request)
* @param request the current HttpServletRequest (only necessary when
* actually accessing the request)
*/
public MockPageContext(ServletContext servletContext, HttpServletRequest request) {
this(servletContext, request, null, null);
@@ -98,10 +102,11 @@ public class MockPageContext extends PageContext {
/**
* Create new MockPageContext with a MockServletConfig.
*
* @param servletContext the ServletContext that the JSP page runs in
* @param request the current HttpServletRequest
* @param response the current HttpServletResponse
* (only necessary when actually writing to the response)
* @param response the current HttpServletResponse (only necessary when
* actually writing to the response)
*/
public MockPageContext(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response) {
this(servletContext, request, response, null);
@@ -109,13 +114,15 @@ public class MockPageContext extends PageContext {
/**
* Create new MockServletConfig.
*
* @param servletContext the ServletContext that the JSP page runs in
* @param request the current HttpServletRequest
* @param response the current HttpServletResponse
* @param servletConfig the ServletConfig (hardly ever accessed from within a tag)
* @param servletConfig the ServletConfig (hardly ever accessed from within
* a tag)
*/
public MockPageContext(ServletContext servletContext, HttpServletRequest request,
HttpServletResponse response, ServletConfig servletConfig) {
public MockPageContext(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response,
ServletConfig servletConfig) {
this.servletContext = (servletContext != null ? servletContext : new MockServletContext());
this.request = (request != null ? request : new MockHttpServletRequest(servletContext));
@@ -123,10 +130,8 @@ public class MockPageContext extends PageContext {
this.servletConfig = (servletConfig != null ? servletConfig : new MockServletConfig(servletContext));
}
public void initialize(
Servlet servlet, ServletRequest request, ServletResponse response,
String errorPageURL, boolean needsSession, int bufferSize, boolean autoFlush) {
public void initialize(Servlet servlet, ServletRequest request, ServletResponse response, String errorPageURL,
boolean needsSession, int bufferSize, boolean autoFlush) {
throw new UnsupportedOperationException("Use appropriate constructor");
}

View File

@@ -27,6 +27,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
import javax.portlet.PortalContext;
import javax.portlet.PortletContext;
import javax.portlet.PortletMode;
@@ -41,7 +42,7 @@ import org.springframework.util.CollectionUtils;
/**
* Mock implementation of the {@link javax.portlet.PortletRequest} interface.
*
*
* @author John A. Lewis
* @author Juergen Hoeller
* @since 2.0
@@ -102,6 +103,7 @@ public class MockPortletRequest implements PortletRequest {
/**
* Create a new MockPortletRequest with a default {@link MockPortalContext}
* and a default {@link MockPortletContext}.
*
* @see MockPortalContext
* @see MockPortletContext
*/
@@ -111,6 +113,7 @@ public class MockPortletRequest implements PortletRequest {
/**
* Create a new MockPortletRequest with a default {@link MockPortalContext}.
*
* @param portletContext the PortletContext that the request runs in
* @see MockPortalContext
*/
@@ -120,6 +123,7 @@ public class MockPortletRequest implements PortletRequest {
/**
* Create a new MockPortletRequest.
*
* @param portalContext the PortalContext that the request runs in
* @param portletContext the PortletContext that the request runs in
*/
@@ -131,10 +135,9 @@ public class MockPortletRequest implements PortletRequest {
this.attributes.put(LIFECYCLE_PHASE, getLifecyclePhase());
}
//---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Lifecycle methods
//---------------------------------------------------------------------
// ---------------------------------------------------------------------
/**
* Return the Portlet 2.0 lifecycle id for the current phase.
@@ -167,10 +170,9 @@ public class MockPortletRequest implements PortletRequest {
}
}
//---------------------------------------------------------------------
// ---------------------------------------------------------------------
// PortletRequest methods
//---------------------------------------------------------------------
// ---------------------------------------------------------------------
public boolean isWindowStateAllowed(WindowState windowState) {
return CollectionUtils.contains(this.portalContext.getSupportedWindowStates(), windowState);
@@ -234,8 +236,9 @@ public class MockPortletRequest implements PortletRequest {
/**
* Set a single value for the specified property.
* <p>If there are already one or more values registered for the given
* property key, they will be replaced.
* <p>
* If there are already one or more values registered for the given property
* key, they will be replaced.
*/
public void setProperty(String key, String value) {
Assert.notNull(key, "Property key must not be null");
@@ -246,8 +249,9 @@ public class MockPortletRequest implements PortletRequest {
/**
* Add a single value for the specified property.
* <p>If there are already one or more values registered for the given
* property key, the given value will be added to the end of the list.
* <p>
* If there are already one or more values registered for the given property
* key, the given value will be added to the end of the list.
*/
public void addProperty(String key, String value) {
Assert.notNull(key, "Property key must not be null");
@@ -264,7 +268,7 @@ public class MockPortletRequest implements PortletRequest {
public String getProperty(String key) {
Assert.notNull(key, "Property key must not be null");
List list = this.properties.get(key);
List<String> list = this.properties.get(key);
return (list != null && list.size() > 0 ? (String) list.get(0) : null);
}
@@ -340,7 +344,7 @@ public class MockPortletRequest implements PortletRequest {
public void setParameter(String key, String value) {
Assert.notNull(key, "Parameter key must be null");
Assert.notNull(value, "Parameter value must not be null");
this.parameters.put(key, new String[] {value});
this.parameters.put(key, new String[] { value });
}
public void setParameter(String key, String[] values) {
@@ -350,7 +354,7 @@ public class MockPortletRequest implements PortletRequest {
}
public void addParameter(String name, String value) {
addParameter(name, new String[] {value});
addParameter(name, new String[] { value });
}
public void addParameter(String name, String[] values) {

View File

@@ -63,6 +63,7 @@ import org.springframework.util.Assert;
* ({@link org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests})
*/
@Deprecated
@SuppressWarnings({ "unchecked", "rawtypes" })
public abstract class AbstractDependencyInjectionSpringContextTests extends AbstractSingleSpringContextTests {
/**

View File

@@ -29,7 +29,6 @@ import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.jdbc.JdbcTestUtils;
import org.springframework.util.StringUtils;
/**
* Subclass of AbstractTransactionalSpringContextTests that adds some convenience
@@ -49,6 +48,7 @@ import org.springframework.util.StringUtils;
* ({@link org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests})
*/
@Deprecated
@SuppressWarnings({ "unchecked", "rawtypes" })
public abstract class AbstractTransactionalDataSourceSpringContextTests
extends AbstractTransactionalSpringContextTests {

View File

@@ -84,6 +84,7 @@ package org.springframework.test;
* @deprecated favor use of JUnit 4's {@code @Test(expected=...)} support
*/
@Deprecated
@SuppressWarnings({ "unchecked", "rawtypes" })
public abstract class AssertThrows {
private final Class expectedException;

View File

@@ -1,9 +1,7 @@
/**
*
* <p>Support classes for ApplicationContext-based and transactional
* tests run with JUnit 3.8 and the <em>Spring TestContext Framework</em>.</p>
*
*/
package org.springframework.test.context.junit38;

View File

@@ -462,6 +462,7 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
* @see RunBeforeTestMethodCallbacks
*/
@Override
@SuppressWarnings("deprecation")
protected Statement withBefores(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) {
Statement junitBefores = super.withBefores(frameworkMethod, testInstance, statement);
return new RunBeforeTestMethodCallbacks(junitBefores, testInstance, frameworkMethod.getMethod(),
@@ -477,6 +478,7 @@ public class SpringJUnit4ClassRunner extends BlockJUnit4ClassRunner {
* @see RunAfterTestMethodCallbacks
*/
@Override
@SuppressWarnings("deprecation")
protected Statement withAfters(FrameworkMethod frameworkMethod, Object testInstance, Statement statement) {
Statement junitAfters = super.withAfters(frameworkMethod, testInstance, statement);
return new RunAfterTestMethodCallbacks(junitAfters, testInstance, frameworkMethod.getMethod(),

View File

@@ -1,8 +1,6 @@
/**
*
* <p>Support classes for the <em>Spring TestContext Framework</em>.</p>
*
*/
package org.springframework.test.context.support;

View File

@@ -1,9 +1,7 @@
/**
*
* <p>Support classes for ApplicationContext-based and transactional
* tests run with TestNG and the <em>Spring TestContext Framework</em>.</p>
*
*/
package org.springframework.test.context.testng;

View File

@@ -52,8 +52,8 @@ import org.springframework.util.StringUtils;
* <p>
* <code>TestExecutionListener</code> which provides support for executing
* tests within transactions by using
* {@link org.springframework.transaction.annotation.Transactional @Transactional}
* and {@link NotTransactional @NotTransactional} annotations.
* {@link org.springframework.transaction.annotation.Transactional &#064;Transactional}
* and {@link NotTransactional &#064;NotTransactional} annotations.
* </p>
* <p>
* Changes to the database during a test run with &#064;Transactional will be
@@ -66,9 +66,9 @@ import org.springframework.util.StringUtils;
* </p>
* <p>
* Transactional commit and rollback behavior can be configured via the
* class-level {@link TransactionConfiguration @TransactionConfiguration} and
* method-level {@link Rollback @Rollback} annotations.
* {@link TransactionConfiguration @TransactionConfiguration} also provides
* class-level {@link TransactionConfiguration &#064;TransactionConfiguration} and
* method-level {@link Rollback &#064;Rollback} annotations.
* {@link TransactionConfiguration &#064;TransactionConfiguration} also provides
* configuration of the bean name of the {@link PlatformTransactionManager} that
* is to be used to drive transactions.
* </p>
@@ -77,8 +77,8 @@ import org.springframework.util.StringUtils;
* certain <em>set up</em> or <em>tear down</em> code outside of a
* transaction. <code>TransactionalTestExecutionListener</code> provides such
* support for methods annotated with
* {@link BeforeTransaction @BeforeTransaction} and
* {@link AfterTransaction @AfterTransaction}.
* {@link BeforeTransaction &#064;BeforeTransaction} and
* {@link AfterTransaction &#064;AfterTransaction}.
* </p>
*
* @author Sam Brannen
@@ -91,6 +91,7 @@ import org.springframework.util.StringUtils;
* @see BeforeTransaction
* @see AfterTransaction
*/
@SuppressWarnings("deprecation")
public class TransactionalTestExecutionListener extends AbstractTestExecutionListener {
private static final Log logger = LogFactory.getLog(TransactionalTestExecutionListener.class);
@@ -107,10 +108,10 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
/**
* If the test method of the supplied {@link TestContext test context} is
* configured to run within a transaction, this method will run
* {@link BeforeTransaction @BeforeTransaction methods} and start a new
* {@link BeforeTransaction &#064;BeforeTransaction methods} and start a new
* transaction.
* <p>Note that if a {@link BeforeTransaction @BeforeTransaction method} fails,
* remaining {@link BeforeTransaction @BeforeTransaction methods} will not
* <p>Note that if a {@link BeforeTransaction &#064;BeforeTransaction method} fails,
* remaining {@link BeforeTransaction &#064;BeforeTransaction methods} will not
* be invoked, and a transaction will not be started.
* @see org.springframework.transaction.annotation.Transactional
* @see org.springframework.test.annotation.NotTransactional
@@ -167,8 +168,8 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
/**
* If a transaction is currently active for the test method of the supplied
* {@link TestContext test context}, this method will end the transaction
* and run {@link AfterTransaction @AfterTransaction methods}.
* <p>{@link AfterTransaction @AfterTransaction methods} are guaranteed to be
* and run {@link AfterTransaction &#064;AfterTransaction methods}.
* <p>{@link AfterTransaction &#064;AfterTransaction methods} are guaranteed to be
* invoked even if an error occurs while ending the transaction.
*/
@Override
@@ -189,7 +190,7 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
}
/**
* Run all {@link BeforeTransaction @BeforeTransaction methods} for the
* Run all {@link BeforeTransaction &#064;BeforeTransaction methods} for the
* specified {@link TestContext test context}. If one of the methods fails,
* however, the caught exception will be rethrown in a wrapped
* {@link RuntimeException}, and the remaining methods will <strong>not</strong>
@@ -216,7 +217,7 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
}
/**
* Run all {@link AfterTransaction @AfterTransaction methods} for the
* Run all {@link AfterTransaction &#064;AfterTransaction methods} for the
* specified {@link TestContext test context}. If one of the methods fails,
* the caught exception will be logged as an error, and the remaining
* methods will be given a chance to execute. After all methods have
@@ -449,7 +450,7 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis
/**
* Retrieves the {@link TransactionConfigurationAttributes} for the
* specified {@link Class class} which may optionally declare or inherit a
* {@link TransactionConfiguration @TransactionConfiguration}. If a
* {@link TransactionConfiguration &#064;TransactionConfiguration}. If a
* {@link TransactionConfiguration} annotation is not present for the
* supplied class, the <em>default values</em> for attributes defined in
* {@link TransactionConfiguration} will be used instead.

View File

@@ -1,9 +1,7 @@
/**
*
* <p>Transactional support classes for the <em>Spring TestContext
* Framework</em>.</p>
*
*/
package org.springframework.test.context.transaction;

View File

@@ -1,8 +1,6 @@
/**
*
* Support classes for tests based on JDBC.
*
*/
package org.springframework.test.jdbc;

View File

@@ -161,6 +161,7 @@ public abstract class AbstractJpaTests extends AbstractAnnotationAwareTransactio
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void runBare() throws Throwable {
if (!shouldUseShadowLoader()) {
super.runBare();
@@ -308,6 +309,7 @@ public abstract class AbstractJpaTests extends AbstractAnnotationAwareTransactio
private final LoadTimeWeaver ltw;
@SuppressWarnings("unused")
public LoadTimeWeaverInjectingBeanPostProcessor(LoadTimeWeaver ltw) {
this.ltw = ltw;
}
@@ -328,6 +330,7 @@ public abstract class AbstractJpaTests extends AbstractAnnotationAwareTransactio
private final ClassLoader shadowingClassLoader;
@SuppressWarnings("unused")
public ShadowingLoadTimeWeaver(ClassLoader shadowingClassLoader) {
this.shadowingClassLoader = shadowingClassLoader;
}

View File

@@ -1,8 +1,6 @@
/**
*
* Helper classes for unit tests with reflective needs.
*
*/
package org.springframework.test.util;

View File

@@ -72,6 +72,7 @@ public abstract class AbstractModelAndViewTests extends TestCase {
* <code>null</code>)
* @param expectedList the expected list
*/
@SuppressWarnings("rawtypes")
protected void assertCompareListModelAttribute(ModelAndView mav, String modelName, List expectedList) {
try {
ModelAndViewAssert.assertCompareListModelAttribute(mav, modelName, expectedList);
@@ -139,6 +140,7 @@ public abstract class AbstractModelAndViewTests extends TestCase {
* not specifying the comparator, both lists will be sorted not using
* any comparator.
*/
@SuppressWarnings("rawtypes")
protected void assertSortAndCompareListModelAttribute(
ModelAndView mav, String modelName, List expectedList, Comparator comparator) {
try {

View File

@@ -27,13 +27,13 @@ import org.springframework.util.ObjectUtils;
import org.springframework.web.servlet.ModelAndView;
/**
* A collection of assertions intended to simplify testing scenarios
* dealing with Spring Web MVC
* {@link org.springframework.web.servlet.ModelAndView ModelAndView} objects.
*
* <p>Intended for use with JUnit 4 and TestNG.
* All <code>assert*()</code> methods throw {@link AssertionError}s.
*
* A collection of assertions intended to simplify testing scenarios dealing
* with Spring Web MVC {@link org.springframework.web.servlet.ModelAndView
* ModelAndView} objects.
* <p>
* Intended for use with JUnit 4 and TestNG. All <code>assert*()</code> methods
* throw {@link AssertionError}s.
*
* @author Sam Brannen
* @author Alef Arendsen
* @author Bram Smeets
@@ -44,8 +44,9 @@ public abstract class ModelAndViewAssert {
/**
* Checks whether the model value under the given <code>modelName</code>
* exists and checks it type, based on the <code>expectedType</code>. If
* the model entry exists and the type matches, the model value is returned.
* exists and checks it type, based on the <code>expectedType</code>. If the
* model entry exists and the type matches, the model value is returned.
*
* @param mav ModelAndView to test against (never <code>null</code>)
* @param modelName name of the object to add to the model (never
* <code>null</code>)
@@ -58,29 +59,32 @@ public abstract class ModelAndViewAssert {
assertCondition(mav.getModel() != null, "Model is null");
Object obj = mav.getModel().get(modelName);
assertCondition(obj != null, "Model attribute with name '" + modelName + "' is null");
assertCondition(expectedType.isAssignableFrom(obj.getClass()), "Model attribute is not of expected type '" +
expectedType.getName() + "' but rather of type '" + obj.getClass().getName() + "'");
assertCondition(expectedType.isAssignableFrom(obj.getClass()), "Model attribute is not of expected type '"
+ expectedType.getName() + "' but rather of type '" + obj.getClass().getName() + "'");
return (T) obj;
}
/**
* Compare each individual entry in a list, without first sorting the lists.
*
* @param mav ModelAndView to test against (never <code>null</code>)
* @param modelName name of the object to add to the model (never
* <code>null</code>)
* @param expectedList the expected list
*/
@SuppressWarnings("rawtypes")
public static void assertCompareListModelAttribute(ModelAndView mav, String modelName, List expectedList) {
assertCondition(mav != null, "ModelAndView is null");
List modelList = assertAndReturnModelAttributeOfType(mav, modelName, List.class);
assertCondition(expectedList.size() == modelList.size(), "Size of model list is '" + modelList.size() +
"' while size of expected list is '" + expectedList.size() + "'");
assertCondition(expectedList.equals(modelList), "List in model under name '" + modelName +
"' is not equal to the expected list.");
assertCondition(expectedList.size() == modelList.size(), "Size of model list is '" + modelList.size()
+ "' while size of expected list is '" + expectedList.size() + "'");
assertCondition(expectedList.equals(modelList), "List in model under name '" + modelName
+ "' is not equal to the expected list.");
}
/**
* Assert whether or not a model attribute is available.
*
* @param mav ModelAndView to test against (never <code>null</code>)
* @param modelName name of the object to add to the model (never
* <code>null</code>)
@@ -88,13 +92,14 @@ public abstract class ModelAndViewAssert {
public static void assertModelAttributeAvailable(ModelAndView mav, String modelName) {
assertCondition(mav != null, "ModelAndView is null");
assertCondition(mav.getModel() != null, "Model is null");
assertCondition(mav.getModel().containsKey(modelName), "Model attribute with name '" + modelName +
"' is not available");
assertCondition(mav.getModel().containsKey(modelName), "Model attribute with name '" + modelName
+ "' is not available");
}
/**
* Compare a given <code>expectedValue</code> to the value from the model
* bound under the given <code>modelName</code>.
*
* @param mav ModelAndView to test against (never <code>null</code>)
* @param modelName name of the object to add to the model (never
* <code>null</code>)
@@ -103,13 +108,14 @@ public abstract class ModelAndViewAssert {
public static void assertModelAttributeValue(ModelAndView mav, String modelName, Object expectedValue) {
assertCondition(mav != null, "ModelAndView is null");
Object modelValue = assertAndReturnModelAttributeOfType(mav, modelName, Object.class);
assertCondition(modelValue.equals(expectedValue), "Model value with name '" + modelName +
"' is not the same as the expected value which was '" + expectedValue + "'");
assertCondition(modelValue.equals(expectedValue), "Model value with name '" + modelName
+ "' is not the same as the expected value which was '" + expectedValue + "'");
}
/**
* Inspect the <code>expectedModel</code> to see if all elements in the
* model appear and are equal.
*
* @param mav ModelAndView to test against (never <code>null</code>)
* @param expectedModel the expected model
*/
@@ -128,8 +134,8 @@ public abstract class ModelAndViewAssert {
Object assertionValue = expectedModel.get(modelName);
Object mavValue = mav.getModel().get(modelName);
if (!assertionValue.equals(mavValue)) {
sb.append("Value under name '").append(modelName).append("' differs, should have been '")
.append(assertionValue).append("' but was '").append(mavValue).append("'\n");
sb.append("Value under name '").append(modelName).append("' differs, should have been '").append(
assertionValue).append("' but was '").append(mavValue).append("'\n");
}
}
@@ -142,23 +148,24 @@ public abstract class ModelAndViewAssert {
/**
* Compare each individual entry in a list after having sorted both lists
* (optionally using a comparator).
*
* @param mav ModelAndView to test against (never <code>null</code>)
* @param modelName name of the object to add to the model
* (never <code>null</code>)
* @param modelName name of the object to add to the model (never
* <code>null</code>)
* @param expectedList the expected list
* @param comparator the comparator to use (may be <code>null</code>).
* If not specifying the comparator, both lists will be sorted not using
* any comparator.
* @param comparator the comparator to use (may be <code>null</code>). If
* not specifying the comparator, both lists will be sorted not using any
* comparator.
*/
@SuppressWarnings("unchecked")
public static void assertSortAndCompareListModelAttribute(
ModelAndView mav, String modelName, List expectedList, Comparator comparator) {
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void assertSortAndCompareListModelAttribute(ModelAndView mav, String modelName, List expectedList,
Comparator comparator) {
assertCondition(mav != null, "ModelAndView is null");
List modelList = assertAndReturnModelAttributeOfType(mav, modelName, List.class);
assertCondition(expectedList.size() == modelList.size(), "Size of model list is '" + modelList.size() +
"' while size of expected list is '" + expectedList.size() + "'");
assertCondition(expectedList.size() == modelList.size(), "Size of model list is '" + modelList.size()
+ "' while size of expected list is '" + expectedList.size() + "'");
if (comparator != null) {
Collections.sort(modelList, comparator);
@@ -169,26 +176,27 @@ public abstract class ModelAndViewAssert {
Collections.sort(expectedList);
}
assertCondition(expectedList.equals(modelList), "List in model under name '" + modelName +
"' is not equal to the expected list.");
assertCondition(expectedList.equals(modelList), "List in model under name '" + modelName
+ "' is not equal to the expected list.");
}
/**
* Check to see if the view name in the ModelAndView matches the given
* <code>expectedName</code>.
*
* @param mav ModelAndView to test against (never <code>null</code>)
* @param expectedName the name of the model value
*/
public static void assertViewName(ModelAndView mav, String expectedName) {
assertCondition(mav != null, "ModelAndView is null");
assertCondition(ObjectUtils.nullSafeEquals(expectedName, mav.getViewName()),
"View name is not equal to '" + expectedName + "' but was '" + mav.getViewName() + "'");
assertCondition(ObjectUtils.nullSafeEquals(expectedName, mav.getViewName()), "View name is not equal to '"
+ expectedName + "' but was '" + mav.getViewName() + "'");
}
/**
* Fails by throwing an <code>AssertionError</code> with the supplied
* <code>message</code>.
*
* @param message the exception message to use
* @see #assertCondition(boolean,String)
*/
@@ -198,8 +206,9 @@ public abstract class ModelAndViewAssert {
/**
* Assert the provided boolean <code>condition</code>, throwing
* <code>AssertionError</code> with the supplied <code>message</code> if
* the test result is <code>false</code>.
* <code>AssertionError</code> with the supplied <code>message</code> if the
* test result is <code>false</code>.
*
* @param condition a boolean expression
* @param message the exception message to use if the assertion fails
* @see #fail(String)
@@ -210,8 +219,8 @@ public abstract class ModelAndViewAssert {
}
}
private static void appendNonMatchingSetsErrorMessage(
Set<String> assertionSet, Set<String> incorrectSet, StringBuilder sb) {
private static void appendNonMatchingSetsErrorMessage(Set<String> assertionSet, Set<String> incorrectSet,
StringBuilder sb) {
Set<String> tempSet = new HashSet<String>();
tempSet.addAll(incorrectSet);

View File

@@ -1,8 +1,6 @@
/**
*
* Helper classes for unit tests based on Spring's web support.
*
*/
package org.springframework.test.web;