diff --git a/spring-expression/src/main/java/org/springframework/expression/TypeComparator.java b/spring-expression/src/main/java/org/springframework/expression/TypeComparator.java index 1dfb41adc7..d12122dbbc 100644 --- a/spring-expression/src/main/java/org/springframework/expression/TypeComparator.java +++ b/spring-expression/src/main/java/org/springframework/expression/TypeComparator.java @@ -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"); * you may not use this file except in compliance with the License. @@ -17,30 +17,32 @@ package org.springframework.expression; /** - * Instances of a type comparator should be able to compare pairs of objects for equality, the specification of the - * return value is the same as for {@link Comparable}. + * Instances of a type comparator should be able to compare pairs of objects for equality. + * The specification of the return value is the same as for {@link java.lang.Comparable}. * * @author Andy Clement * @since 3.0 + * @see java.lang.Comparable */ public interface TypeComparator { /** - * Compare two objects. + * Return {@code true} if the comparator can compare these two 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 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 + * @return {@code true} if the comparator can compare these objects */ 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; + } diff --git a/spring-expression/src/main/java/org/springframework/expression/TypeConverter.java b/spring-expression/src/main/java/org/springframework/expression/TypeConverter.java index 2fad0f98a5..ee78104dca 100644 --- a/spring-expression/src/main/java/org/springframework/expression/TypeConverter.java +++ b/spring-expression/src/main/java/org/springframework/expression/TypeConverter.java @@ -35,22 +35,23 @@ public interface TypeConverter { * to the desired target type. * @param sourceType a type descriptor that describes the source 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); /** - * Convert (may coerce) a value from one type to another, for example from a boolean - * to a string. The typeDescriptor parameter enables support for typed collections - - * if the caller really wishes they can have a List<Integer> for example, rather - * than simply a List. + * Convert (or coerce) a value from one type to another, for example from a + * {@code boolean} to a {@code String}. + *

The {@link TypeDescriptor} parameters enable support for typed collections: + * A caller may prefer a {@code List<Integer>}, for example, rather than + * simply any {@code List}. * @param value the value to be converted * @param sourceType a type descriptor that supplies extra information about the * source object * @param targetType a type descriptor that supplies extra information about the * requested result type * @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); diff --git a/spring-expression/src/main/java/org/springframework/expression/TypeLocator.java b/spring-expression/src/main/java/org/springframework/expression/TypeLocator.java index 4a22a82c19..e969626895 100644 --- a/spring-expression/src/main/java/org/springframework/expression/TypeLocator.java +++ b/spring-expression/src/main/java/org/springframework/expression/TypeLocator.java @@ -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"); * you may not use this file except in compliance with the License. @@ -17,9 +17,12 @@ package org.springframework.expression; /** - * Implementors of this interface are expected to be able to locate types. They may use custom classloaders - * or the and deal with common package prefixes (java.lang, etc) however they wish. See - * {@link org.springframework.expression.spel.support.StandardTypeLocator} for an example implementation. + * Implementers of this interface are expected to be able to locate types. + * They may use a custom {@link ClassLoader} and/or deal with common + * package prefixes (e.g. {@code java.lang}) however they wish. + * + *

