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

View File

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

View File

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

View File

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

View File

@ -27,6 +27,7 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Vector; import java.util.Vector;
import javax.portlet.PortalContext; import javax.portlet.PortalContext;
import javax.portlet.PortletContext; import javax.portlet.PortletContext;
import javax.portlet.PortletMode; import javax.portlet.PortletMode;
@ -102,6 +103,7 @@ public class MockPortletRequest implements PortletRequest {
/** /**
* Create a new MockPortletRequest with a default {@link MockPortalContext} * Create a new MockPortletRequest with a default {@link MockPortalContext}
* and a default {@link MockPortletContext}. * and a default {@link MockPortletContext}.
*
* @see MockPortalContext * @see MockPortalContext
* @see MockPortletContext * @see MockPortletContext
*/ */
@ -111,6 +113,7 @@ public class MockPortletRequest implements PortletRequest {
/** /**
* Create a new MockPortletRequest with a default {@link MockPortalContext}. * Create a new MockPortletRequest with a default {@link MockPortalContext}.
*
* @param portletContext the PortletContext that the request runs in * @param portletContext the PortletContext that the request runs in
* @see MockPortalContext * @see MockPortalContext
*/ */
@ -120,6 +123,7 @@ public class MockPortletRequest implements PortletRequest {
/** /**
* Create a new MockPortletRequest. * Create a new MockPortletRequest.
*
* @param portalContext the PortalContext that the request runs in * @param portalContext the PortalContext that the request runs in
* @param portletContext the PortletContext that the request runs in * @param portletContext the PortletContext that the request runs in
*/ */
@ -131,7 +135,6 @@ public class MockPortletRequest implements PortletRequest {
this.attributes.put(LIFECYCLE_PHASE, getLifecyclePhase()); this.attributes.put(LIFECYCLE_PHASE, getLifecyclePhase());
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// Lifecycle methods // Lifecycle methods
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
@ -167,7 +170,6 @@ public class MockPortletRequest implements PortletRequest {
} }
} }
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
// PortletRequest methods // PortletRequest methods
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
@ -234,8 +236,9 @@ public class MockPortletRequest implements PortletRequest {
/** /**
* Set a single value for the specified property. * Set a single value for the specified property.
* <p>If there are already one or more values registered for the given * <p>
* property key, they will be replaced. * 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) { public void setProperty(String key, String value) {
Assert.notNull(key, "Property key must not be null"); 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. * Add a single value for the specified property.
* <p>If there are already one or more values registered for the given * <p>
* property key, the given value will be added to the end of the list. * 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) { public void addProperty(String key, String value) {
Assert.notNull(key, "Property key must not be null"); Assert.notNull(key, "Property key must not be null");
@ -264,7 +268,7 @@ public class MockPortletRequest implements PortletRequest {
public String getProperty(String key) { public String getProperty(String key) {
Assert.notNull(key, "Property key must not be null"); 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); return (list != null && list.size() > 0 ? (String) list.get(0) : null);
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -21,6 +21,7 @@ import org.springframework.core.enums.ShortCodedLabeledEnum;
/** /**
* @author Rob Harrop * @author Rob Harrop
*/ */
@SuppressWarnings({ "serial", "deprecation" })
public class Colour extends ShortCodedLabeledEnum { public class Colour extends ShortCodedLabeledEnum {
public static final Colour RED = new Colour(0, "RED"); public static final Colour RED = new Colour(0, "RED");
@ -28,6 +29,7 @@ public class Colour extends ShortCodedLabeledEnum {
public static final Colour GREEN = new Colour(2, "GREEN"); public static final Colour GREEN = new Colour(2, "GREEN");
public static final Colour PURPLE = new Colour(3, "PURPLE"); public static final Colour PURPLE = new Colour(3, "PURPLE");
private Colour(int code, String label) { private Colour(int code, String label) {
super(code, label); super(code, label);
} }

View File

@ -30,6 +30,7 @@ import java.util.TreeSet;
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 11.11.2003 * @since 11.11.2003
*/ */
@SuppressWarnings("rawtypes")
public class IndexedTestBean { public class IndexedTestBean {
private TestBean[] array; private TestBean[] array;
@ -57,6 +58,7 @@ public class IndexedTestBean {
} }
} }
@SuppressWarnings("unchecked")
public void populate() { public void populate() {
TestBean tb0 = new TestBean("name0", 0); TestBean tb0 = new TestBean("name0", 0);
TestBean tb1 = new TestBean("name1", 0); TestBean tb1 = new TestBean("name1", 0);
@ -85,7 +87,6 @@ public class IndexedTestBean {
this.map.put("key4", list); this.map.put("key4", list);
} }
public TestBean[] getArray() { public TestBean[] getArray() {
return array; return array;
} }

View File

@ -40,6 +40,7 @@ import org.springframework.util.ObjectUtils;
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 15 April 2001 * @since 15 April 2001
*/ */
@SuppressWarnings("rawtypes")
public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOther, Comparable { public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOther, Comparable {
private String beanName; private String beanName;
@ -136,7 +137,6 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
this.someProperties = someProperties; this.someProperties = someProperties;
} }
public void setBeanName(String beanName) { public void setBeanName(String beanName) {
this.beanName = beanName; this.beanName = beanName;
} }
@ -366,7 +366,6 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
this.pets = pets; this.pets = pets;
} }
/** /**
* @see ITestBean#exceptional(Throwable) * @see ITestBean#exceptional(Throwable)
*/ */
@ -379,6 +378,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
public void unreliableFileOperation() throws IOException { public void unreliableFileOperation() throws IOException {
throw new IOException(); throw new IOException();
} }
/** /**
* @see ITestBean#returnsThis() * @see ITestBean#returnsThis()
*/ */
@ -396,7 +396,6 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
return age++; return age++;
} }
public void destroy() { public void destroy() {
this.destroyed = true; this.destroyed = true;
} }
@ -405,7 +404,6 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
return destroyed; return destroyed;
} }
public boolean equals(Object other) { public boolean equals(Object other) {
if (this == other) { if (this == other) {
return true; return true;

View File

@ -32,7 +32,7 @@ public class MockHttpServletRequestTests extends TestCase {
String headerName = "Header1"; String headerName = "Header1";
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader(headerName, "value1"); request.addHeader(headerName, "value1");
Enumeration requestHeaders = request.getHeaderNames(); Enumeration<String> requestHeaders = request.getHeaderNames();
assertNotNull(requestHeaders); assertNotNull(requestHeaders);
assertEquals("HTTP header casing not being preserved", headerName, requestHeaders.nextElement()); assertEquals("HTTP header casing not being preserved", headerName, requestHeaders.nextElement());
} }
@ -41,7 +41,7 @@ public class MockHttpServletRequestTests extends TestCase {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
request.setParameter("key1", "value1"); request.setParameter("key1", "value1");
request.setParameter("key2", "value2"); request.setParameter("key2", "value2");
Map params = new HashMap(2); Map<String, Object> params = new HashMap<String, Object>(2);
params.put("key1", "newValue1"); params.put("key1", "newValue1");
params.put("key3", new String[] { "value3A", "value3B" }); params.put("key3", new String[] { "value3A", "value3B" });
request.setParameters(params); request.setParameters(params);
@ -59,7 +59,7 @@ public class MockHttpServletRequestTests extends TestCase {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
request.setParameter("key1", "value1"); request.setParameter("key1", "value1");
request.setParameter("key2", "value2"); request.setParameter("key2", "value2");
Map params = new HashMap(2); Map<String, Object> params = new HashMap<String, Object>(2);
params.put("key1", "newValue1"); params.put("key1", "newValue1");
params.put("key3", new String[] { "value3A", "value3B" }); params.put("key3", new String[] { "value3A", "value3B" });
request.addParameters(params); request.addParameters(params);
@ -77,7 +77,7 @@ public class MockHttpServletRequestTests extends TestCase {
public void testRemoveAllParameters() { public void testRemoveAllParameters() {
MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletRequest request = new MockHttpServletRequest();
request.setParameter("key1", "value1"); request.setParameter("key1", "value1");
Map params = new HashMap(2); Map<String, Object> params = new HashMap<String, Object>(2);
params.put("key2", "value2"); params.put("key2", "value2");
params.put("key3", new String[] { "value3A", "value3B" }); params.put("key3", new String[] { "value3A", "value3B" });
request.addParameters(params); request.addParameters(params);

View File

@ -34,8 +34,8 @@ public class MockHttpServletResponseTests extends TestCase {
public void testSetContentTypeWithNoEncoding() { public void testSetContentTypeWithNoEncoding() {
MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletResponse response = new MockHttpServletResponse();
response.setContentType("test/plain"); response.setContentType("test/plain");
assertEquals("Character encoding should be the default", assertEquals("Character encoding should be the default", WebUtils.DEFAULT_CHARACTER_ENCODING,
WebUtils.DEFAULT_CHARACTER_ENCODING, response.getCharacterEncoding()); response.getCharacterEncoding());
} }
public void testSetContentTypeWithUTF8() { public void testSetContentTypeWithUTF8() {
@ -49,7 +49,7 @@ public class MockHttpServletResponseTests extends TestCase {
MockHttpServletResponse response = new MockHttpServletResponse(); MockHttpServletResponse response = new MockHttpServletResponse();
response.addHeader(headerName, "value1"); response.addHeader(headerName, "value1");
Set responseHeaders = response.getHeaderNames(); Set<String> responseHeaders = response.getHeaderNames();
assertNotNull(responseHeaders); assertNotNull(responseHeaders);
assertEquals(1, responseHeaders.size()); assertEquals(1, responseHeaders.size());
assertEquals("HTTP header casing not being preserved", headerName, responseHeaders.iterator().next()); assertEquals("HTTP header casing not being preserved", headerName, responseHeaders.iterator().next());

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2007 the original author or authors. * Copyright 2007-2011 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.
@ -28,6 +28,7 @@ import org.springframework.context.ApplicationContext;
* @author Sam Brannen * @author Sam Brannen
* @since 2.5 * @since 2.5
*/ */
@SuppressWarnings("deprecation")
public abstract class AbstractSpr3350SingleSpringContextTests extends AbstractDependencyInjectionSpringContextTests { public abstract class AbstractSpr3350SingleSpringContextTests extends AbstractDependencyInjectionSpringContextTests {
private Pet cat; private Pet cat;
@ -48,7 +49,8 @@ public abstract class AbstractSpr3350SingleSpringContextTests extends AbstractDe
/** /**
* Forcing concrete subclasses to provide a config path appropriate to the * Forcing concrete subclasses to provide a config path appropriate to the
* configured * configured
* {@link #createBeanDefinitionReader(org.springframework.context.support.GenericApplicationContext) BeanDefinitionReader}. * {@link #createBeanDefinitionReader(org.springframework.context.support.GenericApplicationContext)
* BeanDefinitionReader}.
* *
* @see org.springframework.test.AbstractSingleSpringContextTests#getConfigPath() * @see org.springframework.test.AbstractSingleSpringContextTests#getConfigPath()
*/ */
@ -62,12 +64,11 @@ public abstract class AbstractSpr3350SingleSpringContextTests extends AbstractDe
* {@link AbstractSingleSpringContextTests} always uses an * {@link AbstractSingleSpringContextTests} always uses an
* {@link XmlBeanDefinitionReader} internally when creating the * {@link XmlBeanDefinitionReader} internally when creating the
* {@link ApplicationContext} inside * {@link ApplicationContext} inside
* {@link #createApplicationContext(String[])}. It would be nice to have * {@link #createApplicationContext(String[])}. It would be nice to have the
* the bean definition reader creation in a separate method so that * bean definition reader creation in a separate method so that subclasses
* subclasses can choose that individually without having to copy-n-paste * can choose that individually without having to copy-n-paste code from
* code from createApplicationContext() to do the context creation and * createApplicationContext() to do the context creation and refresh.
* refresh. Consider JavaConfig where an Annotation based reader can be * Consider JavaConfig where an Annotation based reader can be plugged in.
* plugged in.
* </p> * </p>
*/ */
public final void testApplicationContextNotAutoCreated() { public final void testApplicationContextNotAutoCreated() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2007 the original author or authors. * Copyright 2007-2011 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.
@ -25,6 +25,7 @@ package org.springframework.test;
* @since 2.5 * @since 2.5
* @see Spr3264SingleSpringContextTests * @see Spr3264SingleSpringContextTests
*/ */
@SuppressWarnings("deprecation")
public class Spr3264DependencyInjectionSpringContextTests extends AbstractDependencyInjectionSpringContextTests { public class Spr3264DependencyInjectionSpringContextTests extends AbstractDependencyInjectionSpringContextTests {
public Spr3264DependencyInjectionSpringContextTests() { public Spr3264DependencyInjectionSpringContextTests() {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2007 the original author or authors. * Copyright 2007-2011 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.
@ -25,6 +25,7 @@ package org.springframework.test;
* @since 2.5 * @since 2.5
* @see Spr3264DependencyInjectionSpringContextTests * @see Spr3264DependencyInjectionSpringContextTests
*/ */
@SuppressWarnings("deprecation")
public class Spr3264SingleSpringContextTests extends AbstractSingleSpringContextTests { public class Spr3264SingleSpringContextTests extends AbstractSingleSpringContextTests {
public Spr3264SingleSpringContextTests() { public Spr3264SingleSpringContextTests() {

View File

@ -75,10 +75,12 @@ public class ProfileValueAnnotationAwareTransactionalTests extends TestCase {
} }
@SuppressWarnings("deprecation")
protected static class DefaultProfileValueSourceTestCase extends AbstractAnnotationAwareTransactionalTests { protected static class DefaultProfileValueSourceTestCase extends AbstractAnnotationAwareTransactionalTests {
int invocationCount = 0; int invocationCount = 0;
public DefaultProfileValueSourceTestCase() { public DefaultProfileValueSourceTestCase() {
} }
@ -130,12 +132,10 @@ public class ProfileValueAnnotationAwareTransactionalTests extends TestCase {
} }
} }
@ProfileValueSourceConfiguration(HardCodedProfileValueSource.class) @ProfileValueSourceConfiguration(HardCodedProfileValueSource.class)
protected static class HardCodedProfileValueSourceTestCase extends DefaultProfileValueSourceTestCase { protected static class HardCodedProfileValueSourceTestCase extends DefaultProfileValueSourceTestCase {
} }
public static class HardCodedProfileValueSource implements ProfileValueSource { public static class HardCodedProfileValueSource implements ProfileValueSource {
public String get(String key) { public String get(String key) {

View File

@ -23,8 +23,6 @@ import java.lang.reflect.Method;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/** /**
* Unit tests for {@link ProfileValueUtils}. * Unit tests for {@link ProfileValueUtils}.
@ -32,7 +30,6 @@ import org.junit.runners.JUnit4;
* @author Sam Brannen * @author Sam Brannen
* @since 3.0 * @since 3.0
*/ */
@RunWith(JUnit4.class)
public class ProfileValueUtilsTests { public class ProfileValueUtilsTests {
private static final String NON_ANNOTATED_METHOD = "nonAnnotatedMethod"; private static final String NON_ANNOTATED_METHOD = "nonAnnotatedMethod";

View File

@ -23,7 +23,6 @@ import javax.sql.DataSource;
import org.junit.internal.runners.JUnit38ClassRunner; import org.junit.internal.runners.JUnit38ClassRunner;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.Employee; import org.springframework.beans.Employee;
import org.springframework.beans.Pet; import org.springframework.beans.Pet;
import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.BeanNameAware;
@ -46,6 +45,7 @@ import org.springframework.test.jdbc.SimpleJdbcTestUtils;
* @author Sam Brannen * @author Sam Brannen
* @since 2.5 * @since 2.5
*/ */
@SuppressWarnings("deprecation")
@RunWith(JUnit38ClassRunner.class) @RunWith(JUnit38ClassRunner.class)
@ContextConfiguration @ContextConfiguration
public class ConcreteTransactionalJUnit38SpringContextTests extends AbstractTransactionalJUnit38SpringContextTests public class ConcreteTransactionalJUnit38SpringContextTests extends AbstractTransactionalJUnit38SpringContextTests

View File

@ -23,9 +23,9 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
/** /**
* Abstract base class for verifying support of Spring's * Abstract base class for verifying support of Spring's {@link Transactional
* {@link Transactional @Transactional} and * &#64;Transactional} and {@link NotTransactional &#64;NotTransactional}
* {@link NotTransactional @NotTransactional} annotations. * annotations.
* *
* @author Sam Brannen * @author Sam Brannen
* @since 2.5 * @since 2.5
@ -34,7 +34,8 @@ import org.springframework.transaction.annotation.Transactional;
* @see Transactional * @see Transactional
* @see NotTransactional * @see NotTransactional
*/ */
@ContextConfiguration(locations = {"transactionalTests-context.xml"}) @SuppressWarnings("deprecation")
@ContextConfiguration("transactionalTests-context.xml")
public abstract class AbstractTransactionalSpringRunnerTests { public abstract class AbstractTransactionalSpringRunnerTests {
protected static final String BOB = "bob"; protected static final String BOB = "bob";

View File

@ -26,7 +26,6 @@ import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.test.annotation.NotTransactional; import org.springframework.test.annotation.NotTransactional;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
@ -40,11 +39,11 @@ import org.springframework.transaction.annotation.Transactional;
/** /**
* <p> * <p>
* JUnit 4 based unit test which verifies support of Spring's * JUnit 4 based unit test which verifies support of Spring's
* {@link Transactional @Transactional}, * {@link Transactional &#64;Transactional}, {@link NotTransactional
* {@link NotTransactional @NotTransactional}, * &#64;NotTransactional}, {@link TestExecutionListeners
* {@link TestExecutionListeners @TestExecutionListeners}, and * &#64;TestExecutionListeners}, and {@link ContextConfiguration
* {@link ContextConfiguration @ContextConfiguration} annotations in conjunction * &#64;ContextConfiguration} annotations in conjunction with the
* with the {@link SpringJUnit4ClassRunner} and the following * {@link SpringJUnit4ClassRunner} and the following
* {@link TestExecutionListener TestExecutionListeners}: * {@link TestExecutionListener TestExecutionListeners}:
* </p> * </p>
* <ul> * <ul>
@ -61,6 +60,7 @@ import org.springframework.transaction.annotation.Transactional;
* @since 2.5 * @since 2.5
* @see MethodLevelTransactionalSpringRunnerTests * @see MethodLevelTransactionalSpringRunnerTests
*/ */
@SuppressWarnings("deprecation")
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration @ContextConfiguration
@Transactional @Transactional
@ -83,7 +83,6 @@ public class ClassLevelTransactionalSpringRunnerTests extends AbstractTransactio
countRowsInPersonTable(simpleJdbcTemplate)); countRowsInPersonTable(simpleJdbcTemplate));
} }
@Test @Test
public void modifyTestDataWithinTransaction() { public void modifyTestDataWithinTransaction() {
assertInTransaction(true); assertInTransaction(true);

View File

@ -29,7 +29,6 @@ import javax.sql.DataSource;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.Employee; import org.springframework.beans.Employee;
import org.springframework.beans.Pet; import org.springframework.beans.Pet;
import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.BeanNameAware;
@ -50,6 +49,7 @@ import org.springframework.test.jdbc.SimpleJdbcTestUtils;
* @author Sam Brannen * @author Sam Brannen
* @since 2.5 * @since 2.5
*/ */
@SuppressWarnings("deprecation")
@ContextConfiguration @ContextConfiguration
public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTransactionalJUnit4SpringContextTests public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTransactionalJUnit4SpringContextTests
implements BeanNameAware, InitializingBean { implements BeanNameAware, InitializingBean {
@ -61,7 +61,6 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
protected static final String LEIA = "leia"; protected static final String LEIA = "leia";
protected static final String YODA = "yoda"; protected static final String YODA = "yoda";
private boolean beanInitialized = false; private boolean beanInitialized = false;
private String beanName = "replace me with [" + getClass().getName() + "]"; private String beanName = "replace me with [" + getClass().getName() + "]";
@ -105,7 +104,6 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
return simpleJdbcTemplate.update("DELETE FROM person WHERE name=?", name); return simpleJdbcTemplate.update("DELETE FROM person WHERE name=?", name);
} }
@Resource @Resource
public void setDataSource(DataSource dataSource) { public void setDataSource(DataSource dataSource) {
super.setDataSource(dataSource); super.setDataSource(dataSource);
@ -129,7 +127,6 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
this.beanInitialized = true; this.beanInitialized = true;
} }
@Test @Test
@NotTransactional @NotTransactional
public final void verifyApplicationContext() { public final void verifyApplicationContext() {
@ -185,7 +182,6 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
assertEquals("The bar method should have been wired via @Resource.", "Bar", this.bar); assertEquals("The bar method should have been wired via @Resource.", "Bar", this.bar);
} }
@BeforeTransaction @BeforeTransaction
public void beforeTransaction() { public void beforeTransaction() {
assertEquals("Verifying the number of rows in the person table before a transactional test method.", 1, assertEquals("Verifying the number of rows in the person table before a transactional test method.", 1,

View File

@ -16,15 +16,16 @@
package org.springframework.test.context.junit4; package org.springframework.test.context.junit4;
import static org.junit.Assert.assertEquals;
import static org.springframework.test.transaction.TransactionTestUtils.assertInTransaction;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.junit.AfterClass; import org.junit.AfterClass;
import static org.junit.Assert.*;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListener; import org.springframework.test.context.TestExecutionListener;
@ -32,17 +33,15 @@ import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener; import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener; import org.springframework.test.context.support.DirtiesContextTestExecutionListener;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener; import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
import org.springframework.test.context.transaction.TransactionConfiguration;
import static org.springframework.test.transaction.TransactionTestUtils.*;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
/** /**
* <p> * <p>
* JUnit 4 based unit test which verifies support of Spring's * JUnit 4 based unit test which verifies support of Spring's
* {@link Transactional @Transactional}, * {@link Transactional &#64;Transactional}, {@link TestExecutionListeners
* {@link TestExecutionListeners @TestExecutionListeners}, and * &#64;TestExecutionListeners}, and {@link ContextConfiguration
* {@link ContextConfiguration @ContextConfiguration} annotations in conjunction * &#64;ContextConfiguration} annotations in conjunction with the
* with the {@link SpringJUnit4ClassRunner} and the following * {@link SpringJUnit4ClassRunner} and the following
* {@link TestExecutionListener TestExecutionListeners}: * {@link TestExecutionListener TestExecutionListeners}:
* </p> * </p>
* <ul> * <ul>

View File

@ -20,7 +20,6 @@ import static org.springframework.test.transaction.TransactionTestUtils.assertIn
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.test.annotation.NotTransactional; import org.springframework.test.annotation.NotTransactional;
import org.springframework.test.annotation.Repeat; import org.springframework.test.annotation.Repeat;
import org.springframework.test.annotation.Timed; import org.springframework.test.annotation.Timed;
@ -29,16 +28,17 @@ import org.springframework.transaction.annotation.Transactional;
/** /**
* JUnit 4 based unit test which verifies support of Spring's * JUnit 4 based unit test which verifies support of Spring's
* {@link Transactional @Transactional} and * {@link Transactional &#64;Transactional} and {@link NotTransactional
* {@link NotTransactional @NotTransactional} annotations in conjunction with * &#64;NotTransactional} annotations in conjunction with {@link Timed
* {@link Timed @Timed} and JUnit 4's {@link Test#timeout() timeout} attribute. * &#64;Timed} and JUnit 4's {@link Test#timeout() timeout} attribute.
* *
* @author Sam Brannen * @author Sam Brannen
* @since 2.5 * @since 2.5
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"transactionalTests-context.xml"}) @ContextConfiguration("transactionalTests-context.xml")
@Transactional @Transactional
@SuppressWarnings("deprecation")
public class TimedTransactionalSpringRunnerTests { public class TimedTransactionalSpringRunnerTests {
@Test @Test

View File

@ -51,6 +51,7 @@ import org.testng.annotations.Test;
* @author Sam Brannen * @author Sam Brannen
* @since 2.5 * @since 2.5
*/ */
@SuppressWarnings("deprecation")
@ContextConfiguration @ContextConfiguration
public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTransactionalTestNGSpringContextTests public class ConcreteTransactionalTestNGSpringContextTests extends AbstractTransactionalTestNGSpringContextTests
implements BeanNameAware, InitializingBean { implements BeanNameAware, InitializingBean {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2011 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.
@ -16,10 +16,13 @@
package org.springframework.test.jdbc; package org.springframework.test.jdbc;
import junit.framework.TestCase; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
/** /**
* Unit tests for {@link JdbcTestUtils}. * Unit tests for {@link JdbcTestUtils}.
@ -27,48 +30,48 @@ import java.util.ArrayList;
* @author Thomas Risberg * @author Thomas Risberg
* @since 2.5.4 * @since 2.5.4
*/ */
public class JdbcTestUtilsTests extends TestCase { public class JdbcTestUtilsTests {
public void testContainsDelimiters() { @Test
public void containsDelimiters() {
assertTrue("test with ';' is wrong", !JdbcTestUtils.containsSqlScriptDelimiters("select 1\n select ';'", ';')); assertTrue("test with ';' is wrong", !JdbcTestUtils.containsSqlScriptDelimiters("select 1\n select ';'", ';'));
assertTrue("test with delimiter ; is wrong", JdbcTestUtils.containsSqlScriptDelimiters("select 1; select 2", ';')); assertTrue("test with delimiter ; is wrong",
assertTrue("test with '\\n' is wrong", !JdbcTestUtils.containsSqlScriptDelimiters("select 1; select '\\n\n';", '\n')); JdbcTestUtils.containsSqlScriptDelimiters("select 1; select 2", ';'));
assertTrue("test with delimiter \\n is wrong", JdbcTestUtils.containsSqlScriptDelimiters("select 1\n select 2", '\n')); assertTrue("test with '\\n' is wrong",
!JdbcTestUtils.containsSqlScriptDelimiters("select 1; select '\\n\n';", '\n'));
assertTrue("test with delimiter \\n is wrong",
JdbcTestUtils.containsSqlScriptDelimiters("select 1\n select 2", '\n'));
} }
public void testSplitSqlScriptDelimitedWithSemicolon() { @Test
String statement1 = "insert into customer (id, name) \n" + public void splitSqlScriptDelimitedWithSemicolon() {
"values (1, 'Rod ; Johnson'), (2, 'Adrian \n Collier')"; String statement1 = "insert into customer (id, name) \n"
String statement2 = "insert into orders(id, order_date, customer_id) \n" + + "values (1, 'Rod ; Johnson'), (2, 'Adrian \n Collier')";
"values (1, '2008-01-02', 2)"; String statement2 = "insert into orders(id, order_date, customer_id) \n" + "values (1, '2008-01-02', 2)";
String statement3 = "insert into orders(id, order_date, customer_id) " + String statement3 = "insert into orders(id, order_date, customer_id) " + "values (1, '2008-01-02', 2)";
"values (1, '2008-01-02', 2)";
char delim = ';'; char delim = ';';
String script = statement1 + delim + statement2 + delim + statement3; String script = statement1 + delim + statement2 + delim + statement3;
List statements = new ArrayList(); List<String> statements = new ArrayList<String>();
JdbcTestUtils.splitSqlScript(script, delim, statements); JdbcTestUtils.splitSqlScript(script, delim, statements);
assertEquals("wrong number of statements", 3, statements.size()); assertEquals("wrong number of statements", 3, statements.size());
assertEquals("statement 1 not split correctly", statement1, statements.get(0)); assertEquals("statement 1 not split correctly", statement1, statements.get(0));
assertEquals("statement 2 not split correctly", statement2, statements.get(1)); assertEquals("statement 2 not split correctly", statement2, statements.get(1));
assertEquals("statement 3 not split correctly", statement3, statements.get(2)); assertEquals("statement 3 not split correctly", statement3, statements.get(2));
} }
public void testSplitSqlScriptDelimitedWithNewLine() { @Test
String statement1 = "insert into customer (id, name) " + public void splitSqlScriptDelimitedWithNewLine() {
"values (1, 'Rod ; Johnson'), (2, 'Adrian ; Collier')"; String statement1 = "insert into customer (id, name) " + "values (1, 'Rod ; Johnson'), (2, 'Adrian ; Collier')";
String statement2 = "insert into orders(id, order_date, customer_id) " + String statement2 = "insert into orders(id, order_date, customer_id) " + "values (1, '2008-01-02', 2)";
"values (1, '2008-01-02', 2)"; String statement3 = "insert into orders(id, order_date, customer_id) " + "values (1, '2008-01-02', 2)";
String statement3 = "insert into orders(id, order_date, customer_id) " +
"values (1, '2008-01-02', 2)";
char delim = '\n'; char delim = '\n';
String script = statement1 + delim + statement2 + delim + statement3; String script = statement1 + delim + statement2 + delim + statement3;
List statements = new ArrayList(); List<String> statements = new ArrayList<String>();
JdbcTestUtils.splitSqlScript(script, delim, statements); JdbcTestUtils.splitSqlScript(script, delim, statements);
assertEquals("wrong number of statements", 3, statements.size()); assertEquals("wrong number of statements", 3, statements.size());
assertEquals("statement 1 not split correctly", statement1, statements.get(0)); assertEquals("statement 1 not split correctly", statement1, statements.get(0));
assertEquals("statement 2 not split correctly", statement2, statements.get(1)); assertEquals("statement 2 not split correctly", statement2, statements.get(1));
assertEquals("statement 3 not split correctly", statement3, statements.get(2)); assertEquals("statement 3 not split correctly", statement3, statements.get(2));
}
} }
}

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008 the original author or authors. * Copyright 2002-2011 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.
@ -27,6 +27,7 @@ import org.springframework.test.util.subpackage.Person;
* @author Sam Brannen * @author Sam Brannen
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */
@SuppressWarnings("deprecation")
public class ReflectionTestUtilsTests extends TestCase { public class ReflectionTestUtilsTests extends TestCase {
protected static final Float PI = new Float((float) 22 / 7); protected static final Float PI = new Float((float) 22 / 7);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2007 the original author or authors. * Copyright 2007-2011 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.
@ -42,6 +42,7 @@ public class Person extends PersistentEntity {
return this.name; return this.name;
} }
@SuppressWarnings("unused")
private final void setName(final String name) { private final void setName(final String name) {
this.name = name; this.name = name;
} }

View File

@ -16,6 +16,11 @@
package org.springframework.web.multipart; package org.springframework.web.multipart;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.HashSet; import java.util.HashSet;
@ -25,8 +30,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import junit.framework.TestCase; import org.junit.Test;
import org.springframework.mock.web.MockMultipartFile; import org.springframework.mock.web.MockMultipartFile;
import org.springframework.mock.web.MockMultipartHttpServletRequest; import org.springframework.mock.web.MockMultipartHttpServletRequest;
import org.springframework.util.FileCopyUtils; import org.springframework.util.FileCopyUtils;
@ -35,9 +39,10 @@ import org.springframework.util.ObjectUtils;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller
*/ */
public class MockMultipartHttpServletRequestTests extends TestCase { public class MockMultipartHttpServletRequestTests {
public void testMockMultipartHttpServletRequestWithByteArray() throws IOException { @Test
public void mockMultipartHttpServletRequestWithByteArray() throws IOException {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
assertFalse(request.getFileNames().hasNext()); assertFalse(request.getFileNames().hasNext());
assertNull(request.getFile("file1")); assertNull(request.getFile("file1"));
@ -49,16 +54,18 @@ public class MockMultipartHttpServletRequestTests extends TestCase {
doTestMultipartHttpServletRequest(request); doTestMultipartHttpServletRequest(request);
} }
public void testMockMultipartHttpServletRequestWithInputStream() throws IOException { @Test
public void mockMultipartHttpServletRequestWithInputStream() throws IOException {
MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(); MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest();
request.addFile(new MockMultipartFile("file1", new ByteArrayInputStream("myContent1".getBytes()))); request.addFile(new MockMultipartFile("file1", new ByteArrayInputStream("myContent1".getBytes())));
request.addFile(new MockMultipartFile("file2", "myOrigFilename", "text/plain", new ByteArrayInputStream("myContent2".getBytes()))); request.addFile(new MockMultipartFile("file2", "myOrigFilename", "text/plain", new ByteArrayInputStream(
"myContent2".getBytes())));
doTestMultipartHttpServletRequest(request); doTestMultipartHttpServletRequest(request);
} }
private void doTestMultipartHttpServletRequest(MultipartHttpServletRequest request) throws IOException { private void doTestMultipartHttpServletRequest(MultipartHttpServletRequest request) throws IOException {
Set fileNames = new HashSet(); Set<String> fileNames = new HashSet<String>();
Iterator fileIter = request.getFileNames(); Iterator<String> fileIter = request.getFileNames();
while (fileIter.hasNext()) { while (fileIter.hasNext()) {
fileNames.add(fileIter.next()); fileNames.add(fileIter.next());
} }
@ -67,8 +74,8 @@ public class MockMultipartHttpServletRequestTests extends TestCase {
assertTrue(fileNames.contains("file2")); assertTrue(fileNames.contains("file2"));
MultipartFile file1 = request.getFile("file1"); MultipartFile file1 = request.getFile("file1");
MultipartFile file2 = request.getFile("file2"); MultipartFile file2 = request.getFile("file2");
Map fileMap = request.getFileMap(); Map<String, MultipartFile> fileMap = request.getFileMap();
List fileMapKeys = new LinkedList(fileMap.keySet()); List<String> fileMapKeys = new LinkedList<String>(fileMap.keySet());
assertEquals(2, fileMapKeys.size()); assertEquals(2, fileMapKeys.size());
assertEquals(file1, fileMap.get("file1")); assertEquals(file1, fileMap.get("file1"));
assertEquals(file2, fileMap.get("file2")); assertEquals(file2, fileMap.get("file2"));
@ -77,12 +84,14 @@ public class MockMultipartHttpServletRequestTests extends TestCase {
assertEquals("", file1.getOriginalFilename()); assertEquals("", file1.getOriginalFilename());
assertNull(file1.getContentType()); assertNull(file1.getContentType());
assertTrue(ObjectUtils.nullSafeEquals("myContent1".getBytes(), file1.getBytes())); assertTrue(ObjectUtils.nullSafeEquals("myContent1".getBytes(), file1.getBytes()));
assertTrue(ObjectUtils.nullSafeEquals("myContent1".getBytes(), FileCopyUtils.copyToByteArray(file1.getInputStream()))); assertTrue(ObjectUtils.nullSafeEquals("myContent1".getBytes(),
FileCopyUtils.copyToByteArray(file1.getInputStream())));
assertEquals("file2", file2.getName()); assertEquals("file2", file2.getName());
assertEquals("myOrigFilename", file2.getOriginalFilename()); assertEquals("myOrigFilename", file2.getOriginalFilename());
assertEquals("text/plain", file2.getContentType()); assertEquals("text/plain", file2.getContentType());
assertTrue(ObjectUtils.nullSafeEquals("myContent2".getBytes(), file2.getBytes())); assertTrue(ObjectUtils.nullSafeEquals("myContent2".getBytes(), file2.getBytes()));
assertTrue(ObjectUtils.nullSafeEquals("myContent2".getBytes(), FileCopyUtils.copyToByteArray(file2.getInputStream()))); assertTrue(ObjectUtils.nullSafeEquals("myContent2".getBytes(),
FileCopyUtils.copyToByteArray(file2.getInputStream())));
} }
} }