Polishing

This commit is contained in:
Juergen Hoeller 2014-01-16 16:54:49 +01:00
parent fd13c994c9
commit 16bf501b30
7 changed files with 463 additions and 520 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2013 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.
@ -17,30 +17,32 @@
package org.springframework.expression; package org.springframework.expression;
/** /**
* Instances of a type comparator should be able to compare pairs of objects for equality, the specification of the * Instances of a type comparator should be able to compare pairs of objects for equality.
* return value is the same as for {@link Comparable}. * The specification of the return value is the same as for {@link java.lang.Comparable}.
* *
* @author Andy Clement * @author Andy Clement
* @since 3.0 * @since 3.0
* @see java.lang.Comparable
*/ */
public interface TypeComparator { public interface TypeComparator {
/** /**
* Compare two objects. * Return {@code true} if the comparator can compare these two objects.
* @param firstObject the first object * @param firstObject the first object
* @param secondObject the second object * @param secondObject the second object
* @return 0 if they are equal, <0 if the first is smaller than the second, or >0 if the first is larger than the * @return {@code true} if the comparator can compare these objects
* second
* @throws EvaluationException if a problem occurs during comparison (or they are not comparable)
*/
int compare(Object firstObject, Object secondObject) throws EvaluationException;
/**
* Return true if the comparator can compare these two objects
* @param firstObject the first object
* @param secondObject the second object
* @return true if the comparator can compare these objects
*/ */
boolean canCompare(Object firstObject, Object secondObject); boolean canCompare(Object firstObject, Object secondObject);
/**
* Compare two given objects.
* @param firstObject the first object
* @param secondObject the second object
* @return 0 if they are equal, <0 if the first is smaller than the second,
* or >0 if the first is larger than the second
* @throws EvaluationException if a problem occurs during comparison
* (or if they are not comparable in the first place)
*/
int compare(Object firstObject, Object secondObject) throws EvaluationException;
} }

View File

