Polish
Remove: - auto-boxing - unnecessary array creation - public keyword on interface methods - unnecessary throws clauses Use lambda expressions
This commit is contained in:
@@ -32,6 +32,6 @@ public interface MapAdaptable<K, V> {
|
||||
* calculated) be cached as appropriate.
|
||||
* @return the object's contents as a map
|
||||
*/
|
||||
public Map<K, V> asMap();
|
||||
Map<K, V> asMap();
|
||||
|
||||
}
|
||||
|
||||
@@ -41,5 +41,5 @@ public interface SharedMap<K, V> extends Map<K, V> {
|
||||
*
|
||||
* @return the mutex
|
||||
*/
|
||||
public Object getMutex();
|
||||
}
|
||||
Object getMutex();
|
||||
}
|
||||
|
||||
@@ -28,18 +28,18 @@ public interface ConversionExecutor {
|
||||
* Returns the source class of conversions performed by this executor.
|
||||
* @return the source class
|
||||
*/
|
||||
public Class<?> getSourceClass();
|
||||
Class<?> getSourceClass();
|
||||
|
||||
/**
|
||||
* Returns the target class of conversions performed by this executor.
|
||||
* @return the target class
|
||||
*/
|
||||
public Class<?> getTargetClass();
|
||||
Class<?> getTargetClass();
|
||||
|
||||
/**
|
||||
* Execute the conversion for the provided source object.
|
||||
* @param source the source object to convert
|
||||
*/
|
||||
public Object execute(Object source) throws ConversionExecutionException;
|
||||
Object execute(Object source) throws ConversionExecutionException;
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public interface ConversionService {
|
||||
* @return the converted object, an instance of the <code>targetClass</code>
|
||||
* @throws ConversionException if an exception occurred during the conversion process
|
||||
*/
|
||||
public Object executeConversion(Object source, Class<?> targetClass) throws ConversionException;
|
||||
Object executeConversion(Object source, Class<?> targetClass) throws ConversionException;
|
||||
|
||||
/**
|
||||
* Execute a conversion using the custom converter with the provided id.
|
||||
@@ -43,7 +43,7 @@ public interface ConversionService {
|
||||
* @return the converted object, an instance of the <code>targetClass</code>
|
||||
* @throws ConversionException if an exception occurred during the conversion process
|
||||
*/
|
||||
public Object executeConversion(String converterId, Object source, Class<?> targetClass);
|
||||
Object executeConversion(String converterId, Object source, Class<?> targetClass);
|
||||
|
||||
/**
|
||||
* Return the default conversion executor capable of converting source objects of the specified
|
||||
@@ -55,7 +55,7 @@ public interface ConversionService {
|
||||
* @return the executor that can execute instance type conversion, never null
|
||||
* @throws ConversionExecutorNotFoundException when no suitable conversion executor could be found
|
||||
*/
|
||||
public ConversionExecutor getConversionExecutor(Class<?> sourceClass, Class<?> targetClass)
|
||||
ConversionExecutor getConversionExecutor(Class<?> sourceClass, Class<?> targetClass)
|
||||
throws ConversionExecutorNotFoundException;
|
||||
|
||||
/**
|
||||
@@ -69,7 +69,7 @@ public interface ConversionService {
|
||||
* @return the executor that can execute instance type conversion, never null
|
||||
* @throws ConversionExecutorNotFoundException when no suitable conversion executor could be found
|
||||
*/
|
||||
public ConversionExecutor getConversionExecutor(String id, Class<?> sourceClass, Class<?> targetClass)
|
||||
ConversionExecutor getConversionExecutor(String id, Class<?> sourceClass, Class<?> targetClass)
|
||||
throws ConversionExecutorNotFoundException;
|
||||
|
||||
/**
|
||||
@@ -77,13 +77,13 @@ public interface ConversionService {
|
||||
* @param alias the class alias
|
||||
* @return the class, or <code>null</code> if no alias exists
|
||||
*/
|
||||
public Class<?> getClassForAlias(String alias);
|
||||
Class<?> getClassForAlias(String alias);
|
||||
|
||||
/**
|
||||
* Return the underlying Spring ConversionService.
|
||||
*
|
||||
* @return the conversion service
|
||||
*/
|
||||
public org.springframework.core.convert.ConversionService getDelegateConversionService();
|
||||
org.springframework.core.convert.ConversionService getDelegateConversionService();
|
||||
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class ArrayToArray implements Converter {
|
||||
return Object[].class;
|
||||
}
|
||||
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception {
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public class ArrayToCollection implements TwoWayConverter {
|
||||
return collection;
|
||||
}
|
||||
|
||||
public Object convertTargetToSourceClass(Object target, Class<?> sourceClass) throws Exception {
|
||||
public Object convertTargetToSourceClass(Object target, Class<?> sourceClass) {
|
||||
if (target == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class CollectionToCollection implements Converter {
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception {
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -31,14 +31,14 @@ public interface Converter {
|
||||
* convert specific subclasses as well.
|
||||
* @return the source type
|
||||
*/
|
||||
public Class<?> getSourceClass();
|
||||
Class<?> getSourceClass();
|
||||
|
||||
/**
|
||||
* The target class this converter can convert to. May be an interface or abstract type to allow this converter to
|
||||
* convert specific subclasses as well.
|
||||
* @return the target type
|
||||
*/
|
||||
public Class<?> getTargetClass();
|
||||
Class<?> getTargetClass();
|
||||
|
||||
/**
|
||||
* Convert the provided source object argument to an instance of the specified target class.
|
||||
@@ -48,6 +48,6 @@ public interface Converter {
|
||||
* @return the converted object, which must be an instance of the <code>targetClass</code>
|
||||
* @throws Exception an exception occurred performing the conversion
|
||||
*/
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception;
|
||||
Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public class FormattedStringToNumber extends StringToObject {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Object toObject(String string, Class<?> targetClass) throws Exception {
|
||||
protected Object toObject(String string, Class<?> targetClass) {
|
||||
ParsePosition parsePosition = new ParsePosition(0);
|
||||
NumberFormat format = numberFormatFactory.getNumberFormat();
|
||||
Number number = format.parse(string, parsePosition);
|
||||
@@ -102,7 +102,7 @@ public class FormattedStringToNumber extends StringToObject {
|
||||
return convertToNumberClass(number, (Class<? extends Number>) targetClass);
|
||||
}
|
||||
|
||||
protected String toString(Object object) throws Exception {
|
||||
protected String toString(Object object) {
|
||||
Number number = (Number) object;
|
||||
return numberFormatFactory.getNumberFormat().format(number);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class NumberToNumber implements Converter {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception {
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) {
|
||||
return NumberUtils.convertNumberToTargetClass((Number) source, (Class<? extends Number>) targetClass);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class ObjectToArray implements Converter {
|
||||
return Object[].class;
|
||||
}
|
||||
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception {
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class ObjectToCollection implements Converter {
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception {
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -35,14 +35,14 @@ public class PropertyEditorConverter extends StringToObject {
|
||||
this.propertyEditor = propertyEditor;
|
||||
}
|
||||
|
||||
protected Object toObject(String string, Class<?> targetClass) throws Exception {
|
||||
protected Object toObject(String string, Class<?> targetClass) {
|
||||
synchronized (propertyEditor) {
|
||||
propertyEditor.setAsText(string);
|
||||
return propertyEditor.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
protected String toString(Object object) throws Exception {
|
||||
protected String toString(Object object) {
|
||||
synchronized (propertyEditor) {
|
||||
propertyEditor.setValue(object);
|
||||
return propertyEditor.getAsText();
|
||||
|
||||
@@ -50,7 +50,7 @@ public class SpringConvertingConverterAdapter implements Converter {
|
||||
this.conversionService = conversionService;
|
||||
}
|
||||
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception {
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) {
|
||||
return conversionService.convert(source, targetClass);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class StringToBigDecimal extends StringToObject {
|
||||
return new BigDecimal(string);
|
||||
}
|
||||
|
||||
public String toString(Object object) throws Exception {
|
||||
public String toString(Object object) {
|
||||
BigDecimal number = (BigDecimal) object;
|
||||
return number.toString();
|
||||
}
|
||||
|
||||
@@ -28,11 +28,11 @@ public class StringToBigInteger extends StringToObject {
|
||||
super(BigInteger.class);
|
||||
}
|
||||
|
||||
public Object toObject(String string, Class<?> objectClass) throws Exception {
|
||||
public Object toObject(String string, Class<?> objectClass) {
|
||||
return new BigInteger(string);
|
||||
}
|
||||
|
||||
public String toString(Object object) throws Exception {
|
||||
public String toString(Object object) {
|
||||
BigInteger number = (BigInteger) object;
|
||||
return number.toString();
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class StringToBoolean extends StringToObject {
|
||||
this.falseString = falseString;
|
||||
}
|
||||
|
||||
protected Object toObject(String string, Class<?> targetClass) throws Exception {
|
||||
protected Object toObject(String string, Class<?> targetClass) {
|
||||
if (trueString != null && string.equals(trueString)) {
|
||||
return true;
|
||||
} else if (falseString != null && string.equals(falseString)) {
|
||||
@@ -62,7 +62,7 @@ public class StringToBoolean extends StringToObject {
|
||||
}
|
||||
}
|
||||
|
||||
protected String toString(Object object) throws Exception {
|
||||
protected String toString(Object object) {
|
||||
Boolean value = (Boolean) object;
|
||||
if (Boolean.TRUE.equals(value)) {
|
||||
if (trueString != null) {
|
||||
|
||||
@@ -26,11 +26,11 @@ public class StringToByte extends StringToObject {
|
||||
super(Byte.class);
|
||||
}
|
||||
|
||||
public Object toObject(String string, Class<?> objectClass) throws Exception {
|
||||
public Object toObject(String string, Class<?> objectClass) {
|
||||
return Byte.valueOf(string);
|
||||
}
|
||||
|
||||
public String toString(Object object) throws Exception {
|
||||
public String toString(Object object) {
|
||||
Byte number = (Byte) object;
|
||||
return number.toString();
|
||||
}
|
||||
|
||||
@@ -21,11 +21,11 @@ public class StringToCharacter extends StringToObject {
|
||||
super(Character.class);
|
||||
}
|
||||
|
||||
protected Object toObject(String string, Class<?> targetClass) throws Exception {
|
||||
protected Object toObject(String string, Class<?> targetClass) {
|
||||
return new Character(string.charAt(0));
|
||||
}
|
||||
|
||||
protected String toString(Object object) throws Exception {
|
||||
protected String toString(Object object) {
|
||||
Character character = (Character) object;
|
||||
return character.toString();
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ public class StringToClass extends StringToObject {
|
||||
return ClassUtils.forName(string, classLoader);
|
||||
}
|
||||
|
||||
public String toString(Object object) throws Exception {
|
||||
public String toString(Object object) {
|
||||
Class<?> clazz = (Class<?>) object;
|
||||
return clazz.getName();
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class StringToDate extends StringToObject {
|
||||
this.locale = locale;
|
||||
}
|
||||
|
||||
public Object toObject(String string, Class<?> targetClass) throws Exception {
|
||||
public Object toObject(String string, Class<?> targetClass) {
|
||||
if (!StringUtils.hasText(string)) {
|
||||
return null;
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public class StringToDate extends StringToObject {
|
||||
}
|
||||
}
|
||||
|
||||
public String toString(Object target) throws Exception {
|
||||
public String toString(Object target) {
|
||||
Date date = (Date) target;
|
||||
if (date == null) {
|
||||
return "";
|
||||
|
||||
@@ -26,11 +26,11 @@ public class StringToDouble extends StringToObject {
|
||||
super(Double.class);
|
||||
}
|
||||
|
||||
public Object toObject(String string, Class<?> objectClass) throws Exception {
|
||||
public Object toObject(String string, Class<?> objectClass) {
|
||||
return Double.valueOf(string);
|
||||
}
|
||||
|
||||
public String toString(Object object) throws Exception {
|
||||
public String toString(Object object) {
|
||||
Double number = (Double) object;
|
||||
return number.toString();
|
||||
}
|
||||
|
||||
@@ -27,11 +27,11 @@ public class StringToEnum extends StringToObject {
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
protected Object toObject(String string, Class<?> targetClass) throws Exception {
|
||||
protected Object toObject(String string, Class<?> targetClass) {
|
||||
return Enum.valueOf((Class) targetClass, string);
|
||||
}
|
||||
|
||||
protected String toString(Object object) throws Exception {
|
||||
protected String toString(Object object) {
|
||||
return object.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,11 +26,11 @@ public class StringToFloat extends StringToObject {
|
||||
super(Float.class);
|
||||
}
|
||||
|
||||
public Object toObject(String string, Class<?> objectClass) throws Exception {
|
||||
public Object toObject(String string, Class<?> objectClass) {
|
||||
return Float.valueOf(string);
|
||||
}
|
||||
|
||||
public String toString(Object object) throws Exception {
|
||||
public String toString(Object object) {
|
||||
Float number = (Float) object;
|
||||
return number.toString();
|
||||
}
|
||||
|
||||
@@ -26,11 +26,11 @@ public class StringToInteger extends StringToObject {
|
||||
super(Integer.class);
|
||||
}
|
||||
|
||||
public Object toObject(String string, Class<?> objectClass) throws Exception {
|
||||
public Object toObject(String string, Class<?> objectClass) {
|
||||
return Integer.valueOf(string);
|
||||
}
|
||||
|
||||
public String toString(Object object) throws Exception {
|
||||
public String toString(Object object) {
|
||||
Integer number = (Integer) object;
|
||||
return number.toString();
|
||||
}
|
||||
|
||||
@@ -30,11 +30,11 @@ public class StringToLocale extends StringToObject {
|
||||
super(Locale.class);
|
||||
}
|
||||
|
||||
public Object toObject(String string, Class<?> objectClass) throws Exception {
|
||||
public Object toObject(String string, Class<?> objectClass) {
|
||||
return StringUtils.parseLocaleString(string);
|
||||
}
|
||||
|
||||
public String toString(Object object) throws Exception {
|
||||
public String toString(Object object) {
|
||||
Locale locale = (Locale) object;
|
||||
return locale.toString();
|
||||
}
|
||||
|
||||
@@ -26,11 +26,11 @@ public class StringToLong extends StringToObject {
|
||||
super(Long.class);
|
||||
}
|
||||
|
||||
public Object toObject(String string, Class<?> objectClass) throws Exception {
|
||||
public Object toObject(String string, Class<?> objectClass) {
|
||||
return Long.valueOf(string);
|
||||
}
|
||||
|
||||
public String toString(Object object) throws Exception {
|
||||
public String toString(Object object) {
|
||||
Long number = (Long) object;
|
||||
return number.toString();
|
||||
}
|
||||
|
||||
@@ -30,6 +30,6 @@ public interface TwoWayConverter extends Converter {
|
||||
* @return the converted object, which must be an instance of the <code>sourceClass</code>
|
||||
* @throws Exception an exception occurred performing the conversion
|
||||
*/
|
||||
public Object convertTargetToSourceClass(Object target, Class<?> sourceClass) throws Exception;
|
||||
Object convertTargetToSourceClass(Object target, Class<?> sourceClass) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class NoOpConverter implements Converter {
|
||||
return targetClass;
|
||||
}
|
||||
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) throws Exception {
|
||||
public Object convertSourceToTargetClass(Object source, Class<?> targetClass) {
|
||||
return source;
|
||||
}
|
||||
|
||||
@@ -52,8 +52,7 @@ class NoOpConverter implements Converter {
|
||||
return true;
|
||||
}
|
||||
|
||||
public Object convertTargetToSourceClass(Object target, Class<?> sourceClass) throws Exception,
|
||||
UnsupportedOperationException {
|
||||
public Object convertTargetToSourceClass(Object target, Class<?> sourceClass) {
|
||||
return target;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public interface Expression {
|
||||
* @return the evaluation result
|
||||
* @throws EvaluationException an exception occurred during expression evaluation
|
||||
*/
|
||||
public Object getValue(Object context) throws EvaluationException;
|
||||
Object getValue(Object context) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Set this expression in the provided context to the value provided.
|
||||
@@ -38,7 +38,7 @@ public interface Expression {
|
||||
* @param value the new value to set
|
||||
* @throws EvaluationException an exception occurred during expression evaluation
|
||||
*/
|
||||
public void setValue(Object context, Object value) throws EvaluationException;
|
||||
void setValue(Object context, Object value) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Returns the most general type that can be passed to the {@link #setValue(Object, Object)} method for the given
|
||||
@@ -48,12 +48,12 @@ public interface Expression {
|
||||
* information cannot be determined
|
||||
* @throws EvaluationException an exception occurred during expression evaluation
|
||||
*/
|
||||
public Class<?> getValueType(Object context) throws EvaluationException;
|
||||
Class<?> getValueType(Object context) throws EvaluationException;
|
||||
|
||||
/**
|
||||
* Returns the original string used to create this expression, unmodified.
|
||||
* @return the original expression string
|
||||
*/
|
||||
public String getExpressionString();
|
||||
String getExpressionString();
|
||||
|
||||
}
|
||||
|
||||
@@ -36,6 +36,6 @@ public interface ExpressionParser {
|
||||
* @return an evaluator for the parsed expression
|
||||
* @throws ParserException an exception occurred during parsing
|
||||
*/
|
||||
public Expression parseExpression(String expressionString, ParserContext context) throws ParserException;
|
||||
Expression parseExpression(String expressionString, ParserContext context) throws ParserException;
|
||||
|
||||
}
|
||||
@@ -26,20 +26,20 @@ public interface ParserContext {
|
||||
* value to install custom variable resolves for that particular type of context.
|
||||
* @return the evaluation context type
|
||||
*/
|
||||
public Class<?> getEvaluationContextType();
|
||||
Class<?> getEvaluationContextType();
|
||||
|
||||
/**
|
||||
* Returns the expected type of object returned from evaluating the parsed expression. An expression parser may use
|
||||
* this value to coerce an raw evaluation result before it is returned.
|
||||
* @return the expected evaluation result type
|
||||
*/
|
||||
public Class<?> getExpectedEvaluationResultType();
|
||||
Class<?> getExpectedEvaluationResultType();
|
||||
|
||||
/**
|
||||
* Returns additional expression variables or aliases that can be referenced during expression evaluation. An
|
||||
* expression parser will register these variables for reference during evaluation.
|
||||
*/
|
||||
public ExpressionVariable[] getExpressionVariables();
|
||||
ExpressionVariable[] getExpressionVariables();
|
||||
|
||||
/**
|
||||
* Whether or not the expression being parsed is a template. A template expression consists of literal text that can
|
||||
@@ -53,6 +53,6 @@ public interface ParserContext {
|
||||
*
|
||||
* @return true if the expression is a template, false otherwise
|
||||
*/
|
||||
public boolean isTemplate();
|
||||
boolean isTemplate();
|
||||
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@ package org.springframework.binding.expression.el;
|
||||
import javax.el.ELContext;
|
||||
import javax.el.ELException;
|
||||
import javax.el.ExpressionFactory;
|
||||
import javax.el.PropertyNotFoundException;
|
||||
import javax.el.PropertyNotWritableException;
|
||||
import javax.el.ValueExpression;
|
||||
|
||||
import org.springframework.binding.convert.ConversionException;
|
||||
@@ -45,22 +43,21 @@ class BindingValueExpression extends ValueExpression {
|
||||
return targetExpression.getExpectedType();
|
||||
}
|
||||
|
||||
public Class<?> getType(ELContext context) throws NullPointerException, PropertyNotFoundException, ELException {
|
||||
public Class<?> getType(ELContext context) throws NullPointerException, ELException {
|
||||
return targetExpression.getType(context);
|
||||
}
|
||||
|
||||
public Object getValue(ELContext context) throws NullPointerException, PropertyNotFoundException, ELException,
|
||||
public Object getValue(ELContext context) throws NullPointerException, ELException,
|
||||
ValueCoercionException {
|
||||
Object value = targetExpression.getValue(context);
|
||||
return convertValueIfNecessary(value, expectedType, context);
|
||||
}
|
||||
|
||||
public boolean isReadOnly(ELContext context) throws NullPointerException, PropertyNotFoundException, ELException {
|
||||
public boolean isReadOnly(ELContext context) throws NullPointerException, ELException {
|
||||
return targetExpression.isReadOnly(context);
|
||||
}
|
||||
|
||||
public void setValue(ELContext context, Object value) throws NullPointerException, PropertyNotFoundException,
|
||||
PropertyNotWritableException, ELException, ValueCoercionException {
|
||||
public void setValue(ELContext context, Object value) throws NullPointerException, ELException, ValueCoercionException {
|
||||
value = convertValueIfNecessary(value, targetExpression.getType(context), context);
|
||||
targetExpression.setValue(context, value);
|
||||
}
|
||||
|
||||
@@ -37,6 +37,6 @@ public interface ELContextFactory {
|
||||
* @param target The base object for the expression evaluation
|
||||
* @return ELContext The configured ELContext instance for evaluating expressions.
|
||||
*/
|
||||
public ELContext getELContext(Object target);
|
||||
ELContext getELContext(Object target);
|
||||
|
||||
}
|
||||
@@ -18,11 +18,9 @@ package org.springframework.binding.expression.el;
|
||||
import java.beans.FeatureDescriptor;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.el.ELContext;
|
||||
import javax.el.ELException;
|
||||
import javax.el.ELResolver;
|
||||
import javax.el.PropertyNotFoundException;
|
||||
import javax.el.PropertyNotWritableException;
|
||||
|
||||
import org.springframework.binding.collection.MapAdaptable;
|
||||
@@ -45,7 +43,7 @@ public class MapAdaptableELResolver extends ELResolver {
|
||||
}
|
||||
|
||||
public Class<?> getType(ELContext context, Object base, Object property) throws NullPointerException,
|
||||
PropertyNotFoundException, ELException {
|
||||
ELException {
|
||||
if (context == null) {
|
||||
throw new NullPointerException("The ELContext is null.");
|
||||
}
|
||||
@@ -60,7 +58,7 @@ public class MapAdaptableELResolver extends ELResolver {
|
||||
}
|
||||
|
||||
public Object getValue(ELContext context, Object base, Object property) throws NullPointerException,
|
||||
PropertyNotFoundException, ELException {
|
||||
ELException {
|
||||
if (context == null) {
|
||||
throw new NullPointerException("The ELContext is null.");
|
||||
}
|
||||
@@ -74,7 +72,7 @@ public class MapAdaptableELResolver extends ELResolver {
|
||||
}
|
||||
|
||||
public boolean isReadOnly(ELContext context, Object base, Object property) throws NullPointerException,
|
||||
PropertyNotFoundException, ELException {
|
||||
ELException {
|
||||
if (context == null) {
|
||||
throw new NullPointerException("The ELContext is null.");
|
||||
}
|
||||
@@ -87,7 +85,7 @@ public class MapAdaptableELResolver extends ELResolver {
|
||||
}
|
||||
|
||||
public void setValue(ELContext context, Object base, Object property, Object value) throws NullPointerException,
|
||||
PropertyNotFoundException, PropertyNotWritableException, ELException {
|
||||
ELException {
|
||||
if (context == null) {
|
||||
throw new NullPointerException("The ELContext is null.");
|
||||
}
|
||||
|
||||
@@ -15,6 +15,6 @@ public interface NumberFormatFactory {
|
||||
* display.
|
||||
* @return the number format
|
||||
*/
|
||||
public NumberFormat getNumberFormat();
|
||||
NumberFormat getNumberFormat();
|
||||
|
||||
}
|
||||
@@ -28,5 +28,5 @@ public interface Mapper {
|
||||
* @param target the target
|
||||
* @return results of the mapping transaction
|
||||
*/
|
||||
public MappingResults map(Object source, Object target);
|
||||
MappingResults map(Object source, Object target);
|
||||
}
|
||||
@@ -27,15 +27,15 @@ public interface Mapping {
|
||||
/**
|
||||
* The source of the mapping.
|
||||
*/
|
||||
public Expression getSourceExpression();
|
||||
Expression getSourceExpression();
|
||||
|
||||
/**
|
||||
* The target of the mapping.
|
||||
*/
|
||||
public Expression getTargetExpression();
|
||||
Expression getTargetExpression();
|
||||
|
||||
/**
|
||||
* Whether this is a required mapping.
|
||||
*/
|
||||
public boolean isRequired();
|
||||
boolean isRequired();
|
||||
}
|
||||
@@ -28,33 +28,33 @@ public interface MappingResult extends Serializable {
|
||||
/**
|
||||
* The mapping that executed for which this result pertains to.
|
||||
*/
|
||||
public Mapping getMapping();
|
||||
Mapping getMapping();
|
||||
|
||||
/**
|
||||
* The mapping result code; for example, "success" , "typeMismatch", "propertyNotFound", or "evaluationException".
|
||||
*/
|
||||
public String getCode();
|
||||
String getCode();
|
||||
|
||||
/**
|
||||
* Indicates if this result is an error result.
|
||||
*/
|
||||
public boolean isError();
|
||||
boolean isError();
|
||||
|
||||
/**
|
||||
* Get the cause of the error result
|
||||
* @return the underyling cause, or null if this is not an error or there was no root cause.
|
||||
*/
|
||||
public Throwable getErrorCause();
|
||||
Throwable getErrorCause();
|
||||
|
||||
/**
|
||||
* The original value of the source object that was to be mapped. May be null if this result is an error on the
|
||||
* source object.
|
||||
*/
|
||||
public Object getOriginalValue();
|
||||
Object getOriginalValue();
|
||||
|
||||
/**
|
||||
* The actual value that was mapped to the target object. Null if this result is an error.
|
||||
*/
|
||||
public Object getMappedValue();
|
||||
Object getMappedValue();
|
||||
|
||||
}
|
||||
@@ -28,32 +28,32 @@ public interface MappingResults extends Serializable {
|
||||
/**
|
||||
* The source object that was mapped from.
|
||||
*/
|
||||
public Object getSource();
|
||||
Object getSource();
|
||||
|
||||
/**
|
||||
* The target object that was mapped to.
|
||||
*/
|
||||
public Object getTarget();
|
||||
Object getTarget();
|
||||
|
||||
/**
|
||||
* A list of all the mapping results between the source and target.
|
||||
*/
|
||||
public List<MappingResult> getAllResults();
|
||||
List<MappingResult> getAllResults();
|
||||
|
||||
/**
|
||||
* Whether some results were errors. Returns true if mapping errors occurred.
|
||||
*/
|
||||
public boolean hasErrorResults();
|
||||
boolean hasErrorResults();
|
||||
|
||||
/**
|
||||
* A list of all error results that occurred.
|
||||
*/
|
||||
public List<MappingResult> getErrorResults();
|
||||
List<MappingResult> getErrorResults();
|
||||
|
||||
/**
|
||||
* Get all results that meet the given result criteria.
|
||||
* @param criteria the mapping result criteria
|
||||
*/
|
||||
public List<MappingResult> getResults(MappingResultsCriteria criteria);
|
||||
List<MappingResult> getResults(MappingResultsCriteria criteria);
|
||||
|
||||
}
|
||||
|
||||
@@ -27,5 +27,5 @@ public interface MappingResultsCriteria {
|
||||
* @param result the result
|
||||
* @return true if so, false if not
|
||||
*/
|
||||
public boolean test(MappingResult result);
|
||||
boolean test(MappingResult result);
|
||||
}
|
||||
|
||||
@@ -24,36 +24,36 @@ public interface MessageContext {
|
||||
* Get all messages in this context. The messages returned should be suitable for display as-is.
|
||||
* @return the messages
|
||||
*/
|
||||
public Message[] getAllMessages();
|
||||
Message[] getAllMessages();
|
||||
|
||||
/**
|
||||
* Get all messages in this context for the source provided.
|
||||
* @param source the source associated with messages, or null for global messages
|
||||
* @return the source's messages
|
||||
*/
|
||||
public Message[] getMessagesBySource(Object source);
|
||||
Message[] getMessagesBySource(Object source);
|
||||
|
||||
/**
|
||||
* Get all messages that meet the given result criteria.
|
||||
* @param criteria the message criteria
|
||||
*/
|
||||
public Message[] getMessagesByCriteria(MessageCriteria criteria);
|
||||
Message[] getMessagesByCriteria(MessageCriteria criteria);
|
||||
|
||||
/**
|
||||
* Returns true if there are error messages in this context.
|
||||
* @return error messages
|
||||
*/
|
||||
public boolean hasErrorMessages();
|
||||
boolean hasErrorMessages();
|
||||
|
||||
/**
|
||||
* Add a new message to this context.
|
||||
* @param messageResolver the resolver that will resolve the message to be added
|
||||
*/
|
||||
public void addMessage(MessageResolver messageResolver);
|
||||
void addMessage(MessageResolver messageResolver);
|
||||
|
||||
/**
|
||||
* Clear all messages added to this context.
|
||||
*/
|
||||
public void clearMessages();
|
||||
void clearMessages();
|
||||
|
||||
}
|
||||
|
||||
@@ -157,23 +157,19 @@ public class MessageContextErrors extends AbstractErrors {
|
||||
return expressionParser.parseExpression(field, new FluentParserContext().evaluate(boundObject.getClass()));
|
||||
}
|
||||
|
||||
private static MessageCriteria GLOBAL_ERROR = new MessageCriteria() {
|
||||
public boolean test(Message message) {
|
||||
if (message.getSeverity() == Severity.ERROR && message.getSource() == null) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
private static MessageCriteria GLOBAL_ERROR = message -> {
|
||||
if (message.getSeverity() == Severity.ERROR && message.getSource() == null) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
private static MessageCriteria FIELD_ERROR = new MessageCriteria() {
|
||||
public boolean test(Message message) {
|
||||
if (message.getSeverity() == Severity.ERROR && message.getSource() instanceof String) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
private static MessageCriteria FIELD_ERROR = message -> {
|
||||
if (message.getSeverity() == Severity.ERROR && message.getSource() instanceof String) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -27,5 +27,5 @@ public interface MessageCriteria {
|
||||
* @param message the message
|
||||
* @return true if this criteria is met for the message, false if not
|
||||
*/
|
||||
public boolean test(Message message);
|
||||
boolean test(Message message);
|
||||
}
|
||||
|
||||
@@ -35,5 +35,5 @@ public interface MessageResolver {
|
||||
* @param locale the current locale of this request
|
||||
* @return the resolved message
|
||||
*/
|
||||
public Message resolveMessage(MessageSource messageSource, Locale locale);
|
||||
Message resolveMessage(MessageSource messageSource, Locale locale);
|
||||
}
|
||||
|
||||
@@ -32,14 +32,14 @@ public interface StateManageableMessageContext extends MessageContext {
|
||||
* Create a serializable memento, or token representing a snapshot of the internal state of this message context.
|
||||
* @return the messages memento
|
||||
*/
|
||||
public Serializable createMessagesMemento();
|
||||
Serializable createMessagesMemento();
|
||||
|
||||
/**
|
||||
* Set the state of this context from the memento provided. After this call, the messages in this context will match
|
||||
* what is encapsulated inside the memento. Any previous state will be overridden.
|
||||
* @param messagesMemento the messages memento
|
||||
*/
|
||||
public void restoreMessages(Serializable messagesMemento);
|
||||
void restoreMessages(Serializable messagesMemento);
|
||||
|
||||
/**
|
||||
* Configure the message source used to resolve messages added to this context. May be set at any time to change how
|
||||
@@ -47,5 +47,5 @@ public interface StateManageableMessageContext extends MessageContext {
|
||||
* @param messageSource the message source
|
||||
* @see MessageContext#addMessage(MessageResolver)
|
||||
*/
|
||||
public void setMessageSource(MessageSource messageSource);
|
||||
void setMessageSource(MessageSource messageSource);
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ public class MethodKey implements Serializable {
|
||||
* Map with primitive wrapper type as key and corresponding primitive type as value, for example: Integer.class ->
|
||||
* int.class.
|
||||
*/
|
||||
private static final Map<Class<?>, Class<?>> PRIMITIVE_WRAPPER_TYPE_MAP = new HashMap<Class<?>, Class<?>>(8);
|
||||
private static final Map<Class<?>, Class<?>> PRIMITIVE_WRAPPER_TYPE_MAP = new HashMap<>(8);
|
||||
static {
|
||||
PRIMITIVE_WRAPPER_TYPE_MAP.put(Boolean.class, boolean.class);
|
||||
PRIMITIVE_WRAPPER_TYPE_MAP.put(Byte.class, byte.class);
|
||||
|
||||
@@ -31,23 +31,23 @@ public interface ValidationContext {
|
||||
/**
|
||||
* A context for adding failure messages to display to the user directly.
|
||||
*/
|
||||
public MessageContext getMessageContext();
|
||||
MessageContext getMessageContext();
|
||||
|
||||
/**
|
||||
* The current user.
|
||||
*/
|
||||
public Principal getUserPrincipal();
|
||||
Principal getUserPrincipal();
|
||||
|
||||
/**
|
||||
* The current user event that triggered validation.
|
||||
*/
|
||||
public String getUserEvent();
|
||||
String getUserEvent();
|
||||
|
||||
/**
|
||||
* Obtain the value entered by the current user in the UI field bound to the property provided.
|
||||
* @param property the name of a bound property
|
||||
* @return the value the user entered in the field bound to the property
|
||||
*/
|
||||
public Object getUserValue(String property);
|
||||
Object getUserValue(String property);
|
||||
|
||||
}
|
||||
|
||||
@@ -220,16 +220,8 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
ConversionExecutor executor = service.getConversionExecutor("princy", Principal[].class, List.class);
|
||||
final Principal princy1 = new Principal() {
|
||||
public String getName() {
|
||||
return "princy1";
|
||||
}
|
||||
};
|
||||
final Principal princy2 = new Principal() {
|
||||
public String getName() {
|
||||
return "princy2";
|
||||
}
|
||||
};
|
||||
final Principal princy1 = () -> "princy1";
|
||||
final Principal princy2 = () -> "princy2";
|
||||
List<String> p = (List<String>) executor.execute(new Principal[] { princy1, princy2 });
|
||||
assertEquals("princy1", p.get(0));
|
||||
assertEquals("princy2", p.get(1));
|
||||
@@ -262,16 +254,8 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
ConversionExecutor executor = service.getConversionExecutor("princy", List.class, String[].class);
|
||||
final Principal princy1 = new Principal() {
|
||||
public String getName() {
|
||||
return "princy1";
|
||||
}
|
||||
};
|
||||
final Principal princy2 = new Principal() {
|
||||
public String getName() {
|
||||
return "princy2";
|
||||
}
|
||||
};
|
||||
final Principal princy1 = () -> "princy1";
|
||||
final Principal princy2 = () -> "princy2";
|
||||
List<Principal> princyList = new ArrayList<>();
|
||||
princyList.add(princy1);
|
||||
princyList.add(princy2);
|
||||
@@ -303,11 +287,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
ConversionExecutor executor = service.getConversionExecutor("princy", Principal.class, String[].class);
|
||||
final Principal princy1 = new Principal() {
|
||||
public String getName() {
|
||||
return "princy1";
|
||||
}
|
||||
};
|
||||
final Principal princy1 = () -> "princy1";
|
||||
String[] p = (String[]) executor.execute(princy1);
|
||||
assertEquals("princy1", p[0]);
|
||||
}
|
||||
@@ -359,11 +339,7 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
ConversionExecutor executor = service.getConversionExecutor("princy", Principal.class, List.class);
|
||||
final Principal princy1 = new Principal() {
|
||||
public String getName() {
|
||||
return "princy1";
|
||||
}
|
||||
};
|
||||
final Principal princy1 = () -> "princy1";
|
||||
List<String> list = (List<String>) executor.execute(princy1);
|
||||
assertEquals("princy1", list.get(0));
|
||||
}
|
||||
@@ -386,16 +362,8 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
DefaultConversionService service = new DefaultConversionService();
|
||||
service.addConverter("princy", new CustomTwoWayConverter());
|
||||
ConversionExecutor executor = service.getConversionExecutor("princy", List.class, List.class);
|
||||
final Principal princy1 = new Principal() {
|
||||
public String getName() {
|
||||
return "princy1";
|
||||
}
|
||||
};
|
||||
final Principal princy2 = new Principal() {
|
||||
public String getName() {
|
||||
return "princy2";
|
||||
}
|
||||
};
|
||||
final Principal princy1 = () -> "princy1";
|
||||
final Principal princy2 = () -> "princy2";
|
||||
List<Principal> princyList = new ArrayList<>();
|
||||
princyList.add(princy1);
|
||||
princyList.add(princy2);
|
||||
@@ -598,21 +566,17 @@ public class DefaultConversionServiceTests extends TestCase {
|
||||
super(List.class);
|
||||
}
|
||||
|
||||
protected Object toObject(String string, Class<?> targetClass) throws Exception {
|
||||
protected Object toObject(String string, Class<?> targetClass) {
|
||||
List<Principal> principals = new ArrayList<>();
|
||||
StringTokenizer tokenizer = new StringTokenizer(string, ",");
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
final String name = tokenizer.nextToken();
|
||||
principals.add(new Principal() {
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
});
|
||||
principals.add(() -> name);
|
||||
}
|
||||
return principals;
|
||||
}
|
||||
|
||||
protected String toString(Object object) throws Exception {
|
||||
protected String toString(Object object) {
|
||||
throw new UnsupportedOperationException("No implemented");
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ public class StaticConversionExecutorImplTests extends TestCase {
|
||||
|
||||
private StaticConversionExecutor conversionExecutor;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
protected void setUp() {
|
||||
StringToDate stringToDate = new StringToDate();
|
||||
conversionExecutor = new StaticConversionExecutor(String.class, Date.class, stringToDate);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class ELExpressionParserTests extends TestCase {
|
||||
public void testParseSimpleEvalExpressionNoParserContext() {
|
||||
String expressionString = "3 + 4";
|
||||
Expression exp = parser.parseExpression(expressionString, null);
|
||||
assertEquals(new Long(7), exp.getValue(null));
|
||||
assertEquals(7L, exp.getValue(null));
|
||||
}
|
||||
|
||||
public void testParseNullExpressionString() {
|
||||
@@ -61,7 +61,7 @@ public class ELExpressionParserTests extends TestCase {
|
||||
String expressionString = "3 + 4";
|
||||
Expression exp = parser
|
||||
.parseExpression(expressionString, new FluentParserContext().expectResult(Integer.class));
|
||||
assertEquals(new Integer(7), exp.getValue(null));
|
||||
assertEquals(7, exp.getValue(null));
|
||||
}
|
||||
|
||||
public void testParseBeanEvalExpressionNoParserContext() {
|
||||
@@ -73,7 +73,7 @@ public class ELExpressionParserTests extends TestCase {
|
||||
public void testParseEvalExpressionWithContextTypeCoersion() {
|
||||
String expressionString = "maximum";
|
||||
Expression exp = parser.parseExpression(expressionString, new FluentParserContext().expectResult(Long.class));
|
||||
assertEquals(new Long(2), exp.getValue(new TestBean()));
|
||||
assertEquals(2L, exp.getValue(new TestBean()));
|
||||
}
|
||||
|
||||
public void testParseEvalExpressionWithContextCustomELVariableResolver() {
|
||||
@@ -119,7 +119,7 @@ public class ELExpressionParserTests extends TestCase {
|
||||
Expression exp = parser.parseExpression("max", new FluentParserContext().variable(new ExpressionVariable("max",
|
||||
"maximum", new FluentParserContext().expectResult(Long.class))));
|
||||
TestBean target = new TestBean();
|
||||
assertEquals(new Long(2), exp.getValue(target));
|
||||
assertEquals(2L, exp.getValue(target));
|
||||
}
|
||||
|
||||
public void testTemplateNestedVariables() {
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ELExpressionParserCompatibilityTests extends TestCase {
|
||||
|
||||
private SpringELExpressionParser parser = new SpringELExpressionParser(new SpelExpressionParser());
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
protected void setUp() {
|
||||
parser.addPropertyAccessor(new SpecialPropertyAccessor());
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class ELExpressionParserCompatibilityTests extends TestCase {
|
||||
public void testParseSimpleEvalExpressionNoEvalContextWithTypeCoersion() {
|
||||
String expressionString = "3 + 4";
|
||||
Expression exp = parser.parseExpression(expressionString, new FluentParserContext().expectResult(Long.class));
|
||||
assertEquals(new Long(7), exp.getValue(null));
|
||||
assertEquals(7L, exp.getValue(null));
|
||||
}
|
||||
|
||||
public void testParseBeanEvalExpressionNoParserContext() {
|
||||
@@ -95,7 +95,7 @@ public class ELExpressionParserCompatibilityTests extends TestCase {
|
||||
String expressionString = "maximum";
|
||||
Expression exp = parser
|
||||
.parseExpression(expressionString, new FluentParserContext().expectResult(Integer.class));
|
||||
assertEquals(new Integer(2), exp.getValue(new TestBean()));
|
||||
assertEquals(2, exp.getValue(new TestBean()));
|
||||
}
|
||||
|
||||
public void testParseEvalExpressionWithContextCustomELVariableResolver() {
|
||||
@@ -198,11 +198,10 @@ public class ELExpressionParserCompatibilityTests extends TestCase {
|
||||
}
|
||||
|
||||
private final class SpecialPropertyAccessor implements PropertyAccessor {
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue)
|
||||
throws AccessException {
|
||||
public void write(EvaluationContext context, Object target, String name, Object newValue) {
|
||||
}
|
||||
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public TypedValue read(EvaluationContext context, Object target, String name) {
|
||||
return new TypedValue("Custom resolver resolved this special property!",
|
||||
TypeDescriptor.valueOf(String.class));
|
||||
}
|
||||
@@ -211,11 +210,11 @@ public class ELExpressionParserCompatibilityTests extends TestCase {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canWrite(EvaluationContext context, Object target, String name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
|
||||
public boolean canRead(EvaluationContext context, Object target, String name) {
|
||||
return "specialProperty".equals(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,13 +34,11 @@ public class DefaultMapperTests extends TestCase {
|
||||
assertEquals(0, results.getErrorResults().size());
|
||||
assertEquals("a", bean2.bar);
|
||||
assertEquals("a", bean2.baz);
|
||||
assertEquals(1, results.getResults(new MappingResultsCriteria() {
|
||||
public boolean test(MappingResult result) {
|
||||
if (result.getMapping().getTargetExpression().getExpressionString().equals("baz")) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
assertEquals(1, results.getResults(result -> {
|
||||
if (result.getMapping().getTargetExpression().getExpressionString().equals("baz")) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}).size());
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class MessageBuilderTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testBuildCodes() {
|
||||
MessageResolver resolver = builder.error().codes(new String[] { "foo" }).build();
|
||||
MessageResolver resolver = builder.error().codes("foo").build();
|
||||
Message message = resolver.resolveMessage(messageSource, locale);
|
||||
assertEquals("bar", message.getText());
|
||||
assertEquals(Severity.ERROR, message.getSeverity());
|
||||
@@ -85,7 +85,7 @@ public class MessageBuilderTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testBuildArgs() {
|
||||
MessageResolver resolver = builder.error().codes(new String[] { "bar" }).args(new Object[] { "baz" }).build();
|
||||
MessageResolver resolver = builder.error().codes("bar").args("baz").build();
|
||||
Message message = resolver.resolveMessage(messageSource, locale);
|
||||
assertEquals("baz", message.getText());
|
||||
assertEquals(Severity.ERROR, message.getSeverity());
|
||||
@@ -113,7 +113,7 @@ public class MessageBuilderTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testBuildArgsWithNullCodes() {
|
||||
MessageResolver resolver = builder.error().args(new Object[] { "baz" }).build();
|
||||
MessageResolver resolver = builder.error().args("baz").build();
|
||||
try {
|
||||
resolver.resolveMessage(messageSource, locale);
|
||||
fail("Should have failed");
|
||||
@@ -122,7 +122,7 @@ public class MessageBuilderTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testBuildArgsWithNullCodesDefaultText() {
|
||||
MessageResolver resolver = builder.error().args(new Object[] { "baz" }).defaultText("foo").build();
|
||||
MessageResolver resolver = builder.error().args("baz").defaultText("foo").build();
|
||||
Message message = resolver.resolveMessage(messageSource, locale);
|
||||
assertEquals("foo", message.getText());
|
||||
}
|
||||
@@ -144,7 +144,7 @@ public class MessageBuilderTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testBuildResolvableArgs() {
|
||||
MessageResolver resolver = builder.error().codes(new String[] { "bar" }).resolvableArgs(new Object[] { "baz" })
|
||||
MessageResolver resolver = builder.error().codes("bar").resolvableArgs("baz")
|
||||
.build();
|
||||
Message message = resolver.resolveMessage(messageSource, locale);
|
||||
assertEquals("boop", message.getText());
|
||||
|
||||
@@ -3,8 +3,8 @@ package org.springframework.binding.message;
|
||||
import java.util.Locale;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
|
||||
import org.springframework.context.support.StaticMessageSource;
|
||||
import org.springframework.validation.MessageCodesResolver;
|
||||
|
||||
@@ -19,7 +19,7 @@ public class MessageContextErrorsMessageCodesTests extends TestCase {
|
||||
private MessageCodesResolver resolver;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
protected void setUp() {
|
||||
StaticMessageSource messageSource = new StaticMessageSource();
|
||||
messageSource.addMessage(errorCode, Locale.getDefault(), "doesntmatter");
|
||||
context = new DefaultMessageContext(messageSource);
|
||||
@@ -27,7 +27,7 @@ public class MessageContextErrorsMessageCodesTests extends TestCase {
|
||||
resolver = EasyMock.createMock(MessageCodesResolver.class);
|
||||
}
|
||||
|
||||
public void testRejectUsesObjectName() throws Exception {
|
||||
public void testRejectUsesObjectName() {
|
||||
EasyMock.expect(resolver.resolveMessageCodes(errorCode, objectName)).andReturn(new String[] {});
|
||||
EasyMock.replay(resolver);
|
||||
|
||||
@@ -38,7 +38,7 @@ public class MessageContextErrorsMessageCodesTests extends TestCase {
|
||||
EasyMock.verify(resolver);
|
||||
}
|
||||
|
||||
public void testRejectValueUsesObjectName() throws Exception {
|
||||
public void testRejectValueUsesObjectName() {
|
||||
EasyMock.expect(resolver.resolveMessageCodes(errorCode, objectName, "field", null)).andReturn(new String[] {});
|
||||
EasyMock.replay(resolver);
|
||||
|
||||
@@ -48,7 +48,7 @@ public class MessageContextErrorsMessageCodesTests extends TestCase {
|
||||
EasyMock.verify(resolver);
|
||||
}
|
||||
|
||||
public void testRejectValueEmptyField() throws Exception {
|
||||
public void testRejectValueEmptyField() {
|
||||
EasyMock.expect(resolver.resolveMessageCodes(errorCode, objectName)).andReturn(new String[] {});
|
||||
EasyMock.replay(resolver);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public class MessageContextErrorsTests extends TestCase {
|
||||
private MessageContextErrors errors;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
protected void setUp() {
|
||||
StaticMessageSource messageSource = new StaticMessageSource();
|
||||
messageSource.addMessage("foo", Locale.getDefault(), "bar");
|
||||
messageSource.addMessage("bar", Locale.getDefault(), "{0}");
|
||||
|
||||
@@ -29,7 +29,7 @@ public class MethodInvokerTests extends TestCase {
|
||||
|
||||
private MethodInvoker methodInvoker;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
protected void setUp() {
|
||||
this.methodInvoker = new MethodInvoker();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,34 +32,34 @@ public class MethodKeyTests extends TestCase {
|
||||
private static final Method LIST_FILENAME_FILTER = safeGetMethod(File.class, "list",
|
||||
new Class[] { FilenameFilter.class });
|
||||
|
||||
public void testGetMethodWithNoArgs() throws Exception {
|
||||
MethodKey key = new MethodKey(File.class, "list", new Class[0]);
|
||||
public void testGetMethodWithNoArgs() {
|
||||
MethodKey key = new MethodKey(File.class, "list");
|
||||
Method m = key.getMethod();
|
||||
assertEquals(LIST_NO_ARGS, m);
|
||||
}
|
||||
|
||||
public void testGetMoreGenericMethod() throws Exception {
|
||||
MethodKey key = new MethodKey(Object.class, "equals", new Class[] { Long.class });
|
||||
public void testGetMoreGenericMethod() {
|
||||
MethodKey key = new MethodKey(Object.class, "equals", Long.class);
|
||||
assertEquals(safeGetMethod(Object.class, "equals", new Class[] { Object.class }), key.getMethod());
|
||||
}
|
||||
|
||||
public void testGetMethodWithSingleArg() throws Exception {
|
||||
MethodKey key = new MethodKey(File.class, "list", new Class[] { FilenameFilter.class });
|
||||
public void testGetMethodWithSingleArg() {
|
||||
MethodKey key = new MethodKey(File.class, "list", FilenameFilter.class);
|
||||
Method m = key.getMethod();
|
||||
assertEquals(LIST_FILENAME_FILTER, m);
|
||||
}
|
||||
|
||||
public void testGetMethodWithSingleNullArgAndValidMatch() throws Exception {
|
||||
public void testGetMethodWithSingleNullArgAndValidMatch() {
|
||||
MethodKey key = new MethodKey(File.class, "list", new Class[] { null });
|
||||
Method m = key.getMethod();
|
||||
assertEquals(LIST_FILENAME_FILTER, m);
|
||||
}
|
||||
|
||||
public void testGetMethodWithSingleNullAndUnclearMatch() throws Exception {
|
||||
public void testGetMethodWithSingleNullAndUnclearMatch() {
|
||||
new MethodKey(File.class, "listFiles", new Class[] { null });
|
||||
}
|
||||
|
||||
private static final Method safeGetMethod(Class<?> type, String name, Class<?>[] argTypes) {
|
||||
private static Method safeGetMethod(Class<?> type, String name, Class<?>[] argTypes) {
|
||||
try {
|
||||
return type.getMethod(name, argTypes);
|
||||
} catch (NoSuchMethodException e) {
|
||||
|
||||
Reference in New Issue
Block a user