See {@link org.springframework.expression.spel.support.StandardTypeLocator} + * for an example implementation. * * @author Andy Clement * @since 3.0 @@ -27,11 +30,12 @@ package org.springframework.expression; public interface TypeLocator { /** - * Find a type by name. The name may or may not be fully qualified (eg. String or java.lang.String) - * @param typename the type to be located - * @return the class object representing that type - * @throws EvaluationException if there is a problem finding it + * Find a type by name. The name may or may not be fully qualified + * (e.g. {@code String} or {@code java.lang.String}). + * @param typeName the type to be located + * @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; } diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeComparator.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeComparator.java index 18f29d148b..97528526d5 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeComparator.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeComparator.java @@ -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"); * 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; /** - * 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 Juergen Hoeller @@ -29,49 +30,6 @@ import org.springframework.expression.spel.SpelMessage; */ 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) { if (left == null || right == null) { return true; @@ -85,4 +43,56 @@ public class StandardTypeComparator implements TypeComparator { 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)); + } + } diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java index 5d75cf55db..4c2f5f2fb8 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java @@ -18,7 +18,6 @@ package org.springframework.expression.spel.support; import org.springframework.core.convert.ConversionException; import org.springframework.core.convert.ConversionService; -import org.springframework.core.convert.ConverterNotFoundException; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.expression.TypeConverter; @@ -27,8 +26,8 @@ import org.springframework.expression.spel.SpelMessage; import org.springframework.util.Assert; /** - * Default implementation of the {@link TypeConverter} interface, delegating to a core - * Spring {@link ConversionService}. + * Default implementation of the {@link TypeConverter} interface, + * delegating to a core Spring {@link ConversionService}. * * @author Juergen Hoeller * @author Andy Clement @@ -42,6 +41,9 @@ public class StandardTypeConverter implements TypeConverter { private final ConversionService conversionService; + /** + * Create a StandardTypeConverter for the default ConversionService. + */ public StandardTypeConverter() { synchronized (this) { if (defaultConversionService == null) { @@ -51,6 +53,10 @@ public class StandardTypeConverter implements TypeConverter { this.conversionService = defaultConversionService; } + /** + * Create a StandardTypeConverter for the given ConversionService. + * @param conversionService the ConversionService to delegate to + */ public StandardTypeConverter(ConversionService conversionService) { Assert.notNull(conversionService, "ConversionService must not be null"); this.conversionService = conversionService; @@ -65,10 +71,6 @@ public class StandardTypeConverter implements TypeConverter { try { 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) { throw new SpelEvaluationException( ex, SpelMessage.TYPE_CONVERSION_ERROR, sourceType.toString(), targetType.toString()); diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeLocator.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeLocator.java index 2a210e3fda..7b6b45aae2 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeLocator.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeLocator.java @@ -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"); * you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ package org.springframework.expression.spel.support; -import java.util.ArrayList; import java.util.Collections; +import java.util.LinkedList; import java.util.List; import org.springframework.expression.EvaluationException; @@ -27,8 +27,9 @@ import org.springframework.expression.spel.SpelMessage; import org.springframework.util.ClassUtils; /** - * A default implementation of a TypeLocator that uses the context classloader (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. + * A simple implementation of {@link TypeLocator} that uses the context ClassLoader + * (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 Juergen Hoeller @@ -36,49 +37,30 @@ import org.springframework.util.ClassUtils; */ public class StandardTypeLocator implements TypeLocator { - private ClassLoader loader; + private final ClassLoader classLoader; - private final List knownPackagePrefixes = new ArrayList(); + private final List knownPackagePrefixes = new LinkedList(); + /** + * Create a StandardTypeLocator for the default ClassLoader + * (typically, the thread context ClassLoader). + */ public StandardTypeLocator() { this(ClassUtils.getDefaultClassLoader()); } - public StandardTypeLocator(ClassLoader loader) { - this.loader = loader; - // Similar to when writing Java, it only knows about java.lang by default + /** + * Create a StandardTypeLocator for the given ClassLoader. + * @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"); } - /** - * 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. * Expected format is something like "java.lang". @@ -88,16 +70,48 @@ public class StandardTypeLocator implements TypeLocator { 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 list of registered import prefixes + * @return a list of registered import prefixes */ public List getImportPrefixes() { 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); } } diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java index c6957f862b..0bbbe01ce5 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java @@ -27,7 +27,6 @@ import java.util.List; import java.util.Map; import java.util.Properties; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -75,9 +74,8 @@ public class SpelReproTests extends ExpressionTestCase { } @Test - @Ignore 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 @@ -101,7 +99,8 @@ public class SpelReproTests extends ExpressionTestCase { expr = new SpelExpressionParser().parseRaw("tryToInvokeWithNull2(null)"); expr.getValue(); fail("Should have failed to find a method to which it could pass null"); - } catch (EvaluationException see) { + } + catch (EvaluationException see) { // success } eContext.setTypeLocator(new MyTypeLocator()); @@ -133,31 +132,44 @@ public class SpelReproTests extends ExpressionTestCase { static class MyTypeLocator extends StandardTypeLocator { @Override - public Class findType(String typename) throws EvaluationException { - if (typename.equals("Spr5899Class")) { + public Class findType(String typeName) throws EvaluationException { + if (typeName.equals("Spr5899Class")) { return Spr5899Class.class; } - if (typename.equals("Outer")) { + if (typeName.equals("Outer")) { return Outer.class; } - return super.findType(typename); + return super.findType(typeName); } } static class Spr5899Class { - public Spr5899Class() {} - 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 Spr5899Class() { + } + + 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) { StringBuilder sb = new StringBuilder(); - for (int i=0;i[] getSpecificTargetClasses() { return new Class[] {Map.class}; } - } @Test @@ -323,13 +338,15 @@ public class SpelReproTests extends ExpressionTestCase { try { propertyAccessor.read(context, null, "abc"); fail("Should have failed with an AccessException"); - } catch (AccessException ae) { + } + catch (AccessException ae) { // success } try { propertyAccessor.write(context, null, "abc","foo"); fail("Should have failed with an AccessException"); - } catch (AccessException ae) { + } + catch (AccessException ae) { // success } } @@ -347,20 +364,25 @@ public class SpelReproTests extends ExpressionTestCase { } static class Foo { + public ResourceSummary resource = new ResourceSummary(); } static class ResourceSummary { + + private final Resource resource; + ResourceSummary() { this.resource = new Resource(); } - private final Resource resource; + public Resource getResource() { return resource; } } static class Resource { + public String getServer() { return "abc"; } @@ -498,6 +520,7 @@ public class SpelReproTests extends ExpressionTestCase { } static class XX { + public Map m; public String floo ="bar"; @@ -512,7 +535,9 @@ public class SpelReproTests extends ExpressionTestCase { static class Goo { public static Goo instance = new Goo(); + public String bar = "key"; + public String value = null; public String wibble = "wobble"; @@ -524,7 +549,6 @@ public class SpelReproTests extends ExpressionTestCase { public void setKey(String s) { value = s; } - } static class Holder { @@ -553,23 +577,27 @@ public class SpelReproTests extends ExpressionTestCase { try { parser.parseExpression(expression,context); fail("Should have failed"); - } catch (Exception e) { - if (!e.getMessage().equals(expectedMessage)) { - e.printStackTrace(); + } + catch (Exception ex) { + if (!ex.getMessage().equals(expectedMessage)) { + ex.printStackTrace(); } - assertEquals(expectedMessage,e.getMessage()); + assertEquals(expectedMessage, ex.getMessage()); } } private static final ParserContext DOLLARSQUARE_TEMPLATE_PARSER_CONTEXT = new ParserContext() { + @Override public String getExpressionPrefix() { return "$["; } + @Override public String getExpressionSuffix() { return "]"; } + @Override public boolean isTemplate() { return true; @@ -577,12 +605,14 @@ public class SpelReproTests extends ExpressionTestCase { }; static class Foo2 { + public void execute(String str){ System.out.println("Value: " + str); } } static class Message{ + private String payload; public String getPayload() { @@ -605,7 +635,8 @@ public class SpelReproTests extends ExpressionTestCase { try { expr = new SpelExpressionParser().parseRaw("@foo"); assertEquals("custard",expr.getValue(eContext,String.class)); - } catch (SpelEvaluationException see) { + } + catch (SpelEvaluationException see) { assertEquals(SpelMessage.NO_BEAN_RESOLVER_REGISTERED,see.getMessageCode()); assertEquals("foo",see.getInserts()[0]); } @@ -624,7 +655,8 @@ public class SpelReproTests extends ExpressionTestCase { expr = new SpelExpressionParser().parseRaw("@goo"); try { assertEquals(null,expr.getValue(eContext,String.class)); - } catch (SpelEvaluationException see) { + } + catch (SpelEvaluationException see) { assertEquals(SpelMessage.EXCEPTION_DURING_BEAN_RESOLUTION,see.getMessageCode()); assertEquals("goo",see.getInserts()[0]); assertTrue(see.getCause() instanceof AccessException); @@ -639,19 +671,23 @@ public class SpelReproTests extends ExpressionTestCase { try { expr = new SpelExpressionParser().parseRaw("@378"); assertEquals("trouble",expr.getValue(eContext,String.class)); - } catch (SpelParseException spe) { + } + catch (SpelParseException spe) { assertEquals(SpelMessage.INVALID_BEAN_REFERENCE,spe.getMessageCode()); } } static class MyBeanResolver implements BeanResolver { + @Override - public Object resolve(EvaluationContext context, String beanname) throws AccessException { - if (beanname.equals("foo")) { + public Object resolve(EvaluationContext context, String beanName) throws AccessException { + if (beanName.equals("foo")) { return "custard"; - } else if (beanname.equals("foo.bar")) { + } + else if (beanName.equals("foo.bar")) { return "trouble"; - } else if (beanname.equals("goo")) { + } + else if (beanName.equals("goo")) { throw new AccessException("DONT ASK ME ABOUT GOO"); } return null; @@ -678,7 +714,8 @@ public class SpelReproTests extends ExpressionTestCase { expr = new SpelExpressionParser().parseRaw("(?'abc':'default')"); expr.getValue(eContext); fail(); - } catch (SpelEvaluationException see ) { + } + catch (SpelEvaluationException see ) { assertEquals(SpelMessage.TYPE_CONVERSION_ERROR,see.getMessageCode()); } expr = new SpelExpressionParser().parseRaw("(false?'abc':null)"); @@ -689,7 +726,8 @@ public class SpelReproTests extends ExpressionTestCase { expr = new SpelExpressionParser().parseRaw("(='default')"); expr.getValue(eContext); fail(); - } catch (SpelEvaluationException see ) { + } + catch (SpelEvaluationException see ) { assertEquals(SpelMessage.SETVALUE_NOT_SUPPORTED,see.getMessageCode()); } } @@ -913,7 +951,6 @@ public class SpelReproTests extends ExpressionTestCase { } - @Test public void varargsAndPrimitives_SPR8174() throws Exception { EvaluationContext emptyEvalContext = new StandardEvaluationContext(); @@ -960,60 +997,59 @@ public class SpelReproTests extends ExpressionTestCase { args.add(TypeDescriptor.forObject(23f)); me = new ReflectiveMethodResolver().resolve(emptyEvalContext,ru,"bar",args); me.execute(emptyEvalContext, ru, 12,23f); - } - public class ReflectionUtil { + public Object methodToCall(T param) { System.out.println(param+" "+param.getClass()); - return "Object methodToCall(T param)"; + return "Object methodToCall(T param)"; } public void foo(int... array) { - if (array.length==0) { + if (array.length == 0) { throw new RuntimeException(); } } public void foo(float...array) { - if (array.length==0) { + if (array.length == 0) { throw new RuntimeException(); } } public void foo(double...array) { - if (array.length==0) { + if (array.length == 0) { throw new RuntimeException(); } } public void foo(short...array) { - if (array.length==0) { + if (array.length == 0) { throw new RuntimeException(); } } public void foo(long...array) { - if (array.length==0) { + if (array.length == 0) { throw new RuntimeException(); } } public void foo(boolean...array) { - if (array.length==0) { + if (array.length == 0) { throw new RuntimeException(); } } public void foo(char...array) { - if (array.length==0) { + if (array.length == 0) { throw new RuntimeException(); } } public void foo(byte...array) { - if (array.length==0) { + if (array.length == 0) { throw new RuntimeException(); } } public void bar(int... array) { - if (array.length==0) { + if (array.length == 0) { throw new RuntimeException(); } } @@ -1040,41 +1076,42 @@ public class SpelReproTests extends ExpressionTestCase { m.put("NE","xyz"); } } + StandardEvaluationContext ctx = new StandardEvaluationContext(new Reserver()); SpelExpressionParser parser = new SpelExpressionParser(); String ex = "getReserver().NE"; - SpelExpression exp = null; - exp = parser.parseRaw(ex); - String value = (String)exp.getValue(ctx); - assertEquals("abc",value); + SpelExpression exp = parser.parseRaw(ex); + String value = (String) exp.getValue(ctx); + assertEquals("abc", value); ex = "getReserver().ne"; exp = parser.parseRaw(ex); - value = (String)exp.getValue(ctx); - assertEquals("def",value); + value = (String) exp.getValue(ctx); + assertEquals("def", value); ex = "getReserver().m[NE]"; exp = parser.parseRaw(ex); - value = (String)exp.getValue(ctx); - assertEquals("xyz",value); + value = (String) exp.getValue(ctx); + assertEquals("xyz", value); ex = "getReserver().DIV"; exp = parser.parseRaw(ex); - assertEquals(1,exp.getValue(ctx)); + assertEquals(1, exp.getValue(ctx)); ex = "getReserver().div"; exp = parser.parseRaw(ex); - assertEquals(3,exp.getValue(ctx)); + assertEquals(3, exp.getValue(ctx)); exp = parser.parseRaw("NE"); - assertEquals("abc",exp.getValue(ctx)); + assertEquals("abc", exp.getValue(ctx)); } @Test public void testReservedWordProperties_9862() throws Exception { StandardEvaluationContext ctx = new StandardEvaluationContext(); 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); assertEquals(value, Reserver.CONST); } @@ -1107,47 +1144,53 @@ public class SpelReproTests extends ExpressionTestCase { } class TestPropertyAccessor implements PropertyAccessor { + private String mapName; + public TestPropertyAccessor(String mapName) { this.mapName = mapName; } + @SuppressWarnings("unchecked") public Map getMap(Object target) { try { Field f = target.getClass().getDeclaredField(mapName); return (Map) f.get(target); - } catch (Exception e) { + } + catch (Exception ex) { } return null; } + @Override - public boolean canRead(EvaluationContext context, Object target, String name) - throws AccessException { + public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException { return getMap(target).containsKey(name); } + @Override - public boolean canWrite(EvaluationContext context, Object target, String name) - throws AccessException { + public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException { return getMap(target).containsKey(name); } + @Override public Class[] getSpecificTargetClasses() { - return new Class[]{ContextObject.class}; + return new Class[] {ContextObject.class}; } + @Override - public TypedValue read(EvaluationContext context, Object target, String name) - throws AccessException { + public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException { return new TypedValue(getMap(target).get(name)); } + @Override public void write(EvaluationContext context, Object target, String name, Object newValue) throws AccessException { getMap(target).put(name, (String) newValue); } - } class ContextObject { + public Map firstContext = new HashMap(); public Map secondContext = new HashMap(); public Map thirdContext = new HashMap(); @@ -1168,6 +1211,7 @@ public class SpelReproTests extends ExpressionTestCase { fourthContext.put("shouldBeFourth", "fourth"); } + public Map getFirstContext() {return firstContext;} public Map getSecondContext() {return secondContext;} public Map getThirdContext() {return thirdContext;} @@ -1180,33 +1224,28 @@ public class SpelReproTests extends ExpressionTestCase { */ @Test public void testCustomStaticFunctions_SPR9038() { - try { - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - List methodResolvers = new ArrayList(); - methodResolvers.add(new ReflectiveMethodResolver() { - @Override - protected Method[] getMethods(Class type) { - try { - return new Method[] { - Integer.class.getDeclaredMethod("parseInt", new Class[] { - String.class, Integer.TYPE }) }; - } catch (NoSuchMethodException e1) { - return new Method[0]; - } + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + List methodResolvers = new ArrayList(); + methodResolvers.add(new ReflectiveMethodResolver() { + @Override + protected Method[] getMethods(Class type) { + try { + return new Method[] {Integer.class.getDeclaredMethod("parseInt", + new Class[] {String.class, Integer.TYPE })}; } - }); + catch (NoSuchMethodException ex) { + return new Method[0]; + } + } + }); - context.setMethodResolvers(methodResolvers); - org.springframework.expression.Expression expression = - parser.parseExpression("parseInt('-FF', 16)"); + context.setMethodResolvers(methodResolvers); + org.springframework.expression.Expression expression = + parser.parseExpression("parseInt('-FF', 16)"); - Integer result = expression.getValue(context, "", Integer.class); - assertEquals("Equal assertion failed: ", -255, result.intValue()); - } catch (Exception e) { - e.printStackTrace(); - fail("Unexpected exception: "+e.toString()); - } + Integer result = expression.getValue(context, "", Integer.class); + assertEquals("Equal assertion failed: ", -255, result.intValue()); } @Test @@ -1239,23 +1278,19 @@ public class SpelReproTests extends ExpressionTestCase { } @Test - public void SPR_9486_floatFunctionResolverTest() { - try { - Number expectedResult = Math.abs(-10.2f); - ExpressionParser parser = new SpelExpressionParser(); - SPR_9486_FunctionsClass testObject = new SPR_9486_FunctionsClass(); + public void SPR_9486_floatFunctionResolverTest() throws Exception { + Number expectedResult = Math.abs(-10.2f); + ExpressionParser parser = new SpelExpressionParser(); + SPR_9486_FunctionsClass testObject = new SPR_9486_FunctionsClass(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("abs(-10.2f)"); - Number result = expression.getValue(context, testObject, Number.class); - assertEquals("Equal assertion failed for SPR_9486_floatFunctionResolverTest Test: ", expectedResult, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_floatFunctionResolverTest"); - } + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("abs(-10.2f)"); + Number result = expression.getValue(context, testObject, Number.class); + assertEquals("Equal assertion failed for SPR_9486_floatFunctionResolverTest Test: ", expectedResult, result); } class SPR_9486_FunctionsClass { + public int abs(int value) { return Math.abs(value); } @@ -1267,394 +1302,264 @@ public class SpelReproTests extends ExpressionTestCase { @Test public void SPR_9486_addFloatWithDoubleTest() { - try { - Number expectedNumber = 10.21f + 10.2; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("10.21f + 10.2"); - Number result = expression.getValue(context, null, Number.class); - assertEquals("Equal assertion failed for SPR_9486_addFloatWithDoubleTest Test: ", expectedNumber, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_addFloatWithDoubleTest"); - } + Number expectedNumber = 10.21f + 10.2; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("10.21f + 10.2"); + Number result = expression.getValue(context, null, Number.class); + assertEquals("Equal assertion failed for SPR_9486_addFloatWithDoubleTest Test: ", expectedNumber, result); } @Test public void SPR_9486_addFloatWithFloatTest() { - try { - Number expectedNumber = 10.21f + 10.2f; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("10.21f + 10.2f"); - Number result = expression.getValue(context, null, Number.class); - assertEquals("Equal assertion failed for SPR_9486_addFloatWithFloatTest Test: ", expectedNumber, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_addFloatWithFloatTest"); - } + Number expectedNumber = 10.21f + 10.2f; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("10.21f + 10.2f"); + Number result = expression.getValue(context, null, Number.class); + assertEquals("Equal assertion failed for SPR_9486_addFloatWithFloatTest Test: ", expectedNumber, result); } @Test public void SPR_9486_subtractFloatWithDoubleTest() { - try { - Number expectedNumber = 10.21f - 10.2; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("10.21f - 10.2"); - Number result = expression.getValue(context, null, Number.class); - assertEquals("Equal assertion failed for SPR_9486_subtractFloatWithDoubleTest Test: ", expectedNumber, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_subtractFloatWithDoubleTest"); - } + Number expectedNumber = 10.21f - 10.2; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("10.21f - 10.2"); + Number result = expression.getValue(context, null, Number.class); + assertEquals("Equal assertion failed for SPR_9486_subtractFloatWithDoubleTest Test: ", expectedNumber, result); } @Test public void SPR_9486_subtractFloatWithFloatTest() { - try { - Number expectedNumber = 10.21f - 10.2f; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("10.21f - 10.2f"); - Number result = expression.getValue(context, null, Number.class); - assertEquals("Equal assertion failed for SPR_9486_subtractFloatWithFloatTest Test: ", expectedNumber, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_subtractFloatWithFloatTest"); - } + Number expectedNumber = 10.21f - 10.2f; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("10.21f - 10.2f"); + Number result = expression.getValue(context, null, Number.class); + assertEquals("Equal assertion failed for SPR_9486_subtractFloatWithFloatTest Test: ", expectedNumber, result); } @Test public void SPR_9486_multiplyFloatWithDoubleTest() { - try { - Number expectedNumber = 10.21f * 10.2; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("10.21f * 10.2"); - Number result = expression.getValue(context, null, Number.class); - assertEquals("Equal assertion failed for float multiplied by double Test: ", expectedNumber, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_multiplyFloatWithDoubleTest"); - } + Number expectedNumber = 10.21f * 10.2; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("10.21f * 10.2"); + Number result = expression.getValue(context, null, Number.class); + assertEquals("Equal assertion failed for float multiplied by double Test: ", expectedNumber, result); } @Test public void SPR_9486_multiplyFloatWithFloatTest() { - try { - Number expectedNumber = 10.21f * 10.2f; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("10.21f * 10.2f"); - Number result = expression.getValue(context, null, Number.class); - assertEquals("Equal assertion failed for float multiply by another float Test: ", expectedNumber, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_multiplyFloatWithFloatTest"); - } + Number expectedNumber = 10.21f * 10.2f; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("10.21f * 10.2f"); + Number result = expression.getValue(context, null, Number.class); + assertEquals("Equal assertion failed for float multiply by another float Test: ", expectedNumber, result); } @Test public void SPR_9486_floatDivideByFloatTest() { - try { - Number expectedNumber = -10.21f/-10.2f; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("-10.21f / -10.2f"); - Number result = expression.getValue(context, null, Number.class); - assertEquals("Equal assertion failed for float divide Test: ", expectedNumber, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_floatDivideByFloatTest"); - } + Number expectedNumber = -10.21f/-10.2f; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("-10.21f / -10.2f"); + Number result = expression.getValue(context, null, Number.class); + assertEquals("Equal assertion failed for float divide Test: ", expectedNumber, result); } @Test public void SPR_9486_floatDivideByDoubleTest() { - try { - Number expectedNumber = -10.21f/-10.2; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("-10.21f / -10.2"); - Number result = expression.getValue(context, null, Number.class); - assertEquals("Equal assertion failed for float divide Test: ", expectedNumber, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_floatDivideByDoubleTest"); - } + Number expectedNumber = -10.21f/-10.2; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("-10.21f / -10.2"); + Number result = expression.getValue(context, null, Number.class); + assertEquals("Equal assertion failed for float divide Test: ", expectedNumber, result); } @Test public void SPR_9486_floatEqFloatUnaryMinusTest() { - try { - Boolean expectedResult = -10.21f == -10.2f; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("-10.21f == -10.2f"); - Boolean result = expression.getValue(context, null, Boolean.class); - assertEquals("Equal assertion failed for SPR_9486_floatEqFloatUnaryMinusTest Test: ", expectedResult, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_floatEqFloatUnaryMinusTest"); - } + Boolean expectedResult = -10.21f == -10.2f; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("-10.21f == -10.2f"); + Boolean result = expression.getValue(context, null, Boolean.class); + assertEquals("Equal assertion failed for SPR_9486_floatEqFloatUnaryMinusTest Test: ", expectedResult, result); } @Test public void SPR_9486_floatEqDoubleUnaryMinusTest() { - try { - Boolean expectedResult = -10.21f == -10.2; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("-10.21f == -10.2"); - Boolean result = expression.getValue(context, null, Boolean.class); - assertEquals("Equal assertion failed for SPR_9486_floatEqDoubleUnaryMinusTest Test: ", expectedResult, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_floatEqDoubleUnaryMinusTest"); - } + Boolean expectedResult = -10.21f == -10.2; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("-10.21f == -10.2"); + Boolean result = expression.getValue(context, null, Boolean.class); + assertEquals("Equal assertion failed for SPR_9486_floatEqDoubleUnaryMinusTest Test: ", expectedResult, result); } @Test public void SPR_9486_floatEqFloatTest() { - try { - Boolean expectedResult = 10.215f == 10.2109f; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("10.215f == 10.2109f"); - Boolean result = expression.getValue(context, null, Boolean.class); - assertEquals("Equal assertion failed for SPR_9486_floatEqFloatTest Test: ", expectedResult, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_floatEqFloatTest"); - } + Boolean expectedResult = 10.215f == 10.2109f; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("10.215f == 10.2109f"); + Boolean result = expression.getValue(context, null, Boolean.class); + assertEquals("Equal assertion failed for SPR_9486_floatEqFloatTest Test: ", expectedResult, result); } @Test public void SPR_9486_floatEqDoubleTest() { - try { - Boolean expectedResult = 10.215f == 10.2109; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("10.215f == 10.2109"); - Boolean result = expression.getValue(context, null, Boolean.class); - assertEquals("Equal assertion failed for SPR_9486_floatEqDoubleTest() Test: ", expectedResult, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_floatEqDoubleTest()"); - } + Boolean expectedResult = 10.215f == 10.2109; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("10.215f == 10.2109"); + Boolean result = expression.getValue(context, null, Boolean.class); + assertEquals("Equal assertion failed for SPR_9486_floatEqDoubleTest() Test: ", expectedResult, result); } @Test public void SPR_9486_floatNotEqFloatTest() { - try { - Boolean expectedResult = 10.215f != 10.2109f; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("10.215f != 10.2109f"); - Boolean result = expression.getValue(context, null, Boolean.class); - assertEquals("Equal assertion failed for SPR_9486_floatEqFloatTest Test: ", expectedResult, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_floatEqFloatTest"); - } + Boolean expectedResult = 10.215f != 10.2109f; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("10.215f != 10.2109f"); + Boolean result = expression.getValue(context, null, Boolean.class); + assertEquals("Equal assertion failed for SPR_9486_floatEqFloatTest Test: ", expectedResult, result); } @Test public void SPR_9486_floatNotEqDoubleTest() { - try { - Boolean expectedResult = 10.215f != 10.2109; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("10.215f != 10.2109"); - Boolean result = expression.getValue(context, null, Boolean.class); - assertEquals("Equal assertion failed for SPR_9486_floatNotEqDoubleTest Test: ", expectedResult, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_floatNotEqDoubleTest"); - } + Boolean expectedResult = 10.215f != 10.2109; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("10.215f != 10.2109"); + Boolean result = expression.getValue(context, null, Boolean.class); + assertEquals("Equal assertion failed for SPR_9486_floatNotEqDoubleTest Test: ", expectedResult, result); } @Test public void SPR_9486_floatLessThanFloatTest() { - try { - Boolean expectedNumber = -10.21f < -10.2f; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("-10.21f < -10.2f"); - Boolean result = expression.getValue(context, null, Boolean.class); - assertEquals("Equal assertion failed for SPR_9486_floatLessThanFloatTest Test: ", expectedNumber, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_floatLessThanFloatTest()"); - } + Boolean expectedNumber = -10.21f < -10.2f; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("-10.21f < -10.2f"); + Boolean result = expression.getValue(context, null, Boolean.class); + assertEquals("Equal assertion failed for SPR_9486_floatLessThanFloatTest Test: ", expectedNumber, result); } @Test public void SPR_9486_floatLessThanDoubleTest() { - try { - Boolean expectedNumber = -10.21f < -10.2; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("-10.21f < -10.2"); - Boolean result = expression.getValue(context, null, Boolean.class); - assertEquals("Equal assertion failed for SPR_9486_floatLessThanDoubleTest Test: ", expectedNumber, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_floatLessThanDoubleTest()"); - } + Boolean expectedNumber = -10.21f < -10.2; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("-10.21f < -10.2"); + Boolean result = expression.getValue(context, null, Boolean.class); + assertEquals("Equal assertion failed for SPR_9486_floatLessThanDoubleTest Test: ", expectedNumber, result); } @Test public void SPR_9486_floatLessThanOrEqualFloatTest() { - try { - Boolean expectedNumber = -10.21f <= -10.22f; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("-10.21f <= -10.22f"); - Boolean result = expression.getValue(context, null, Boolean.class); - assertEquals("Equal assertion failed for SPR_9486_floatLessThanOrEqualFloatTest Test: ", expectedNumber, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_floatLessThanOrEqualFloatTest"); - } + Boolean expectedNumber = -10.21f <= -10.22f; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("-10.21f <= -10.22f"); + Boolean result = expression.getValue(context, null, Boolean.class); + assertEquals("Equal assertion failed for SPR_9486_floatLessThanOrEqualFloatTest Test: ", expectedNumber, result); } @Test public void SPR_9486_floatLessThanOrEqualDoubleTest() { - try { - Boolean expectedNumber = -10.21f <= -10.2; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("-10.21f <= -10.2"); - Boolean result = expression.getValue(context, null, Boolean.class); - assertEquals("Equal assertion failed for SPR_9486_floatLessThanOrEqualDoubleTest Test: ", expectedNumber, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_floatLessThanOrEqualDoubleTest"); - } + Boolean expectedNumber = -10.21f <= -10.2; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("-10.21f <= -10.2"); + Boolean result = expression.getValue(context, null, Boolean.class); + assertEquals("Equal assertion failed for SPR_9486_floatLessThanOrEqualDoubleTest Test: ", expectedNumber, result); } @Test public void SPR_9486_floatGreaterThanFloatTest() { - try { - Boolean expectedNumber = -10.21f > -10.2f; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("-10.21f > -10.2f"); - Boolean result = expression.getValue(context, null, Boolean.class); - assertEquals("Equal assertion failed for SPR_9486_floatGreaterThanFloatTest Test: ", expectedNumber, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_floatGreaterThanTest"); - } + Boolean expectedNumber = -10.21f > -10.2f; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("-10.21f > -10.2f"); + Boolean result = expression.getValue(context, null, Boolean.class); + assertEquals("Equal assertion failed for SPR_9486_floatGreaterThanFloatTest Test: ", expectedNumber, result); } @Test public void SPR_9486_floatGreaterThanDoubleTest() { - try { - Boolean expectedResult = -10.21f > -10.2; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("-10.21f > -10.2"); - Boolean result = expression.getValue(context, null, Boolean.class); - assertEquals("Equal assertion failed for SPR_9486_floatGreaterThanDoubleTest Test: ", expectedResult, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_floatGreaterThanTest"); - } + Boolean expectedResult = -10.21f > -10.2; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("-10.21f > -10.2"); + Boolean result = expression.getValue(context, null, Boolean.class); + assertEquals("Equal assertion failed for SPR_9486_floatGreaterThanDoubleTest Test: ", expectedResult, result); } @Test public void SPR_9486_floatGreaterThanOrEqualFloatTest() { - try { - Boolean expectedNumber = -10.21f >= -10.2f; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("-10.21f >= -10.2f"); - Boolean result = expression.getValue(context, null, Boolean.class); - assertEquals("Equal assertion failed for SPR_9486_floatGreaterThanFloatTest Test: ", expectedNumber, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_floatGreaterThanTest"); - } + Boolean expectedNumber = -10.21f >= -10.2f; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("-10.21f >= -10.2f"); + Boolean result = expression.getValue(context, null, Boolean.class); + assertEquals("Equal assertion failed for SPR_9486_floatGreaterThanFloatTest Test: ", expectedNumber, result); } @Test public void SPR_9486_floatGreaterThanEqualDoubleTest() { - try { - Boolean expectedResult = -10.21f >= -10.2; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("-10.21f >= -10.2"); - Boolean result = expression.getValue(context, null, Boolean.class); - assertEquals("Equal assertion failed for SPR_9486_floatGreaterThanDoubleTest Test: ", expectedResult, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_floatGreaterThanTest"); - } + Boolean expectedResult = -10.21f >= -10.2; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("-10.21f >= -10.2"); + Boolean result = expression.getValue(context, null, Boolean.class); + assertEquals("Equal assertion failed for SPR_9486_floatGreaterThanDoubleTest Test: ", expectedResult, result); } @Test public void SPR_9486_floatModulusFloatTest() { - try { - Number expectedResult = 10.21f % 10.2f; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("10.21f % 10.2f"); - Number result = expression.getValue(context, null, Number.class); - assertEquals("Equal assertion failed for SPR_9486_floatModulusFloatTest Test: ", expectedResult, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_floatModulusFloatTest"); - } + Number expectedResult = 10.21f % 10.2f; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("10.21f % 10.2f"); + Number result = expression.getValue(context, null, Number.class); + assertEquals("Equal assertion failed for SPR_9486_floatModulusFloatTest Test: ", expectedResult, result); } @Test public void SPR_9486_floatModulusDoubleTest() { - try { - Number expectedResult = 10.21f % 10.2; - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("10.21f % 10.2"); - Number result = expression.getValue(context, null, Number.class); - assertEquals("Equal assertion failed for SPR_9486_floatModulusDoubleTest Test: ", expectedResult, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_floatModulusDoubleTest"); - } + Number expectedResult = 10.21f % 10.2; + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("10.21f % 10.2"); + Number result = expression.getValue(context, null, Number.class); + assertEquals("Equal assertion failed for SPR_9486_floatModulusDoubleTest Test: ", expectedResult, result); } @Test public void SPR_9486_floatPowerFloatTest() { - try { - Number expectedResult = Math.pow(10.21f, -10.2f); - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("10.21f ^ -10.2f"); - Number result = expression.getValue(context, null, Number.class); - assertEquals("Equal assertion failed for SPR_9486_floatPowerFloatTest Test: ", expectedResult, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_floatPowerFloatTest"); - } + Number expectedResult = Math.pow(10.21f, -10.2f); + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("10.21f ^ -10.2f"); + Number result = expression.getValue(context, null, Number.class); + assertEquals("Equal assertion failed for SPR_9486_floatPowerFloatTest Test: ", expectedResult, result); } @Test public void SPR_9486_floatPowerDoubleTest() { - try { - Number expectedResult = Math.pow(10.21f, 10.2); - ExpressionParser parser = new SpelExpressionParser(); - StandardEvaluationContext context = new StandardEvaluationContext(); - org.springframework.expression.Expression expression = parser.parseExpression("10.21f ^ 10.2"); - Number result = expression.getValue(context, null, Number.class); - assertEquals("Equal assertion failed for SPR_9486_floatPowerDoubleTest Test: ", expectedResult, result); - } catch (Exception e) { - e.printStackTrace(); - fail("Test failed - SPR_9486_floatPowerDoubleTest"); - } + Number expectedResult = Math.pow(10.21f, 10.2); + ExpressionParser parser = new SpelExpressionParser(); + StandardEvaluationContext context = new StandardEvaluationContext(); + org.springframework.expression.Expression expression = parser.parseExpression("10.21f ^ 10.2"); + Number result = expression.getValue(context, null, Number.class); + assertEquals("Equal assertion failed for SPR_9486_floatPowerDoubleTest Test: ", expectedResult, result); } @Test @@ -1877,6 +1782,7 @@ public class SpelReproTests extends ExpressionTestCase { public T getProperty(); } + private static class GenericImplementation implements GenericInterface { @Override @@ -1885,6 +1791,7 @@ public class SpelReproTests extends ExpressionTestCase { } } + static class PackagePrivateClassWithGetter { 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 final String VALUE = "interfaceValue"; } + public abstract static class AbstractStaticFinal implements StaticFinal { } + public static class StaticFinalImpl1 extends AbstractStaticFinal implements StaticFinal { } + public static class StaticFinalImpl2 extends AbstractStaticFinal { } - /** - * The Class TestObject. - */ + public static class SPR10486 { private String name = "name"; @@ -1923,14 +1833,14 @@ public class SpelReproTests extends ExpressionTestCase { public void setName(String name) { this.name = name; } - } + static class SPR11142 { public String isSomething() { return ""; } - } + }