@ -35,22 +35,23 @@ public interface TypeConverter {
* to the desired target type. * to the desired target type.
* @param sourceType a type descriptor that describes the source type * @param sourceType a type descriptor that describes the source type
* @param targetType a type descriptor that describes the requested result type * @param targetType a type descriptor that describes the requested result type
* @return true if that conversion can be performed * @return {@code true} if that conversion can be performed
*/ */
boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType); boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType);
/** /**
* Convert (may coerce) a value from one type to another, for example from a boolean * Convert (or coerce) a value from one type to another, for example from a
* to a string. The typeDescriptor parameter enables support for typed collections - * {@code boolean} to a {@code String}.
* if the caller really wishes they can have a List&lt;Integer&gt; for example, rather * <p>The {@link TypeDescriptor} parameters enable support for typed collections:
* than simply a List. * A caller may prefer a {@code List&lt;Integer&gt;}, for example, rather than
* simply any {@code List}.
* @param value the value to be converted * @param value the value to be converted
* @param sourceType a type descriptor that supplies extra information about the * @param sourceType a type descriptor that supplies extra information about the
* source object * source object
* @param targetType a type descriptor that supplies extra information about the * @param targetType a type descriptor that supplies extra information about the
* requested result type * requested result type
* @return the converted value * @return the converted value
* @throws EvaluationException if conversion is not possible * @throws EvaluationException if conversion failed or is not possible to begin with
*/ */
Object convertValue(Object value, TypeDescriptor sourceType, TypeDescriptor targetType); Object convertValue(Object value, TypeDescriptor sourceType, TypeDescriptor targetType);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2009 the original author or authors. * Copyright 2002-2013 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.
@ -17,9 +17,12 @@
package org.springframework.expression; package org.springframework.expression;
/** /**
* Implementors of this interface are expected to be able to locate types. They may use custom classloaders * Implementers of this interface are expected to be able to locate types.
* or the and deal with common package prefixes (java.lang, etc) however they wish. See * They may use a custom {@link ClassLoader} and/or deal with common
* {@link org.springframework.expression.spel.support.StandardTypeLocator} for an example implementation. * package prefixes (e.g. {@code java.lang}) however they wish.
*
* <p>See {@link org.springframework.expression.spel.support.StandardTypeLocator}
* for an example implementation.
* *
* @author Andy Clement * @author Andy Clement
* @since 3.0 * @since 3.0
@ -27,11 +30,12 @@ package org.springframework.expression;
public interface TypeLocator { public interface TypeLocator {
/** /**
* Find a type by name. The name may or may not be fully qualified (eg. String or java.lang.String) * Find a type by name. The name may or may not be fully qualified
* @param typename the type to be located * (e.g. {@code String} or {@code java.lang.String}).
* @return the class object representing that type * @param typeName the type to be located
* @throws EvaluationException if there is a problem finding it * @return the {@code Class} object representing that type
* @throws EvaluationException if there is a problem finding the type
*/ */
Class<?> findType(String typename) throws EvaluationException; Class<?> findType(String typeName) throws EvaluationException;
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2013 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.
@ -21,7 +21,8 @@ import org.springframework.expression.spel.SpelEvaluationException;
import org.springframework.expression.spel.SpelMessage; import org.springframework.expression.spel.SpelMessage;
/** /**
* A simple basic TypeComparator implementation. It supports comparison of numbers and types implementing Comparable. * A simple basic {@link TypeComparator} implementation.
* It supports comparison of Numbers and types implementing Comparable.
* *
* @author Andy Clement * @author Andy Clement
* @author Juergen Hoeller * @author Juergen Hoeller
@ -29,49 +30,6 @@ import org.springframework.expression.spel.SpelMessage;
*/ */
public class StandardTypeComparator implements TypeComparator { public class StandardTypeComparator implements TypeComparator {
@SuppressWarnings("unchecked")
public int compare(Object left, Object right) throws SpelEvaluationException {
// If one is null, check if the other is
if (left == null) {
return right == null ? 0 : -1;
} else if (right == null) {
return 1; // left cannot be null
}
// Basic number comparisons
if (left instanceof Number && right instanceof Number) {
Number leftNumber = (Number) left;
Number rightNumber = (Number) right;
if (leftNumber instanceof Double || rightNumber instanceof Double) {
double d1 = leftNumber.doubleValue();
double d2 = rightNumber.doubleValue();
return Double.compare(d1,d2);
} else if (leftNumber instanceof Float || rightNumber instanceof Float) {
float f1 = leftNumber.floatValue();
float f2 = rightNumber.floatValue();
return Float.compare(f1,f2);
} else if (leftNumber instanceof Long || rightNumber instanceof Long) {
Long l1 = leftNumber.longValue();
Long l2 = rightNumber.longValue();
return l1.compareTo(l2);
} else {
Integer i1 = leftNumber.intValue();
Integer i2 = rightNumber.intValue();
return i1.compareTo(i2);
}
}
try {
if (left instanceof Comparable) {
return ((Comparable) left).compareTo(right);
}
} catch (ClassCastException cce) {
throw new SpelEvaluationException(cce, SpelMessage.NOT_COMPARABLE, left.getClass(), right.getClass());
}
throw new SpelEvaluationException(SpelMessage.NOT_COMPARABLE, left.getClass(), right.getClass());
}
public boolean canCompare(Object left, Object right) { public boolean canCompare(Object left, Object right) {
if (left == null || right == null) { if (left == null || right == null) {
return true; return true;
@ -85,4 +43,56 @@ public class StandardTypeComparator implements TypeComparator {
return false; return false;
} }
@SuppressWarnings("unchecked")
public int compare(Object left, Object right) throws SpelEvaluationException {
// If one is null, check if the other is
if (left == null) {
return (right == null ? 0 : -1);
}
else if (right == null) {
return 1; // left cannot be null at this point
}
// Basic number comparisons
if (left instanceof Number && right instanceof Number) {
Number leftNumber = (Number) left;
Number rightNumber = (Number) right;
if (leftNumber instanceof Double || rightNumber instanceof Double) {
return Double.compare(leftNumber.doubleValue(), rightNumber.doubleValue());
}
else if (leftNumber instanceof Float || rightNumber instanceof Float) {
return Float.compare(leftNumber.floatValue(), rightNumber.floatValue());
}
else if (leftNumber instanceof Long || rightNumber instanceof Long) {
// Don't call Long.compare here - only available on JDK 1.7+
return compare(leftNumber.longValue(), rightNumber.longValue());
}
else {
// Don't call Integer.compare here - only available on JDK 1.7+
return compare(leftNumber.intValue(), rightNumber.intValue());
}
}
try {
if (left instanceof Comparable) {
return ((Comparable) left).compareTo(right);
}
}
catch (ClassCastException ex) {
throw new SpelEvaluationException(ex, SpelMessage.NOT_COMPARABLE, left.getClass(), right.getClass());
}
throw new SpelEvaluationException(SpelMessage.NOT_COMPARABLE, left.getClass(), right.getClass());
}
private static int compare(int x, int y) {
return (x < y ? -1 : (x > y ? 1 : 0));
}
private static int compare(long x, long y) {
return (x < y ? -1 : (x > y ? 1 : 0));
}
} }

View File

@ -18,7 +18,6 @@ package org.springframework.expression.spel.support;
import org.springframework.core.convert.ConversionException; import org.springframework.core.convert.ConversionException;
import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.expression.TypeConverter; import org.springframework.expression.TypeConverter;
@ -27,8 +26,8 @@ import org.springframework.expression.spel.SpelMessage;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
* Default implementation of the {@link TypeConverter} interface, delegating to a core * Default implementation of the {@link TypeConverter} interface,
* Spring {@link ConversionService}. * delegating to a core Spring {@link ConversionService}.
* *
* @author Juergen Hoeller * @author Juergen Hoeller
* @author Andy Clement * @author Andy Clement
@ -42,6 +41,9 @@ public class StandardTypeConverter implements TypeConverter {
private final ConversionService conversionService; private final ConversionService conversionService;
/**
* Create a StandardTypeConverter for the default ConversionService.
*/
public StandardTypeConverter() { public StandardTypeConverter() {
synchronized (this) { synchronized (this) {
if (defaultConversionService == null) { if (defaultConversionService == null) {
@ -51,6 +53,10 @@ public class StandardTypeConverter implements TypeConverter {
this.conversionService = defaultConversionService; this.conversionService = defaultConversionService;
} }
/**
* Create a StandardTypeConverter for the given ConversionService.
* @param conversionService the ConversionService to delegate to
*/
public StandardTypeConverter(ConversionService conversionService) { public StandardTypeConverter(ConversionService conversionService) {
Assert.notNull(conversionService, "ConversionService must not be null"); Assert.notNull(conversionService, "ConversionService must not be null");
this.conversionService = conversionService; this.conversionService = conversionService;
@ -65,10 +71,6 @@ public class StandardTypeConverter implements TypeConverter {
try { try {
return this.conversionService.convert(value, sourceType, targetType); return this.conversionService.convert(value, sourceType, targetType);
} }
catch (ConverterNotFoundException ex) {
throw new SpelEvaluationException(
ex, SpelMessage.TYPE_CONVERSION_ERROR, sourceType.toString(), targetType.toString());
}
catch (ConversionException ex) { catch (ConversionException ex) {
throw new SpelEvaluationException( throw new SpelEvaluationException(
ex, SpelMessage.TYPE_CONVERSION_ERROR, sourceType.toString(), targetType.toString()); ex, SpelMessage.TYPE_CONVERSION_ERROR, sourceType.toString(), targetType.toString());

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2013 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,8 +16,8 @@
package org.springframework.expression.spel.support; package org.springframework.expression.spel.support;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.springframework.expression.EvaluationException; import org.springframework.expression.EvaluationException;
@ -27,8 +27,9 @@ import org.springframework.expression.spel.SpelMessage;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
/** /**
* A default implementation of a TypeLocator that uses the context classloader (or any classloader set upon it). It * A simple implementation of {@link TypeLocator} that uses the context ClassLoader
* supports 'well known' packages so if a type cannot be found it will try the registered imports to locate it. * (or any ClassLoader set upon it). It supports 'well-known' packages: So if a
* type cannot be found, it will try the registered imports to locate it.
* *
* @author Andy Clement * @author Andy Clement
* @author Juergen Hoeller * @author Juergen Hoeller
@ -36,49 +37,30 @@ import org.springframework.util.ClassUtils;
*/ */
public class StandardTypeLocator implements TypeLocator { public class StandardTypeLocator implements TypeLocator {
private ClassLoader loader; private final ClassLoader classLoader;
private final List<String> knownPackagePrefixes = new ArrayList<String>(); private final List<String> knownPackagePrefixes = new LinkedList<String>();
/**
* Create a StandardTypeLocator for the default ClassLoader
* (typically, the thread context ClassLoader).
*/
public StandardTypeLocator() { public StandardTypeLocator() {
this(ClassUtils.getDefaultClassLoader()); this(ClassUtils.getDefaultClassLoader());
} }
public StandardTypeLocator(ClassLoader loader) { /**
this.loader = loader; * Create a StandardTypeLocator for the given ClassLoader.
// Similar to when writing Java, it only knows about java.lang by default * @param classLoader the ClassLoader to delegate to
*/
public StandardTypeLocator(ClassLoader classLoader) {
this.classLoader = classLoader;
// Similar to when writing regular Java code, it only knows about java.lang by default
registerImport("java.lang"); registerImport("java.lang");
} }
/**
* Find a (possibly unqualified) type reference - first using the typename as is, then trying any registered
* prefixes if the typename cannot be found.
* @param typename the type to locate
* @return the class object for the type
* @throws EvaluationException if the type cannot be found
*/
public Class<?> findType(String typename) throws EvaluationException {
String nameToLookup = typename;
try {
return this.loader.loadClass(nameToLookup);
}
catch (ClassNotFoundException ey) {
// try any registered prefixes before giving up
}
for (String prefix : this.knownPackagePrefixes) {
try {
nameToLookup = new StringBuilder().append(prefix).append(".").append(typename).toString();
return this.loader.loadClass(nameToLookup);
}
catch (ClassNotFoundException ex) {
// might be a different prefix
}
}
throw new SpelEvaluationException(SpelMessage.TYPE_NOT_FOUND, typename);
}
/** /**
* Register a new import prefix that will be used when searching for unqualified types. * Register a new import prefix that will be used when searching for unqualified types.
* Expected format is something like "java.lang". * Expected format is something like "java.lang".
@ -88,16 +70,48 @@ public class StandardTypeLocator implements TypeLocator {
this.knownPackagePrefixes.add(prefix); this.knownPackagePrefixes.add(prefix);
} }
/**
* Remove that specified prefix from this locator's list of imports.
* @param prefix the prefix to remove
*/
public void removeImport(String prefix) {
this.knownPackagePrefixes.remove(prefix);
}
/** /**
* Return a list of all the import prefixes registered with this StandardTypeLocator. * Return a list of all the import prefixes registered with this StandardTypeLocator.
* @return list of registered import prefixes * @return a list of registered import prefixes
*/ */
public List<String> getImportPrefixes() { public List<String> getImportPrefixes() {
return Collections.unmodifiableList(this.knownPackagePrefixes); return Collections.unmodifiableList(this.knownPackagePrefixes);
} }
public void removeImport(String prefix) {
this.knownPackagePrefixes.remove(prefix); /**
* Find a (possibly unqualified) type reference - first using the type name as-is,
* then trying any registered prefixes if the type name cannot be found.
* @param typeName the type to locate
* @return the class object for the type
* @throws EvaluationException if the type cannot be found
*/
public Class<?> findType(String typeName) throws EvaluationException {
String nameToLookup = typeName;
try {
return this.classLoader.loadClass(nameToLookup);
}
catch (ClassNotFoundException ey) {
// try any registered prefixes before giving up
}
for (String prefix : this.knownPackagePrefixes) {
try {
nameToLookup = prefix + "." + typeName;
return this.classLoader.loadClass(nameToLookup);
}
catch (ClassNotFoundException ex) {
// might be a different prefix
}
}
throw new SpelEvaluationException(SpelMessage.TYPE_NOT_FOUND, typeName);
} }
} }

View File

@ -27,7 +27,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.junit.Ignore;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
@ -75,9 +74,8 @@ public class SpelReproTests extends ExpressionTestCase {
} }
@Test @Test
@Ignore
public void testSWF1086() { public void testSWF1086() {
evaluate("printDouble(T(java.math.BigDecimal).valueOf(14.35))", "anullc", String.class); evaluate("printDouble(T(java.math.BigDecimal).valueOf(14.35))", "14.35", String.class);
} }
@Test @Test
@ -101,7 +99,8 @@ public class SpelReproTests extends ExpressionTestCase {
expr = new SpelExpressionParser().parseRaw("tryToInvokeWithNull2(null)"); expr = new SpelExpressionParser().parseRaw("tryToInvokeWithNull2(null)");
expr.getValue(); expr.getValue();
fail("Should have failed to find a method to which it could pass null"); fail("Should have failed to find a method to which it could pass null");
} catch (EvaluationException see) { }
catch (EvaluationException see) {
// success // success
} }
eContext.setTypeLocator(new MyTypeLocator()); eContext.setTypeLocator(new MyTypeLocator());
@ -133,31 +132,44 @@ public class SpelReproTests extends ExpressionTestCase {
static class MyTypeLocator extends StandardTypeLocator { static class MyTypeLocator extends StandardTypeLocator {
@Override @Override
public Class<?> findType(String typename) throws EvaluationException { public Class<?> findType(String typeName) throws EvaluationException {
if (typename.equals("Spr5899Class")) { if (typeName.equals("Spr5899Class")) {
return Spr5899Class.class; return Spr5899Class.class;
} }
if (typename.equals("Outer")) { if (typeName.equals("Outer")) {
return Outer.class; return Outer.class;
} }
return super.findType(typename); return super.findType(typeName);
} }
} }
static class Spr5899Class { static class Spr5899Class {
public Spr5899Class() {}
public Spr5899Class(Integer i) { }
public Spr5899Class(Integer i, String... s) { }
public Integer tryToInvokeWithNull(Integer value) { return value; } public Spr5899Class() {
public Integer tryToInvokeWithNull2(int i) { return new Integer(i); } }
public Spr5899Class(Integer i) {
}
public Spr5899Class(Integer i, String... s) {
}
public Integer tryToInvokeWithNull(Integer value) {
return value;
}
public Integer tryToInvokeWithNull2(int i) {
return new Integer(i);
}
public String tryToInvokeWithNull3(Integer value, String... strings) { public String tryToInvokeWithNull3(Integer value, String... strings) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (int i=0;i<strings.length;i++) { for (String string : strings) {
if (strings[i]==null) { if (string == null) {
sb.append("null"); sb.append("null");
} else { }
sb.append(strings[i]); else {
sb.append(string);
} }
} }
return sb.toString(); return sb.toString();
@ -182,11 +194,15 @@ public class SpelReproTests extends ExpressionTestCase {
} }
static class Outer { static class Outer {
static class Inner { static class Inner {
public Inner() {} public Inner() {}
public static int run() { public static int run() {
return 12; return 12;
} }
public int run2() { public int run2() {
return 13; return 13;
} }
@ -276,7 +292,6 @@ public class SpelReproTests extends ExpressionTestCase {
public Class<?>[] getSpecificTargetClasses() { public Class<?>[] getSpecificTargetClasses() {
return new Class[] {Map.class}; return new Class[] {Map.class};
} }
} }
@Test @Test
@ -323,13 +338,15 @@ public class SpelReproTests extends ExpressionTestCase {
try { try {
propertyAccessor.read(context, null, "abc"); propertyAccessor.read(context, null, "abc");
fail("Should have failed with an AccessException"); fail("Should have failed with an AccessException");
} catch (AccessException ae) { }
catch (AccessException ae) {
// success // success
} }
try { try {
propertyAccessor.write(context, null, "abc","foo"); propertyAccessor.write(context, null, "abc","foo");
fail("Should have failed with an AccessException"); fail("Should have failed with an AccessException");
} catch (AccessException ae) { }
catch (AccessException ae) {
// success // success
} }
} }
@ -347,20 +364,25 @@ public class SpelReproTests extends ExpressionTestCase {
} }
static class Foo { static class Foo {
public ResourceSummary resource = new ResourceSummary(); public ResourceSummary resource = new ResourceSummary();
} }
static class ResourceSummary { static class ResourceSummary {
private final Resource resource;
ResourceSummary() { ResourceSummary() {
this.resource = new Resource(); this.resource = new Resource();
} }
private final Resource resource;
public Resource getResource() { public Resource getResource() {
return resource; return resource;
} }
} }
static class Resource { static class Resource {
public String getServer() { public String getServer() {
return "abc"; return "abc";
} }
@ -498,6 +520,7 @@ public class SpelReproTests extends ExpressionTestCase {
} }
static class XX { static class XX {
public Map<String,String> m; public Map<String,String> m;
public String floo ="bar"; public String floo ="bar";
@ -512,7 +535,9 @@ public class SpelReproTests extends ExpressionTestCase {
static class Goo { static class Goo {
public static Goo instance = new Goo(); public static Goo instance = new Goo();
public String bar = "key"; public String bar = "key";
public String value = null; public String value = null;
public String wibble = "wobble"; public String wibble = "wobble";
@ -524,7 +549,6 @@ public class SpelReproTests extends ExpressionTestCase {
public void setKey(String s) { public void setKey(String s) {
value = s; value = s;
} }
} }
static class Holder { static class Holder {
@ -553,23 +577,27 @@ public class SpelReproTests extends ExpressionTestCase {
try { try {
parser.parseExpression(expression,context); parser.parseExpression(expression,context);
fail("Should have failed"); fail("Should have failed");
} catch (Exception e) {
if (!e.getMessage().equals(expectedMessage)) {
e.printStackTrace();
} }
assertEquals(expectedMessage,e.getMessage()); catch (Exception ex) {
if (!ex.getMessage().equals(expectedMessage)) {
ex.printStackTrace();
}
assertEquals(expectedMessage, ex.getMessage());
} }
} }
private static final ParserContext DOLLARSQUARE_TEMPLATE_PARSER_CONTEXT = new ParserContext() { private static final ParserContext DOLLARSQUARE_TEMPLATE_PARSER_CONTEXT = new ParserContext() {
@Override @Override
public String getExpressionPrefix() { public String getExpressionPrefix() {
return "$["; return "$[";
} }
@Override @Override
public String getExpressionSuffix() { public String getExpressionSuffix() {
return "]"; return "]";
} }
@Override @Override
public boolean isTemplate() { public boolean isTemplate() {
return true; return true;
@ -577,12 +605,14 @@ public class SpelReproTests extends ExpressionTestCase {
}; };
static class Foo2 { static class Foo2 {
public void execute(String str){ public void execute(String str){
System.out.println("Value: " + str); System.out.println("Value: " + str);
} }
} }
static class Message{ static class Message{
private String payload; private String payload;
public String getPayload() { public String getPayload() {
@ -605,7 +635,8 @@ public class SpelReproTests extends ExpressionTestCase {
try { try {
expr = new SpelExpressionParser().parseRaw("@foo"); expr = new SpelExpressionParser().parseRaw("@foo");
assertEquals("custard",expr.getValue(eContext,String.class)); assertEquals("custard",expr.getValue(eContext,String.class));
} catch (SpelEvaluationException see) { }
catch (SpelEvaluationException see) {
assertEquals(SpelMessage.NO_BEAN_RESOLVER_REGISTERED,see.getMessageCode()); assertEquals(SpelMessage.NO_BEAN_RESOLVER_REGISTERED,see.getMessageCode());
assertEquals("foo",see.getInserts()[0]); assertEquals("foo",see.getInserts()[0]);
} }
@ -624,7 +655,8 @@ public class SpelReproTests extends ExpressionTestCase {
expr = new SpelExpressionParser().parseRaw("@goo"); expr = new SpelExpressionParser().parseRaw("@goo");
try { try {
assertEquals(null,expr.getValue(eContext,String.class)); assertEquals(null,expr.getValue(eContext,String.class));
} catch (SpelEvaluationException see) { }
catch (SpelEvaluationException see) {
assertEquals(SpelMessage.EXCEPTION_DURING_BEAN_RESOLUTION,see.getMessageCode()); assertEquals(SpelMessage.EXCEPTION_DURING_BEAN_RESOLUTION,see.getMessageCode());
assertEquals("goo",see.getInserts()[0]); assertEquals("goo",see.getInserts()[0]);
assertTrue(see.getCause() instanceof AccessException); assertTrue(see.getCause() instanceof AccessException);
@ -639,19 +671,23 @@ public class SpelReproTests extends ExpressionTestCase {
try { try {
expr = new SpelExpressionParser().parseRaw("@378"); expr = new SpelExpressionParser().parseRaw("@378");
assertEquals("trouble",expr.getValue(eContext,String.class)); assertEquals("trouble",expr.getValue(eContext,String.class));
} catch (SpelParseException spe) { }
catch (SpelParseException spe) {
assertEquals(SpelMessage.INVALID_BEAN_REFERENCE,spe.getMessageCode()); assertEquals(SpelMessage.INVALID_BEAN_REFERENCE,spe.getMessageCode());
} }
} }
static class MyBeanResolver implements BeanResolver { static class MyBeanResolver implements BeanResolver {
@Override @Override
public Object resolve(EvaluationContext context, String beanname) throws AccessException { public Object resolve(EvaluationContext context, String beanName) throws AccessException {
if (beanname.equals("foo")) { if (beanName.equals("foo")) {
return "custard"; return "custard";
} else if (beanname.equals("foo.bar")) { }
else if (beanName.equals("foo.bar")) {
return "trouble"; return "trouble";
} else if (beanname.equals("goo")) { }
else if (beanName.equals("goo")) {
throw new AccessException("DONT ASK ME ABOUT GOO"); throw new AccessException("DONT ASK ME ABOUT GOO");
} }
return null; return null;
@ -678,7 +714,8 @@ public class SpelReproTests extends ExpressionTestCase {
expr = new SpelExpressionParser().parseRaw("(?'abc':'default')"); expr = new SpelExpressionParser().parseRaw("(?'abc':'default')");
expr.getValue(eContext); expr.getValue(eContext);
fail(); fail();
} catch (SpelEvaluationException see ) { }
catch (SpelEvaluationException see ) {
assertEquals(SpelMessage.TYPE_CONVERSION_ERROR,see.getMessageCode()); assertEquals(SpelMessage.TYPE_CONVERSION_ERROR,see.getMessageCode());
} }
expr = new SpelExpressionParser().parseRaw("(false?'abc':null)"); expr = new SpelExpressionParser().parseRaw("(false?'abc':null)");
@ -689,7 +726,8 @@ public class SpelReproTests extends ExpressionTestCase {
expr = new SpelExpressionParser().parseRaw("(='default')"); expr = new SpelExpressionParser().parseRaw("(='default')");
expr.getValue(eContext); expr.getValue(eContext);
fail(); fail();
} catch (SpelEvaluationException see ) { }
catch (SpelEvaluationException see ) {
assertEquals(SpelMessage.SETVALUE_NOT_SUPPORTED,see.getMessageCode()); assertEquals(SpelMessage.SETVALUE_NOT_SUPPORTED,see.getMessageCode());
} }
} }
@ -913,7 +951,6 @@ public class SpelReproTests extends ExpressionTestCase {
} }
@Test @Test
public void varargsAndPrimitives_SPR8174() throws Exception { public void varargsAndPrimitives_SPR8174() throws Exception {
EvaluationContext emptyEvalContext = new StandardEvaluationContext(); EvaluationContext emptyEvalContext = new StandardEvaluationContext();
@ -960,12 +997,11 @@ public class SpelReproTests extends ExpressionTestCase {
args.add(TypeDescriptor.forObject(23f)); args.add(TypeDescriptor.forObject(23f));
me = new ReflectiveMethodResolver().resolve(emptyEvalContext,ru,"bar",args); me = new ReflectiveMethodResolver().resolve(emptyEvalContext,ru,"bar",args);
me.execute(emptyEvalContext, ru, 12,23f); me.execute(emptyEvalContext, ru, 12,23f);
} }
public class ReflectionUtil<T extends Number> { public class ReflectionUtil<T extends Number> {
public Object methodToCall(T param) { public Object methodToCall(T param) {
System.out.println(param+" "+param.getClass()); System.out.println(param+" "+param.getClass());
return "Object methodToCall(T param)"; return "Object methodToCall(T param)";
@ -1040,11 +1076,11 @@ public class SpelReproTests extends ExpressionTestCase {
m.put("NE","xyz"); m.put("NE","xyz");
} }
} }
StandardEvaluationContext ctx = new StandardEvaluationContext(new Reserver()); StandardEvaluationContext ctx = new StandardEvaluationContext(new Reserver());
SpelExpressionParser parser = new SpelExpressionParser(); SpelExpressionParser parser = new SpelExpressionParser();
String ex = "getReserver().NE"; String ex = "getReserver().NE";
SpelExpression exp = null; SpelExpression exp = parser.parseRaw(ex);
exp = parser.parseRaw(ex);
String value = (String) exp.getValue(ctx); String value = (String) exp.getValue(ctx);
assertEquals("abc", value); assertEquals("abc", value);
@ -1074,7 +1110,8 @@ public class SpelReproTests extends ExpressionTestCase {
public void testReservedWordProperties_9862() throws Exception { public void testReservedWordProperties_9862() throws Exception {
StandardEvaluationContext ctx = new StandardEvaluationContext(); StandardEvaluationContext ctx = new StandardEvaluationContext();
SpelExpressionParser parser = new SpelExpressionParser(); SpelExpressionParser parser = new SpelExpressionParser();
SpelExpression expression = parser.parseRaw("T(org.springframework.expression.spel.testresources.le.div.mod.reserved.Reserver).CONST"); SpelExpression expression = parser.parseRaw(
"T(org.springframework.expression.spel.testresources.le.div.mod.reserved.Reserver).CONST");
Object value = expression.getValue(ctx); Object value = expression.getValue(ctx);
assertEquals(value, Reserver.CONST); assertEquals(value, Reserver.CONST);
} }
@ -1107,47 +1144,53 @@ public class SpelReproTests extends ExpressionTestCase {
} }
class TestPropertyAccessor implements PropertyAccessor { class TestPropertyAccessor implements PropertyAccessor {
private String mapName; private String mapName;
public TestPropertyAccessor(String mapName) { public TestPropertyAccessor(String mapName) {
this.mapName = mapName; this.mapName = mapName;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Map<String, String> getMap(Object target) { public Map<String, String> getMap(Object target) {
try { try {
Field f = target.getClass().getDeclaredField(mapName); Field f = target.getClass().getDeclaredField(mapName);
return (Map<String,String>) f.get(target); return (Map<String,String>) f.get(target);
} catch (Exception e) { }
catch (Exception ex) {
} }
return null; return null;
} }
@Override @Override
public boolean canRead(EvaluationContext context, Object target, String name) public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
throws AccessException {
return getMap(target).containsKey(name); return getMap(target).containsKey(name);
} }
@Override @Override
public boolean canWrite(EvaluationContext context, Object target, String name) public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
throws AccessException {
return getMap(target).containsKey(name); return getMap(target).containsKey(name);
} }
@Override @Override
public Class<?>[] getSpecificTargetClasses() { public Class<?>[] getSpecificTargetClasses() {
return new Class[] {ContextObject.class}; return new Class[] {ContextObject.class};
} }
@Override @Override
public TypedValue read(EvaluationContext context, Object target, String name) public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
throws AccessException {
return new TypedValue(getMap(target).get(name)); return new TypedValue(getMap(target).get(name));
} }
@Override @Override
public void write(EvaluationContext context, Object target, String name, Object newValue) public void write(EvaluationContext context, Object target, String name, Object newValue)
throws AccessException { throws AccessException {
getMap(target).put(name, (String) newValue); getMap(target).put(name, (String) newValue);
} }
} }
class ContextObject { class ContextObject {
public Map<String, String> firstContext = new HashMap<String, String>(); public Map<String, String> firstContext = new HashMap<String, String>();
public Map<String, String> secondContext = new HashMap<String, String>(); public Map<String, String> secondContext = new HashMap<String, String>();
public Map<String, String> thirdContext = new HashMap<String, String>(); public Map<String, String> thirdContext = new HashMap<String, String>();
@ -1168,6 +1211,7 @@ public class SpelReproTests extends ExpressionTestCase {
fourthContext.put("shouldBeFourth", "fourth"); fourthContext.put("shouldBeFourth", "fourth");
} }
public Map<String, String> getFirstContext() {return firstContext;} public Map<String, String> getFirstContext() {return firstContext;}
public Map<String, String> getSecondContext() {return secondContext;} public Map<String, String> getSecondContext() {return secondContext;}
public Map<String, String> getThirdContext() {return thirdContext;} public Map<String, String> getThirdContext() {return thirdContext;}
@ -1180,7 +1224,6 @@ public class SpelReproTests extends ExpressionTestCase {
*/ */
@Test @Test
public void testCustomStaticFunctions_SPR9038() { public void testCustomStaticFunctions_SPR9038() {
try {
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
List<MethodResolver> methodResolvers = new ArrayList<MethodResolver>(); List<MethodResolver> methodResolvers = new ArrayList<MethodResolver>();
@ -1188,10 +1231,10 @@ public class SpelReproTests extends ExpressionTestCase {
@Override @Override
protected Method[] getMethods(Class<?> type) { protected Method[] getMethods(Class<?> type) {
try { try {
return new Method[] { return new Method[] {Integer.class.getDeclaredMethod("parseInt",
Integer.class.getDeclaredMethod("parseInt", new Class[] { new Class[] {String.class, Integer.TYPE })};
String.class, Integer.TYPE }) }; }
} catch (NoSuchMethodException e1) { catch (NoSuchMethodException ex) {
return new Method[0]; return new Method[0];
} }
} }
@ -1203,10 +1246,6 @@ public class SpelReproTests extends ExpressionTestCase {
Integer result = expression.getValue(context, "", Integer.class); Integer result = expression.getValue(context, "", Integer.class);
assertEquals("Equal assertion failed: ", -255, result.intValue()); assertEquals("Equal assertion failed: ", -255, result.intValue());
} catch (Exception e) {
e.printStackTrace();
fail("Unexpected exception: "+e.toString());
}
} }
@Test @Test
@ -1239,8 +1278,7 @@ public class SpelReproTests extends ExpressionTestCase {
} }
@Test @Test
public void SPR_9486_floatFunctionResolverTest() { public void SPR_9486_floatFunctionResolverTest() throws Exception {
try {
Number expectedResult = Math.abs(-10.2f); Number expectedResult = Math.abs(-10.2f);
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
SPR_9486_FunctionsClass testObject = new SPR_9486_FunctionsClass(); SPR_9486_FunctionsClass testObject = new SPR_9486_FunctionsClass();
@ -1249,13 +1287,10 @@ public class SpelReproTests extends ExpressionTestCase {
org.springframework.expression.Expression expression = parser.parseExpression("abs(-10.2f)"); org.springframework.expression.Expression expression = parser.parseExpression("abs(-10.2f)");
Number result = expression.getValue(context, testObject, Number.class); Number result = expression.getValue(context, testObject, Number.class);
assertEquals("Equal assertion failed for SPR_9486_floatFunctionResolverTest Test: ", expectedResult, result); assertEquals("Equal assertion failed for SPR_9486_floatFunctionResolverTest Test: ", expectedResult, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_floatFunctionResolverTest");
}
} }
class SPR_9486_FunctionsClass { class SPR_9486_FunctionsClass {
public int abs(int value) { public int abs(int value) {
return Math.abs(value); return Math.abs(value);
} }
@ -1267,394 +1302,264 @@ public class SpelReproTests extends ExpressionTestCase {
@Test @Test
public void SPR_9486_addFloatWithDoubleTest() { public void SPR_9486_addFloatWithDoubleTest() {
try {
Number expectedNumber = 10.21f + 10.2; Number expectedNumber = 10.21f + 10.2;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("10.21f + 10.2"); org.springframework.expression.Expression expression = parser.parseExpression("10.21f + 10.2");
Number result = expression.getValue(context, null, Number.class); Number result = expression.getValue(context, null, Number.class);
assertEquals("Equal assertion failed for SPR_9486_addFloatWithDoubleTest Test: ", expectedNumber, result); assertEquals("Equal assertion failed for SPR_9486_addFloatWithDoubleTest Test: ", expectedNumber, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_addFloatWithDoubleTest");
}
} }
@Test @Test
public void SPR_9486_addFloatWithFloatTest() { public void SPR_9486_addFloatWithFloatTest() {
try {
Number expectedNumber = 10.21f + 10.2f; Number expectedNumber = 10.21f + 10.2f;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("10.21f + 10.2f"); org.springframework.expression.Expression expression = parser.parseExpression("10.21f + 10.2f");
Number result = expression.getValue(context, null, Number.class); Number result = expression.getValue(context, null, Number.class);
assertEquals("Equal assertion failed for SPR_9486_addFloatWithFloatTest Test: ", expectedNumber, result); assertEquals("Equal assertion failed for SPR_9486_addFloatWithFloatTest Test: ", expectedNumber, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_addFloatWithFloatTest");
}
} }
@Test @Test
public void SPR_9486_subtractFloatWithDoubleTest() { public void SPR_9486_subtractFloatWithDoubleTest() {
try {
Number expectedNumber = 10.21f - 10.2; Number expectedNumber = 10.21f - 10.2;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("10.21f - 10.2"); org.springframework.expression.Expression expression = parser.parseExpression("10.21f - 10.2");
Number result = expression.getValue(context, null, Number.class); Number result = expression.getValue(context, null, Number.class);
assertEquals("Equal assertion failed for SPR_9486_subtractFloatWithDoubleTest Test: ", expectedNumber, result); assertEquals("Equal assertion failed for SPR_9486_subtractFloatWithDoubleTest Test: ", expectedNumber, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_subtractFloatWithDoubleTest");
}
} }
@Test @Test
public void SPR_9486_subtractFloatWithFloatTest() { public void SPR_9486_subtractFloatWithFloatTest() {
try {
Number expectedNumber = 10.21f - 10.2f; Number expectedNumber = 10.21f - 10.2f;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("10.21f - 10.2f"); org.springframework.expression.Expression expression = parser.parseExpression("10.21f - 10.2f");
Number result = expression.getValue(context, null, Number.class); Number result = expression.getValue(context, null, Number.class);
assertEquals("Equal assertion failed for SPR_9486_subtractFloatWithFloatTest Test: ", expectedNumber, result); assertEquals("Equal assertion failed for SPR_9486_subtractFloatWithFloatTest Test: ", expectedNumber, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_subtractFloatWithFloatTest");
}
} }
@Test @Test
public void SPR_9486_multiplyFloatWithDoubleTest() { public void SPR_9486_multiplyFloatWithDoubleTest() {
try {
Number expectedNumber = 10.21f * 10.2; Number expectedNumber = 10.21f * 10.2;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("10.21f * 10.2"); org.springframework.expression.Expression expression = parser.parseExpression("10.21f * 10.2");
Number result = expression.getValue(context, null, Number.class); Number result = expression.getValue(context, null, Number.class);
assertEquals("Equal assertion failed for float multiplied by double Test: ", expectedNumber, result); assertEquals("Equal assertion failed for float multiplied by double Test: ", expectedNumber, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_multiplyFloatWithDoubleTest");
}
} }
@Test @Test
public void SPR_9486_multiplyFloatWithFloatTest() { public void SPR_9486_multiplyFloatWithFloatTest() {
try {
Number expectedNumber = 10.21f * 10.2f; Number expectedNumber = 10.21f * 10.2f;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("10.21f * 10.2f"); org.springframework.expression.Expression expression = parser.parseExpression("10.21f * 10.2f");
Number result = expression.getValue(context, null, Number.class); Number result = expression.getValue(context, null, Number.class);
assertEquals("Equal assertion failed for float multiply by another float Test: ", expectedNumber, result); assertEquals("Equal assertion failed for float multiply by another float Test: ", expectedNumber, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_multiplyFloatWithFloatTest");
}
} }
@Test @Test
public void SPR_9486_floatDivideByFloatTest() { public void SPR_9486_floatDivideByFloatTest() {
try {
Number expectedNumber = -10.21f/-10.2f; Number expectedNumber = -10.21f/-10.2f;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("-10.21f / -10.2f"); org.springframework.expression.Expression expression = parser.parseExpression("-10.21f / -10.2f");
Number result = expression.getValue(context, null, Number.class); Number result = expression.getValue(context, null, Number.class);
assertEquals("Equal assertion failed for float divide Test: ", expectedNumber, result); assertEquals("Equal assertion failed for float divide Test: ", expectedNumber, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_floatDivideByFloatTest");
}
} }
@Test @Test
public void SPR_9486_floatDivideByDoubleTest() { public void SPR_9486_floatDivideByDoubleTest() {
try {
Number expectedNumber = -10.21f/-10.2; Number expectedNumber = -10.21f/-10.2;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("-10.21f / -10.2"); org.springframework.expression.Expression expression = parser.parseExpression("-10.21f / -10.2");
Number result = expression.getValue(context, null, Number.class); Number result = expression.getValue(context, null, Number.class);
assertEquals("Equal assertion failed for float divide Test: ", expectedNumber, result); assertEquals("Equal assertion failed for float divide Test: ", expectedNumber, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_floatDivideByDoubleTest");
}
} }
@Test @Test
public void SPR_9486_floatEqFloatUnaryMinusTest() { public void SPR_9486_floatEqFloatUnaryMinusTest() {
try {
Boolean expectedResult = -10.21f == -10.2f; Boolean expectedResult = -10.21f == -10.2f;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("-10.21f == -10.2f"); org.springframework.expression.Expression expression = parser.parseExpression("-10.21f == -10.2f");
Boolean result = expression.getValue(context, null, Boolean.class); Boolean result = expression.getValue(context, null, Boolean.class);
assertEquals("Equal assertion failed for SPR_9486_floatEqFloatUnaryMinusTest Test: ", expectedResult, result); assertEquals("Equal assertion failed for SPR_9486_floatEqFloatUnaryMinusTest Test: ", expectedResult, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_floatEqFloatUnaryMinusTest");
}
} }
@Test @Test
public void SPR_9486_floatEqDoubleUnaryMinusTest() { public void SPR_9486_floatEqDoubleUnaryMinusTest() {
try {
Boolean expectedResult = -10.21f == -10.2; Boolean expectedResult = -10.21f == -10.2;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("-10.21f == -10.2"); org.springframework.expression.Expression expression = parser.parseExpression("-10.21f == -10.2");
Boolean result = expression.getValue(context, null, Boolean.class); Boolean result = expression.getValue(context, null, Boolean.class);
assertEquals("Equal assertion failed for SPR_9486_floatEqDoubleUnaryMinusTest Test: ", expectedResult, result); assertEquals("Equal assertion failed for SPR_9486_floatEqDoubleUnaryMinusTest Test: ", expectedResult, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_floatEqDoubleUnaryMinusTest");
}
} }
@Test @Test
public void SPR_9486_floatEqFloatTest() { public void SPR_9486_floatEqFloatTest() {
try {
Boolean expectedResult = 10.215f == 10.2109f; Boolean expectedResult = 10.215f == 10.2109f;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("10.215f == 10.2109f"); org.springframework.expression.Expression expression = parser.parseExpression("10.215f == 10.2109f");
Boolean result = expression.getValue(context, null, Boolean.class); Boolean result = expression.getValue(context, null, Boolean.class);
assertEquals("Equal assertion failed for SPR_9486_floatEqFloatTest Test: ", expectedResult, result); assertEquals("Equal assertion failed for SPR_9486_floatEqFloatTest Test: ", expectedResult, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_floatEqFloatTest");
}
} }
@Test @Test
public void SPR_9486_floatEqDoubleTest() { public void SPR_9486_floatEqDoubleTest() {
try {
Boolean expectedResult = 10.215f == 10.2109; Boolean expectedResult = 10.215f == 10.2109;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("10.215f == 10.2109"); org.springframework.expression.Expression expression = parser.parseExpression("10.215f == 10.2109");
Boolean result = expression.getValue(context, null, Boolean.class); Boolean result = expression.getValue(context, null, Boolean.class);
assertEquals("Equal assertion failed for SPR_9486_floatEqDoubleTest() Test: ", expectedResult, result); assertEquals("Equal assertion failed for SPR_9486_floatEqDoubleTest() Test: ", expectedResult, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_floatEqDoubleTest()");
}
} }
@Test @Test
public void SPR_9486_floatNotEqFloatTest() { public void SPR_9486_floatNotEqFloatTest() {
try {
Boolean expectedResult = 10.215f != 10.2109f; Boolean expectedResult = 10.215f != 10.2109f;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("10.215f != 10.2109f"); org.springframework.expression.Expression expression = parser.parseExpression("10.215f != 10.2109f");
Boolean result = expression.getValue(context, null, Boolean.class); Boolean result = expression.getValue(context, null, Boolean.class);
assertEquals("Equal assertion failed for SPR_9486_floatEqFloatTest Test: ", expectedResult, result); assertEquals("Equal assertion failed for SPR_9486_floatEqFloatTest Test: ", expectedResult, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_floatEqFloatTest");
}
} }
@Test @Test
public void SPR_9486_floatNotEqDoubleTest() { public void SPR_9486_floatNotEqDoubleTest() {
try {
Boolean expectedResult = 10.215f != 10.2109; Boolean expectedResult = 10.215f != 10.2109;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("10.215f != 10.2109"); org.springframework.expression.Expression expression = parser.parseExpression("10.215f != 10.2109");
Boolean result = expression.getValue(context, null, Boolean.class); Boolean result = expression.getValue(context, null, Boolean.class);
assertEquals("Equal assertion failed for SPR_9486_floatNotEqDoubleTest Test: ", expectedResult, result); assertEquals("Equal assertion failed for SPR_9486_floatNotEqDoubleTest Test: ", expectedResult, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_floatNotEqDoubleTest");
}
} }
@Test @Test
public void SPR_9486_floatLessThanFloatTest() { public void SPR_9486_floatLessThanFloatTest() {
try {
Boolean expectedNumber = -10.21f < -10.2f; Boolean expectedNumber = -10.21f < -10.2f;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("-10.21f < -10.2f"); org.springframework.expression.Expression expression = parser.parseExpression("-10.21f < -10.2f");
Boolean result = expression.getValue(context, null, Boolean.class); Boolean result = expression.getValue(context, null, Boolean.class);
assertEquals("Equal assertion failed for SPR_9486_floatLessThanFloatTest Test: ", expectedNumber, result); assertEquals("Equal assertion failed for SPR_9486_floatLessThanFloatTest Test: ", expectedNumber, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_floatLessThanFloatTest()");
}
} }
@Test @Test
public void SPR_9486_floatLessThanDoubleTest() { public void SPR_9486_floatLessThanDoubleTest() {
try {
Boolean expectedNumber = -10.21f < -10.2; Boolean expectedNumber = -10.21f < -10.2;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("-10.21f < -10.2"); org.springframework.expression.Expression expression = parser.parseExpression("-10.21f < -10.2");
Boolean result = expression.getValue(context, null, Boolean.class); Boolean result = expression.getValue(context, null, Boolean.class);
assertEquals("Equal assertion failed for SPR_9486_floatLessThanDoubleTest Test: ", expectedNumber, result); assertEquals("Equal assertion failed for SPR_9486_floatLessThanDoubleTest Test: ", expectedNumber, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_floatLessThanDoubleTest()");
}
} }
@Test @Test
public void SPR_9486_floatLessThanOrEqualFloatTest() { public void SPR_9486_floatLessThanOrEqualFloatTest() {
try {
Boolean expectedNumber = -10.21f <= -10.22f; Boolean expectedNumber = -10.21f <= -10.22f;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("-10.21f <= -10.22f"); org.springframework.expression.Expression expression = parser.parseExpression("-10.21f <= -10.22f");
Boolean result = expression.getValue(context, null, Boolean.class); Boolean result = expression.getValue(context, null, Boolean.class);
assertEquals("Equal assertion failed for SPR_9486_floatLessThanOrEqualFloatTest Test: ", expectedNumber, result); assertEquals("Equal assertion failed for SPR_9486_floatLessThanOrEqualFloatTest Test: ", expectedNumber, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_floatLessThanOrEqualFloatTest");
}
} }
@Test @Test
public void SPR_9486_floatLessThanOrEqualDoubleTest() { public void SPR_9486_floatLessThanOrEqualDoubleTest() {
try {
Boolean expectedNumber = -10.21f <= -10.2; Boolean expectedNumber = -10.21f <= -10.2;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("-10.21f <= -10.2"); org.springframework.expression.Expression expression = parser.parseExpression("-10.21f <= -10.2");
Boolean result = expression.getValue(context, null, Boolean.class); Boolean result = expression.getValue(context, null, Boolean.class);
assertEquals("Equal assertion failed for SPR_9486_floatLessThanOrEqualDoubleTest Test: ", expectedNumber, result); assertEquals("Equal assertion failed for SPR_9486_floatLessThanOrEqualDoubleTest Test: ", expectedNumber, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_floatLessThanOrEqualDoubleTest");
}
} }
@Test @Test
public void SPR_9486_floatGreaterThanFloatTest() { public void SPR_9486_floatGreaterThanFloatTest() {
try {
Boolean expectedNumber = -10.21f > -10.2f; Boolean expectedNumber = -10.21f > -10.2f;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("-10.21f > -10.2f"); org.springframework.expression.Expression expression = parser.parseExpression("-10.21f > -10.2f");
Boolean result = expression.getValue(context, null, Boolean.class); Boolean result = expression.getValue(context, null, Boolean.class);
assertEquals("Equal assertion failed for SPR_9486_floatGreaterThanFloatTest Test: ", expectedNumber, result); assertEquals("Equal assertion failed for SPR_9486_floatGreaterThanFloatTest Test: ", expectedNumber, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_floatGreaterThanTest");
}
} }
@Test @Test
public void SPR_9486_floatGreaterThanDoubleTest() { public void SPR_9486_floatGreaterThanDoubleTest() {
try {
Boolean expectedResult = -10.21f > -10.2; Boolean expectedResult = -10.21f > -10.2;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("-10.21f > -10.2"); org.springframework.expression.Expression expression = parser.parseExpression("-10.21f > -10.2");
Boolean result = expression.getValue(context, null, Boolean.class); Boolean result = expression.getValue(context, null, Boolean.class);
assertEquals("Equal assertion failed for SPR_9486_floatGreaterThanDoubleTest Test: ", expectedResult, result); assertEquals("Equal assertion failed for SPR_9486_floatGreaterThanDoubleTest Test: ", expectedResult, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_floatGreaterThanTest");
}
} }
@Test @Test
public void SPR_9486_floatGreaterThanOrEqualFloatTest() { public void SPR_9486_floatGreaterThanOrEqualFloatTest() {
try {
Boolean expectedNumber = -10.21f >= -10.2f; Boolean expectedNumber = -10.21f >= -10.2f;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("-10.21f >= -10.2f"); org.springframework.expression.Expression expression = parser.parseExpression("-10.21f >= -10.2f");
Boolean result = expression.getValue(context, null, Boolean.class); Boolean result = expression.getValue(context, null, Boolean.class);
assertEquals("Equal assertion failed for SPR_9486_floatGreaterThanFloatTest Test: ", expectedNumber, result); assertEquals("Equal assertion failed for SPR_9486_floatGreaterThanFloatTest Test: ", expectedNumber, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_floatGreaterThanTest");
}
} }
@Test @Test
public void SPR_9486_floatGreaterThanEqualDoubleTest() { public void SPR_9486_floatGreaterThanEqualDoubleTest() {
try {
Boolean expectedResult = -10.21f >= -10.2; Boolean expectedResult = -10.21f >= -10.2;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("-10.21f >= -10.2"); org.springframework.expression.Expression expression = parser.parseExpression("-10.21f >= -10.2");
Boolean result = expression.getValue(context, null, Boolean.class); Boolean result = expression.getValue(context, null, Boolean.class);
assertEquals("Equal assertion failed for SPR_9486_floatGreaterThanDoubleTest Test: ", expectedResult, result); assertEquals("Equal assertion failed for SPR_9486_floatGreaterThanDoubleTest Test: ", expectedResult, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_floatGreaterThanTest");
}
} }
@Test @Test
public void SPR_9486_floatModulusFloatTest() { public void SPR_9486_floatModulusFloatTest() {
try {
Number expectedResult = 10.21f % 10.2f; Number expectedResult = 10.21f % 10.2f;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("10.21f % 10.2f"); org.springframework.expression.Expression expression = parser.parseExpression("10.21f % 10.2f");
Number result = expression.getValue(context, null, Number.class); Number result = expression.getValue(context, null, Number.class);
assertEquals("Equal assertion failed for SPR_9486_floatModulusFloatTest Test: ", expectedResult, result); assertEquals("Equal assertion failed for SPR_9486_floatModulusFloatTest Test: ", expectedResult, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_floatModulusFloatTest");
}
} }
@Test @Test
public void SPR_9486_floatModulusDoubleTest() { public void SPR_9486_floatModulusDoubleTest() {
try {
Number expectedResult = 10.21f % 10.2; Number expectedResult = 10.21f % 10.2;
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("10.21f % 10.2"); org.springframework.expression.Expression expression = parser.parseExpression("10.21f % 10.2");
Number result = expression.getValue(context, null, Number.class); Number result = expression.getValue(context, null, Number.class);
assertEquals("Equal assertion failed for SPR_9486_floatModulusDoubleTest Test: ", expectedResult, result); assertEquals("Equal assertion failed for SPR_9486_floatModulusDoubleTest Test: ", expectedResult, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_floatModulusDoubleTest");
}
} }
@Test @Test
public void SPR_9486_floatPowerFloatTest() { public void SPR_9486_floatPowerFloatTest() {
try {
Number expectedResult = Math.pow(10.21f, -10.2f); Number expectedResult = Math.pow(10.21f, -10.2f);
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("10.21f ^ -10.2f"); org.springframework.expression.Expression expression = parser.parseExpression("10.21f ^ -10.2f");
Number result = expression.getValue(context, null, Number.class); Number result = expression.getValue(context, null, Number.class);
assertEquals("Equal assertion failed for SPR_9486_floatPowerFloatTest Test: ", expectedResult, result); assertEquals("Equal assertion failed for SPR_9486_floatPowerFloatTest Test: ", expectedResult, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_floatPowerFloatTest");
}
} }
@Test @Test
public void SPR_9486_floatPowerDoubleTest() { public void SPR_9486_floatPowerDoubleTest() {
try {
Number expectedResult = Math.pow(10.21f, 10.2); Number expectedResult = Math.pow(10.21f, 10.2);
ExpressionParser parser = new SpelExpressionParser(); ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext(); StandardEvaluationContext context = new StandardEvaluationContext();
org.springframework.expression.Expression expression = parser.parseExpression("10.21f ^ 10.2"); org.springframework.expression.Expression expression = parser.parseExpression("10.21f ^ 10.2");
Number result = expression.getValue(context, null, Number.class); Number result = expression.getValue(context, null, Number.class);
assertEquals("Equal assertion failed for SPR_9486_floatPowerDoubleTest Test: ", expectedResult, result); assertEquals("Equal assertion failed for SPR_9486_floatPowerDoubleTest Test: ", expectedResult, result);
} catch (Exception e) {
e.printStackTrace();
fail("Test failed - SPR_9486_floatPowerDoubleTest");
}
} }
@Test @Test
@ -1877,6 +1782,7 @@ public class SpelReproTests extends ExpressionTestCase {
public T getProperty(); public T getProperty();
} }
private static class GenericImplementation implements GenericInterface<Integer> { private static class GenericImplementation implements GenericInterface<Integer> {
@Override @Override
@ -1885,6 +1791,7 @@ public class SpelReproTests extends ExpressionTestCase {
} }
} }
static class PackagePrivateClassWithGetter { static class PackagePrivateClassWithGetter {
public Integer getProperty() { public Integer getProperty() {
@ -1892,26 +1799,29 @@ public class SpelReproTests extends ExpressionTestCase {
} }
} }
public static class OnlyBridgeMethod extends PackagePrivateClassWithGetter {
public static class OnlyBridgeMethod extends PackagePrivateClassWithGetter {
} }
public static interface StaticFinal { public static interface StaticFinal {
public static final String VALUE = "interfaceValue"; public static final String VALUE = "interfaceValue";
} }
public abstract static class AbstractStaticFinal implements StaticFinal { public abstract static class AbstractStaticFinal implements StaticFinal {
} }
public static class StaticFinalImpl1 extends AbstractStaticFinal implements StaticFinal { public static class StaticFinalImpl1 extends AbstractStaticFinal implements StaticFinal {
} }
public static class StaticFinalImpl2 extends AbstractStaticFinal { public static class StaticFinalImpl2 extends AbstractStaticFinal {
} }
/**
* The Class TestObject.
*/
public static class SPR10486 { public static class SPR10486 {
private String name = "name"; private String name = "name";
@ -1923,14 +1833,14 @@ public class SpelReproTests extends ExpressionTestCase {
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
} }
static class SPR11142 { static class SPR11142 {
public String isSomething() { public String isSomething() {
return ""; return "";
} }
}
} }
}