Polishing

This commit is contained in:
Juergen Hoeller
2017-11-05 16:23:30 +01:00
parent 80a0cf71f4
commit e5c1deea63
10 changed files with 36 additions and 47 deletions

View File

@@ -40,7 +40,9 @@ class HeaderValueHolder {
public void setValue(Object value) {
this.values.clear();
this.values.add(value);
if (value != null) {
this.values.add(value);
}
}
public void addValue(Object value) {

View File

@@ -21,8 +21,6 @@ import javax.servlet.jsp.PageContext;
import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
import org.springframework.util.Assert;
/**
* Mock implementation of the JSP 2.0 {@link javax.servlet.jsp.el.ExpressionEvaluator}
* interface, delegating to the Apache JSTL ExpressionEvaluatorManager.
@@ -57,9 +55,7 @@ public class MockExpressionEvaluator extends javax.servlet.jsp.el.ExpressionEval
return new javax.servlet.jsp.el.Expression() {
@Override
public Object evaluate(javax.servlet.jsp.el.VariableResolver variableResolver)
throws javax.servlet.jsp.el.ELException {
public Object evaluate(javax.servlet.jsp.el.VariableResolver variableResolver) throws javax.servlet.jsp.el.ELException {
return doEvaluate(expression, expectedType, functionMapper);
}
};
@@ -67,26 +63,21 @@ public class MockExpressionEvaluator extends javax.servlet.jsp.el.ExpressionEval
@Override
@SuppressWarnings("rawtypes")
public Object evaluate(String expression, Class expectedType,
javax.servlet.jsp.el.VariableResolver variableResolver,
public Object evaluate(String expression, Class expectedType, javax.servlet.jsp.el.VariableResolver variableResolver,
javax.servlet.jsp.el.FunctionMapper functionMapper) throws javax.servlet.jsp.el.ELException {
Assert.isNull(variableResolver, "Custom VariableResolver not supported");
return doEvaluate(expression, expectedType, functionMapper);
}
@SuppressWarnings("rawtypes")
protected Object doEvaluate(String expression, Class expectedType,
javax.servlet.jsp.el.FunctionMapper functionMapper) throws javax.servlet.jsp.el.ELException {
protected Object doEvaluate(String expression, Class expectedType, javax.servlet.jsp.el.FunctionMapper functionMapper)
throws javax.servlet.jsp.el.ELException {
Assert.isNull(functionMapper, "Custom FunctionMapper not supported");
try {
return ExpressionEvaluatorManager.evaluate(
"JSP EL expression", expression, expectedType, this.pageContext);
return ExpressionEvaluatorManager.evaluate("JSP EL expression", expression, expectedType, this.pageContext);
}
catch (JspException ex) {
throw new javax.servlet.jsp.el.ELException(
"Parsing of JSP EL expression \"" + expression + "\" failed", ex);
throw new javax.servlet.jsp.el.ELException("Parsing of JSP EL expression \"" + expression + "\" failed", ex);
}
}

View File

@@ -43,7 +43,6 @@ import org.springframework.util.ObjectUtils;
* @author Juergen Hoeller
* @author Rob Winch
* @author Rossen Stoyanchev
*
* @since 2.0.3
* @see MockFilterConfig
* @see PassThroughFilterChain
@@ -70,7 +69,6 @@ public class MockFilterChain implements FilterChain {
/**
* Create a FilterChain with a Servlet.
*
* @param servlet the Servlet to invoke
* @since 3.2
*/
@@ -80,7 +78,6 @@ public class MockFilterChain implements FilterChain {
/**
* Create a {@code FilterChain} with Filter's and a Servlet.
*
* @param servlet the {@link Servlet} to invoke in this {@link FilterChain}
* @param filters the {@link Filter}'s to invoke in this {@link FilterChain}
* @since 3.2
@@ -96,6 +93,7 @@ public class MockFilterChain implements FilterChain {
return Arrays.asList(allFilters);
}
/**
* Return the request that {@link #doFilter} has been called with.
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -267,7 +267,7 @@ public class MockPageContext extends PageContext {
return this.request.getAttributeNames();
case SESSION_SCOPE:
HttpSession session = this.request.getSession(false);
return (session != null ? session.getAttributeNames() : null);
return (session != null ? session.getAttributeNames() : Collections.emptyEnumeration());
case APPLICATION_SCOPE:
return this.servletContext.getAttributeNames();
default:

View File

@@ -141,6 +141,7 @@ public class MockServletContext implements ServletContext {
private final Map<String, MediaType> mimeTypes = new LinkedHashMap<>();
/**
* Create a new {@code MockServletContext}, using no base path and a
* {@link DefaultResourceLoader} (i.e. the classpath root as WAR root).
@@ -179,7 +180,7 @@ public class MockServletContext implements ServletContext {
*/
public MockServletContext(String resourceBasePath, ResourceLoader resourceLoader) {
this.resourceLoader = (resourceLoader != null ? resourceLoader : new DefaultResourceLoader());
this.resourceBasePath = (resourceBasePath != null ? resourceBasePath : "");
this.resourceBasePath = resourceBasePath;
// Use JVM temp dir as ServletContext temp dir.
String tempDir = System.getProperty(TEMP_DIR_SYSTEM_PROPERTY);
@@ -204,7 +205,7 @@ public class MockServletContext implements ServletContext {
}
public void setContextPath(String contextPath) {
this.contextPath = (contextPath != null ? contextPath : "");
this.contextPath = contextPath;
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@ import org.springframework.util.Assert;
/**
* Implementation of the {@link javax.servlet.FilterConfig} interface which
* simply passes the call through to a given Filter/FilterChain combo
* simply passes the call through to a given Filter/FilterChain combination
* (indicating the next Filter in the chain along with the FilterChain that it is
* supposed to work on) or to a given Servlet (indicating the end of the chain).
*
@@ -79,6 +79,7 @@ public class PassThroughFilterChain implements FilterChain {
this.filter.doFilter(request, response, this.nextFilterChain);
}
else {
Assert.state(this.servlet != null, "Neither a Filter not a Servlet set");
this.servlet.service(request, response);
}
}