Remove trailing whitespace in source files

find . -type f -name "*.java" -or -name "*.aj" | \
    xargs perl -p -i -e "s/[ \t]*$//g" {} \;

Issue: SPR-10127
This commit is contained in:
Phillip Webb
2012-12-18 13:45:00 -08:00
committed by Chris Beams
parent 44a474a014
commit 1762157ad1
1400 changed files with 5920 additions and 5923 deletions

View File

@@ -22,7 +22,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
/**
* Test construction of arrays.
*
*
* @author Andy Clement
*/
public class ArrayConstructorTests extends ExpressionTestCase {

View File

@@ -34,7 +34,7 @@ import org.springframework.expression.spel.testresources.PlaceOfBirth;
/**
* Tests invocation of constructors.
*
*
* @author Andy Clement
*/
public class ConstructorInvocationTests extends ExpressionTestCase {
@@ -43,22 +43,22 @@ public class ConstructorInvocationTests extends ExpressionTestCase {
public void testTypeConstructors() {
evaluate("new String('hello world')", "hello world", String.class);
}
@Test
public void testNonExistentType() {
evaluateAndCheckError("new FooBar()",SpelMessage.CONSTRUCTOR_INVOCATION_PROBLEM);
}
static class TestException extends Exception {
}
static class Tester {
public static int counter;
public int i;
public Tester() {}
public Tester(int i) throws Exception {
counter++;
if (i==1) {
@@ -72,11 +72,11 @@ public class ConstructorInvocationTests extends ExpressionTestCase {
}
this.i = i;
}
public Tester(PlaceOfBirth pob) {
}
}
@Test
public void testConstructorThrowingException_SPR6760() {
@@ -85,7 +85,7 @@ public class ConstructorInvocationTests extends ExpressionTestCase {
// On 2 it will throw a RuntimeException
// On 3 it will exit normally
// In each case it increments the Tester field 'counter' when invoked
SpelExpressionParser parser = new SpelExpressionParser();
Expression expr = parser.parseExpression("new org.springframework.expression.spel.ConstructorInvocationTests$Tester(#bar).i");
@@ -104,11 +104,11 @@ public class ConstructorInvocationTests extends ExpressionTestCase {
o = expr.getValue(eContext);
Assert.assertEquals(0, o);
// That confirms the logic to mark the cached reference stale and retry is working
// Now let's cause the method to exit via exception and ensure it doesn't cause
// a retry.
// First, switch back to throwException(int)
eContext.setVariable("bar",3);
o = expr.getValue(eContext);
@@ -130,8 +130,8 @@ public class ConstructorInvocationTests extends ExpressionTestCase {
}
// If counter is 4 then the method got called twice!
Assert.assertEquals(3,parser.parseExpression("counter").getValue(eContext));
// 1 will make it throw a RuntimeException - SpEL will let this through
eContext.setVariable("bar",1);
try {
@@ -147,38 +147,38 @@ public class ConstructorInvocationTests extends ExpressionTestCase {
// If counter is 5 then the method got called twice!
Assert.assertEquals(4,parser.parseExpression("counter").getValue(eContext));
}
@Test
public void testAddingConstructorResolvers() {
StandardEvaluationContext ctx = new StandardEvaluationContext();
// reflective constructor accessor is the only one by default
List<ConstructorResolver> constructorResolvers = ctx.getConstructorResolvers();
Assert.assertEquals(1,constructorResolvers.size());
ConstructorResolver dummy = new DummyConstructorResolver();
ctx.addConstructorResolver(dummy);
Assert.assertEquals(2,ctx.getConstructorResolvers().size());
List<ConstructorResolver> copy = new ArrayList<ConstructorResolver>();
copy.addAll(ctx.getConstructorResolvers());
Assert.assertTrue(ctx.removeConstructorResolver(dummy));
Assert.assertFalse(ctx.removeConstructorResolver(dummy));
Assert.assertEquals(1,ctx.getConstructorResolvers().size());
ctx.setConstructorResolvers(copy);
Assert.assertEquals(2,ctx.getConstructorResolvers().size());
}
static class DummyConstructorResolver implements ConstructorResolver {
public ConstructorExecutor resolve(EvaluationContext context, String typeName, List<TypeDescriptor> argumentTypes)
throws AccessException {
throw new UnsupportedOperationException("Auto-generated method stub");
}
}
@Test
public void testVarargsInvocation01() {
// Calling 'Fruit(String... strings)'
@@ -201,7 +201,7 @@ public class ConstructorInvocationTests extends ExpressionTestCase {
evaluate("new org.springframework.expression.spel.testresources.Fruit(2,'a',3.0d).stringscount()", 4, Integer.class);
evaluate("new org.springframework.expression.spel.testresources.Fruit(8,stringArrayOfThreeItems).stringscount()", 11, Integer.class);
}
/*
* These tests are attempting to call constructors where we need to widen or convert the argument in order to
* satisfy a suitable constructor.

View File

@@ -24,7 +24,7 @@ import org.springframework.expression.spel.support.StandardTypeComparator;
/**
* Unit tests for type comparison
*
*
* @author Andy Clement
*/
public class DefaultComparatorUnitTests {
@@ -52,12 +52,12 @@ public class DefaultComparatorUnitTests {
Assert.assertTrue(comparator.compare(1, 2L) < 0);
Assert.assertTrue(comparator.compare(1, 1L) == 0);
Assert.assertTrue(comparator.compare(2, 1L) > 0);
Assert.assertTrue(comparator.compare(1L, 2L) < 0);
Assert.assertTrue(comparator.compare(1L, 1L) == 0);
Assert.assertTrue(comparator.compare(2L, 1L) > 0);
}
@Test
public void testNulls() throws EvaluationException {
TypeComparator comparator = new StandardTypeComparator();
@@ -73,7 +73,7 @@ public class DefaultComparatorUnitTests {
Assert.assertTrue(comparator.compare("a","b")<0);
Assert.assertTrue(comparator.compare("b","a")>0);
}
@Test
public void testCanCompare() throws EvaluationException {
TypeComparator comparator = new StandardTypeComparator();
@@ -85,5 +85,5 @@ public class DefaultComparatorUnitTests {
Assert.assertTrue(comparator.canCompare("abc",3));
Assert.assertFalse(comparator.canCompare(String.class,3));
}
}

View File

@@ -56,7 +56,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
* <li>Adding an advanced (better performing) property resolver
* <li>Adding your own type converter to support conversion between any types you like
* </ul>
*
*
* @author Andy Clement
*/
public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
@@ -75,7 +75,7 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
Object value = expr.getValue();
// They are reusable
value = expr.getValue();
Assert.assertEquals("hello world", value);
Assert.assertEquals(String.class, value.getClass());
} catch (EvaluationException ee) {
@@ -100,7 +100,7 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
List<Integer> primes = new ArrayList<Integer>();
primes.addAll(Arrays.asList(2,3,5,7,11,13,17));
ctx.setVariable("primes",primes);
Expression expr = parser.parseRaw("#favouriteColour");
Object value = expr.getValue(ctx);
Assert.assertEquals("blue", value);
@@ -112,17 +112,17 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
// all prime numbers > 10 from the list (using selection ?{...})
expr = parser.parseRaw("#primes.?[#this>10]");
value = expr.getValue(ctx);
Assert.assertEquals("[11, 13, 17]", value.toString());
Assert.assertEquals("[11, 13, 17]", value.toString());
}
static class TestClass {
public String str;
private int property;
public int getProperty() { return property; }
public void setProperty(int i) { property = i; }
}
/**
* Scenario: using your own root context object
*/
@@ -137,11 +137,11 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
tc.setProperty(42);
tc.str = "wibble";
ctx.setRootObject(tc);
// read it, set it, read it again
Expression expr = parser.parseRaw("str");
Object value = expr.getValue(ctx);
Assert.assertEquals("wibble", value);
Assert.assertEquals("wibble", value);
expr = parser.parseRaw("str");
expr.setValue(ctx, "wobble");
expr = parser.parseRaw("str");
@@ -153,7 +153,7 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
expr = parser.parseRaw("str");
value = expr.getValue(ctx);
Assert.assertEquals("wabble", value);
// private property will be accessed through getter()
expr = parser.parseRaw("property");
value = expr.getValue(ctx);
@@ -166,7 +166,7 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
value = expr.getValue(ctx);
Assert.assertEquals(4,value);
}
public static String repeat(String s) { return s+s; }
/**
@@ -180,7 +180,7 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
// Use the standard evaluation context
StandardEvaluationContext ctx = new StandardEvaluationContext();
ctx.registerFunction("repeat",ExpressionLanguageScenarioTests.class.getDeclaredMethod("repeat",String.class));
Expression expr = parser.parseRaw("#repeat('hello')");
Object value = expr.getValue(ctx);
Assert.assertEquals("hellohello", value);
@@ -193,7 +193,7 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
Assert.fail("Unexpected Exception: " + pe.getMessage());
}
}
/**
* Scenario: add a property resolver that will get called in the resolver chain, this one only supports reading.
*/
@@ -313,6 +313,6 @@ public class ExpressionLanguageScenarioTests extends ExpressionTestCase {
public void write(EvaluationContext context, Object target, String name, Object newValue) throws AccessException {
}
}
}

View File

@@ -33,13 +33,13 @@ import org.springframework.expression.spel.testresources.Inventor;
/**
* Tests for the expression state object - some features are not yet exploited in the language (eg nested scopes)
*
*
* @author Andy Clement
*/
public class ExpressionStateTests extends ExpressionTestCase {
@Test
public void testConstruction() {
public void testConstruction() {
EvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
ExpressionState state = new ExpressionState(context);
Assert.assertEquals(context,state.getEvaluationContext());
@@ -47,14 +47,14 @@ public class ExpressionStateTests extends ExpressionTestCase {
// Local variables are in variable scopes which come and go during evaluation. Normal variables are
// accessible through the evaluation context
@Test
public void testLocalVariables() {
ExpressionState state = getState();
Object value = state.lookupLocalVariable("foo");
Assert.assertNull(value);
state.setLocalVariable("foo",34);
value = state.lookupLocalVariable("foo");
Assert.assertEquals(34,value);
@@ -80,13 +80,13 @@ public class ExpressionStateTests extends ExpressionTestCase {
Assert.assertEquals("abc",typedValue.getValue());
Assert.assertEquals(String.class,typedValue.getTypeDescriptor().getType());
}
@Test
public void testNoVariableInteference() {
ExpressionState state = getState();
TypedValue typedValue = state.lookupVariable("foo");
Assert.assertEquals(TypedValue.NULL,typedValue);
state.setLocalVariable("foo",34);
typedValue = state.lookupVariable("foo");
Assert.assertEquals(TypedValue.NULL,typedValue);
@@ -94,25 +94,25 @@ public class ExpressionStateTests extends ExpressionTestCase {
state.setVariable("goo","hello");
Assert.assertNull(state.lookupLocalVariable("goo"));
}
@Test
public void testLocalVariableNestedScopes() {
ExpressionState state = getState();
Assert.assertEquals(null,state.lookupLocalVariable("foo"));
state.setLocalVariable("foo",12);
Assert.assertEquals(12,state.lookupLocalVariable("foo"));
state.enterScope(null);
Assert.assertEquals(12,state.lookupLocalVariable("foo")); // found in upper scope
state.setLocalVariable("foo","abc");
Assert.assertEquals("abc",state.lookupLocalVariable("foo")); // found in nested scope
state.exitScope();
Assert.assertEquals(12,state.lookupLocalVariable("foo")); // found in nested scope
}
@Test
public void testRootContextObject() {
ExpressionState state = getState();
@@ -122,62 +122,62 @@ public class ExpressionStateTests extends ExpressionTestCase {
((StandardEvaluationContext) state.getEvaluationContext()).setRootObject(null);
Assert.assertEquals(Inventor.class,state.getRootContextObject().getValue().getClass());
// Assert.assertEquals(null, state.getRootContextObject().getValue());
state = new ExpressionState(new StandardEvaluationContext());
Assert.assertEquals(TypedValue.NULL,state.getRootContextObject());
((StandardEvaluationContext)state.getEvaluationContext()).setRootObject(null);
Assert.assertEquals(null,state.getRootContextObject().getValue());
}
@Test
public void testActiveContextObject() {
ExpressionState state = getState();
Assert.assertEquals(state.getRootContextObject().getValue(),state.getActiveContextObject().getValue());
try {
state.popActiveContextObject();
Assert.fail("stack should be empty...");
} catch (EmptyStackException ese) {
// success
}
state.pushActiveContextObject(new TypedValue(34));
Assert.assertEquals(34,state.getActiveContextObject().getValue());
state.pushActiveContextObject(new TypedValue("hello"));
Assert.assertEquals("hello",state.getActiveContextObject().getValue());
state.popActiveContextObject();
Assert.assertEquals(34,state.getActiveContextObject().getValue());
state.popActiveContextObject();
Assert.assertEquals(state.getRootContextObject().getValue(),state.getActiveContextObject().getValue());
state = new ExpressionState(new StandardEvaluationContext());
Assert.assertEquals(TypedValue.NULL,state.getActiveContextObject());
}
@Test
public void testPopulatedNestedScopes() {
ExpressionState state = getState();
Assert.assertNull(state.lookupLocalVariable("foo"));
state.enterScope("foo",34);
Assert.assertEquals(34,state.lookupLocalVariable("foo"));
state.enterScope(null);
state.setLocalVariable("foo",12);
Assert.assertEquals(12,state.lookupLocalVariable("foo"));
state.exitScope();
Assert.assertEquals(34,state.lookupLocalVariable("foo"));
state.exitScope();
Assert.assertNull(state.lookupLocalVariable("goo"));
}
@Test
public void testRootObjectConstructor() {
EvaluationContext ctx = getContext();
@@ -188,21 +188,21 @@ public class ExpressionStateTests extends ExpressionTestCase {
Assert.assertEquals(String.class,stateRoot.getTypeDescriptor().getType());
Assert.assertEquals("i am a string",stateRoot.getValue());
}
@Test
public void testPopulatedNestedScopesMap() {
ExpressionState state = getState();
Assert.assertNull(state.lookupLocalVariable("foo"));
Assert.assertNull(state.lookupLocalVariable("goo"));
Map<String,Object> m = new HashMap<String,Object>();
m.put("foo",34);
m.put("goo","abc");
state.enterScope(m);
Assert.assertEquals(34,state.lookupLocalVariable("foo"));
Assert.assertEquals("abc",state.lookupLocalVariable("goo"));
state.enterScope(null);
state.setLocalVariable("foo",12);
Assert.assertEquals(12,state.lookupLocalVariable("foo"));
@@ -213,7 +213,7 @@ public class ExpressionStateTests extends ExpressionTestCase {
Assert.assertNull(state.lookupLocalVariable("foo"));
Assert.assertNull(state.lookupLocalVariable("goo"));
}
@Test
public void testOperators() throws Exception {
ExpressionState state = getState();
@@ -233,13 +233,13 @@ public class ExpressionStateTests extends ExpressionTestCase {
Assert.assertEquals(SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES,sEx.getMessageCode());
}
}
@Test
public void testComparator() {
ExpressionState state = getState();
Assert.assertEquals(state.getEvaluationContext().getTypeComparator(),state.getTypeComparator());
}
@Test
public void testTypeLocator() throws EvaluationException {
ExpressionState state = getState();
@@ -253,7 +253,7 @@ public class ExpressionStateTests extends ExpressionTestCase {
Assert.assertEquals(SpelMessage.TYPE_NOT_FOUND,sEx.getMessageCode());
}
}
@Test
public void testTypeConversion() throws EvaluationException {
ExpressionState state = getState();
@@ -269,7 +269,7 @@ public class ExpressionStateTests extends ExpressionTestCase {
ExpressionState state = getState();
Assert.assertEquals(state.getEvaluationContext().getPropertyAccessors(),state.getPropertyAccessors());
}
/**
* @return a new ExpressionState
*/
@@ -278,7 +278,7 @@ public class ExpressionStateTests extends ExpressionTestCase {
ExpressionState state = new ExpressionState(context);
return state;
}
private EvaluationContext getContext() {
return TestScenarioCreator.getTestEvaluationContext();
}

View File

@@ -49,7 +49,7 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
private static TypeDescriptor typeDescriptorForListOfString = null;
private static List<Integer> listOfInteger = new ArrayList<Integer>();
private static TypeDescriptor typeDescriptorForListOfInteger = null;
static {
listOfString.add("1");
listOfString.add("2");
@@ -58,21 +58,21 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
listOfInteger.add(5);
listOfInteger.add(6);
}
@Before
public void setUp() throws Exception {
ExpressionTestsUsingCoreConversionService.typeDescriptorForListOfString = new TypeDescriptor(ExpressionTestsUsingCoreConversionService.class.getDeclaredField("listOfString"));
ExpressionTestsUsingCoreConversionService.typeDescriptorForListOfInteger = new TypeDescriptor(ExpressionTestsUsingCoreConversionService.class.getDeclaredField("listOfInteger"));
}
/**
* Test the service can convert what we are about to use in the expression evaluation tests.
*/
@Test
public void testConversionsAvailable() throws Exception {
TypeConvertorUsingConversionService tcs = new TypeConvertorUsingConversionService();
// ArrayList containing List<Integer> to List<String>
Class<?> clazz = typeDescriptorForListOfString.getElementTypeDescriptor().getType();
assertEquals(String.class,clazz);
@@ -82,11 +82,11 @@ public class ExpressionTestsUsingCoreConversionService extends ExpressionTestCas
// ArrayList containing List<String> to List<Integer>
clazz = typeDescriptorForListOfInteger.getElementTypeDescriptor().getType();
assertEquals(Integer.class,clazz);
l = (List) tcs.convertValue(listOfString, TypeDescriptor.forObject(listOfString), typeDescriptorForListOfString);
assertNotNull(l);
}
@Test
public void testSetParameterizedList() throws Exception {
StandardEvaluationContext context = TestScenarioCreator.getTestEvaluationContext();

View File

@@ -38,7 +38,7 @@ public class IndexingTests {
expression = parser.parseExpression("property['foo']");
assertEquals("bar", expression.getValue(this));
}
@FieldAnnotation
public Object property;
@@ -59,7 +59,7 @@ public class IndexingTests {
expression = parser.parseExpression("property['foo']");
assertEquals("bar", expression.getValue(context));
}
public static class MapAccessor implements PropertyAccessor {
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
@@ -83,9 +83,9 @@ public class IndexingTests {
public Class<?>[] getSpecificTargetClasses() {
return new Class[] { Map.class };
}
}
@Test
public void setGenericPropertyContainingMap() {
Map<String, String> property = new HashMap<String, String>();
@@ -97,7 +97,7 @@ public class IndexingTests {
assertEquals(property, expression.getValue(this));
expression = parser.parseExpression("property['foo']");
assertEquals("bar", expression.getValue(this));
expression.setValue(this, "baz");
expression.setValue(this, "baz");
assertEquals("baz", expression.getValue(this));
}
@@ -112,7 +112,7 @@ public class IndexingTests {
assertEquals(property, expression.getValue(this));
expression = parser.parseExpression("parameterizedMap['9']");
assertEquals(3, expression.getValue(this));
expression.setValue(this, "37");
expression.setValue(this, "37");
assertEquals(37, expression.getValue(this));
}
@@ -126,10 +126,10 @@ public class IndexingTests {
assertEquals(property, expression.getValue(this));
expression = parser.parseExpression("parameterizedMap['9']");
assertEquals(null, expression.getValue(this));
expression.setValue(this, "37");
expression.setValue(this, "37");
assertEquals(37, expression.getValue(this));
}
@Test
public void indexIntoGenericPropertyContainingList() {
List<String> property = new ArrayList<String>();
@@ -142,7 +142,7 @@ public class IndexingTests {
expression = parser.parseExpression("property[0]");
assertEquals("bar", expression.getValue(this));
}
@Test
public void setGenericPropertyContainingList() {
List<Integer> property = new ArrayList<Integer>();
@@ -170,10 +170,10 @@ public class IndexingTests {
try {
expression.setValue(this, "4");
} catch (EvaluationException e) {
assertTrue(e.getMessage().startsWith("EL1053E"));
assertTrue(e.getMessage().startsWith("EL1053E"));
}
}
@Test
public void indexIntoPropertyContainingList() {
List<Integer> property = new ArrayList<Integer>();
@@ -186,7 +186,7 @@ public class IndexingTests {
expression = parser.parseExpression("parameterizedList[0]");
assertEquals(3, expression.getValue(this));
}
public List<Integer> parameterizedList;
@Test
@@ -201,9 +201,9 @@ public class IndexingTests {
expression = parser.parseExpression("parameterizedListOfList[0][0]");
assertEquals(3, expression.getValue(this));
}
public List<List<Integer>> parameterizedListOfList;
@Test
public void setPropertyContainingList() {
List<Integer> property = new ArrayList<Integer>();
@@ -218,7 +218,7 @@ public class IndexingTests {
expression.setValue(this, "4");
assertEquals(4, expression.getValue(this));
}
@Test
public void indexIntoGenericPropertyContainingNullList() {
SpelParserConfiguration configuration = new SpelParserConfiguration(true, true);
@@ -230,7 +230,7 @@ public class IndexingTests {
try {
assertEquals("bar", expression.getValue(this));
} catch (EvaluationException e) {
assertTrue(e.getMessage().startsWith("EL1027E"));
assertTrue(e.getMessage().startsWith("EL1027E"));
}
}
@@ -267,7 +267,7 @@ public class IndexingTests {
assertTrue(e.getMessage().startsWith("EL1053E"));
}
}
public List property2;
@Test
@@ -281,7 +281,7 @@ public class IndexingTests {
expression = parser.parseExpression("property[0]");
assertEquals("bar", expression.getValue(this));
}
@Test
public void emptyList() {
listOfScalarNotGeneric = new ArrayList();
@@ -315,7 +315,7 @@ public class IndexingTests {
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface FieldAnnotation {
}
@Test
@@ -327,7 +327,7 @@ public class IndexingTests {
Expression expression = parser.parseExpression("mapNotGeneric");
assertEquals("@org.springframework.expression.spel.IndexingTests$FieldAnnotation java.util.HashMap<?, ?>", expression.getValueTypeDescriptor(this).toString());
}
@FieldAnnotation
public Map mapNotGeneric;
@@ -339,10 +339,10 @@ public class IndexingTests {
Expression expression = parser.parseExpression("listOfScalarNotGeneric[0]");
assertEquals(new Integer(5), expression.getValue(this, Integer.class));
}
public List listOfScalarNotGeneric;
@Test
public void testListsOfMap() {
listOfMapsNotGeneric = new ArrayList();
@@ -353,7 +353,7 @@ public class IndexingTests {
Expression expression = parser.parseExpression("listOfMapsNotGeneric[0]['fruit']");
assertEquals("apple", expression.getValue(this, String.class));
}
public List listOfMapsNotGeneric;
}

View File

@@ -26,7 +26,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
/**
* Test usage of inline lists.
*
*
* @author Andy Clement
* @since 3.0.4
*/

View File

@@ -46,7 +46,7 @@ public class LiteralExpressionTests {
Assert.assertFalse(lEx.isWritable(new Rooty()));
Assert.assertFalse(lEx.isWritable(new StandardEvaluationContext(), new Rooty()));
}
static class Rooty {}
@Test

View File

@@ -23,7 +23,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
/**
* Tests the evaluation of basic literals: boolean, integer, hex integer, long, real, null, date
*
*
* @author Andy Clement
*/
public class LiteralTests extends ExpressionTestCase {
@@ -159,7 +159,7 @@ public class LiteralTests extends ExpressionTestCase {
evaluate("new Integer(37).byteValue()", (byte) 37, Byte.class); // calling byteValue() on Integer.class
evaluateAndAskForReturnType("new Integer(37)", (byte) 37, Byte.class); // relying on registered type converters
}
@Test
public void testNotWritable() throws Exception {
SpelExpression expr = (SpelExpression)parser.parseExpression("37");

View File

@@ -33,7 +33,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
/**
* Testing variations on map access.
*
*
* @author Andy Clement
*/
public class MapAccessTests extends ExpressionTestCase {
@@ -170,7 +170,7 @@ public class MapAccessTests extends ExpressionTestCase {
public Class<?>[] getSpecificTargetClasses() {
return new Class[] { Map.class };
}
}
}

View File

@@ -27,7 +27,7 @@ import org.springframework.expression.spel.standard.SpelExpression;
/**
* Test providing operator support
*
*
* @author Andy Clement
*/
public class OperatorOverloaderTests extends ExpressionTestCase {
@@ -48,11 +48,11 @@ public class OperatorOverloaderTests extends ExpressionTestCase {
return true;
}
return false;
}
}
@Test
public void testSimpleOperations() throws Exception {
// no built in support for this:
@@ -66,7 +66,7 @@ public class OperatorOverloaderTests extends ExpressionTestCase {
expr = (SpelExpression)parser.parseExpression("'abc'-true");
Assert.assertEquals("abc",expr.getValue(eContext));
expr = (SpelExpression)parser.parseExpression("'abc'+null");
Assert.assertEquals("abcnull",expr.getValue(eContext));
}

View File

@@ -23,7 +23,7 @@ import org.springframework.expression.spel.standard.SpelExpression;
/**
* Tests the evaluation of expressions using relational operators.
*
*
* @author Andy Clement
*/
public class OperatorTests extends ExpressionTestCase {
@@ -124,7 +124,7 @@ public class OperatorTests extends ExpressionTestCase {
public void testGreaterThanOrEqual() {
evaluate("3 >= 5", false, Boolean.class);
evaluate("5 >= 3", true, Boolean.class);
evaluate("6 >= 6", true, Boolean.class);
evaluate("6 >= 6", true, Boolean.class);
evaluate("3L >= 5L", false, Boolean.class);
evaluate("5L >= 3L", true, Boolean.class);
evaluate("5L >= 5L", true, Boolean.class);
@@ -137,14 +137,14 @@ public class OperatorTests extends ExpressionTestCase {
evaluate("3 GE 5", false, Boolean.class);
evaluate("5 gE 3", true, Boolean.class);
evaluate("6 Ge 6", true, Boolean.class);
evaluate("6 Ge 6", true, Boolean.class);
evaluate("3L ge 5L", false, Boolean.class);
}
@Test
public void testGreaterThan() {
evaluate("3 > 5", false, Boolean.class);
evaluate("5 > 3", true, Boolean.class);
evaluate("5 > 3", true, Boolean.class);
evaluate("3L > 5L", false, Boolean.class);
evaluate("5L > 3L", true, Boolean.class);
evaluate("3.0d > 5.0d", false, Boolean.class);
@@ -172,7 +172,7 @@ public class OperatorTests extends ExpressionTestCase {
public void testMathOperatorAdd02() {
evaluate("'hello' + ' ' + 'world'", "hello world", String.class);
}
@Test
public void testMathOperatorsInChains() {
evaluate("1+2+3",6,Integer.class);
@@ -194,7 +194,7 @@ public class OperatorTests extends ExpressionTestCase {
evaluate("3 Mod 2", 1, Integer.class);
evaluate("3 MOD 2", 1, Integer.class);
}
@Test
public void testPlus() throws Exception {
evaluate("7 + 2", "9", Integer.class);
@@ -205,26 +205,26 @@ public class OperatorTests extends ExpressionTestCase {
evaluate("2 + 'a'", "2a", String.class);
evaluate("'ab' + null", "abnull", String.class);
evaluate("null + 'ab'", "nullab", String.class);
// AST:
SpelExpression expr = (SpelExpression)parser.parseExpression("+3");
Assert.assertEquals("+3",expr.toStringAST());
expr = (SpelExpression)parser.parseExpression("2+3");
Assert.assertEquals("(2 + 3)",expr.toStringAST());
// use as a unary operator
evaluate("+5d",5d,Double.class);
evaluate("+5L",5L,Long.class);
evaluate("+5",5,Integer.class);
evaluateAndCheckError("+'abc'",SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
// string concatenation
evaluate("'abc'+'def'","abcdef",String.class);
//
//
evaluate("5 + new Integer('37')",42,Integer.class);
}
@Test
public void testMinus() throws Exception {
evaluate("'c' - 2", "a", String.class);
@@ -235,13 +235,13 @@ public class OperatorTests extends ExpressionTestCase {
Assert.assertEquals("-3",expr.toStringAST());
expr = (SpelExpression)parser.parseExpression("2-3");
Assert.assertEquals("(2 - 3)",expr.toStringAST());
evaluate("-5d",-5d,Double.class);
evaluate("-5L",-5L,Long.class);
evaluate("-5",-5,Integer.class);
evaluateAndCheckError("-'abc'",SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
}
@Test
public void testModulus() {
evaluate("3%2",1,Integer.class);
@@ -259,7 +259,7 @@ public class OperatorTests extends ExpressionTestCase {
evaluate("4L DIV 2L",2L,Long.class);
evaluateAndCheckError("'abc'/'def'",SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
}
@Test
public void testMathOperatorDivide_ConvertToDouble() {
evaluateAndAskForReturnType("8/4", new Double(2.0), Double.class);
@@ -282,7 +282,7 @@ public class OperatorTests extends ExpressionTestCase {
evaluate("3.0d / 5.0d", 0.6d, Double.class);
evaluate("6.0d % 3.5d", 2.5d, Double.class);
}
@Test
public void testOperatorNames() throws Exception {
Operator node = getOperatorNode((SpelExpression)parser.parseExpression("1==3"));
@@ -290,13 +290,13 @@ public class OperatorTests extends ExpressionTestCase {
node = getOperatorNode((SpelExpression)parser.parseExpression("1!=3"));
Assert.assertEquals("!=",node.getOperatorName());
node = getOperatorNode((SpelExpression)parser.parseExpression("3/3"));
Assert.assertEquals("/",node.getOperatorName());
node = getOperatorNode((SpelExpression)parser.parseExpression("3+3"));
Assert.assertEquals("+",node.getOperatorName());
node = getOperatorNode((SpelExpression)parser.parseExpression("3-3"));
Assert.assertEquals("-",node.getOperatorName());
@@ -305,29 +305,29 @@ public class OperatorTests extends ExpressionTestCase {
node = getOperatorNode((SpelExpression)parser.parseExpression("3<=4"));
Assert.assertEquals("<=",node.getOperatorName());
node = getOperatorNode((SpelExpression)parser.parseExpression("3*4"));
Assert.assertEquals("*",node.getOperatorName());
node = getOperatorNode((SpelExpression)parser.parseExpression("3%4"));
Assert.assertEquals("%",node.getOperatorName());
node = getOperatorNode((SpelExpression)parser.parseExpression("3>=4"));
Assert.assertEquals(">=",node.getOperatorName());
node = getOperatorNode((SpelExpression)parser.parseExpression("3 between 4"));
Assert.assertEquals("between",node.getOperatorName());
node = getOperatorNode((SpelExpression)parser.parseExpression("3 ^ 4"));
Assert.assertEquals("^",node.getOperatorName());
}
@Test
public void testOperatorOverloading() {
evaluateAndCheckError("'a' * '2'", SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
evaluateAndCheckError("'a' ^ '2'", SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES);
}
@Test
public void testPower() {
evaluate("3^2",9,Integer.class);
@@ -335,16 +335,16 @@ public class OperatorTests extends ExpressionTestCase {
evaluate("3L^2L",9L,Long.class);
evaluate("(2^32)^2",9223372036854775807L,Long.class);
}
@Test
public void testMixedOperands_FloatsAndDoubles() {
evaluate("3.0d + 5.0f", 8.0d, Double.class);
evaluate("3.0D - 5.0f", -2.0d, Double.class);
evaluate("3.0f * 5.0d", 15.0d, Double.class);
evaluate("3.0f / 5.0D", 0.6d, Double.class);
evaluate("5.0D % 3f", 2.0d, Double.class);
evaluate("5.0D % 3f", 2.0d, Double.class);
}
@Test
public void testMixedOperands_DoublesAndInts() {
evaluate("3.0d + 5", 8.0d, Double.class);
@@ -352,10 +352,10 @@ public class OperatorTests extends ExpressionTestCase {
evaluate("3.0f * 5", 15.0f, Float.class);
evaluate("6.0f / 2", 3.0f, Float.class);
evaluate("6.0f / 4", 1.5f, Float.class);
evaluate("5.0D % 3", 2.0d, Double.class);
evaluate("5.5D % 3", 2.5, Double.class);
evaluate("5.0D % 3", 2.0d, Double.class);
evaluate("5.5D % 3", 2.5, Double.class);
}
@Test
public void testStrings() {
evaluate("'abc' == 'abc'",true,Boolean.class);
@@ -363,7 +363,7 @@ public class OperatorTests extends ExpressionTestCase {
evaluate("'abc' != 'abc'",false,Boolean.class);
evaluate("'abc' != 'def'",true,Boolean.class);
}
@Test
public void testLongs() {
evaluate("3L == 4L", false, Boolean.class);
@@ -374,14 +374,14 @@ public class OperatorTests extends ExpressionTestCase {
evaluate("3L + 50L", 53L, Long.class);
evaluate("3L - 50L", -47L, Long.class);
}
// ---
private Operator getOperatorNode(SpelExpression e) {
SpelNode node = e.getAST();
return (Operator)findNode(node,Operator.class);
}
private SpelNode findNode(SpelNode node, Class<Operator> clazz) {
if (clazz.isAssignableFrom(node.getClass())) {
return node;
@@ -395,5 +395,5 @@ public class OperatorTests extends ExpressionTestCase {
}
return null;
}
}

View File

@@ -26,7 +26,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
/**
* Parse some expressions and check we get the AST we expect. Rather than inspecting each node in the AST, we ask it to
* write itself to a string form and check that is as expected.
*
*
* @author Andy Clement
*/
public class ParsingTests {
@@ -160,7 +160,7 @@ public class ParsingTests {
public void testElvis() {
parseCheck("3?:1", "3 ?: 1");
}
// public void testRelOperatorsIn01() {
// parseCheck("3 in {1,2,3,4,5}", "(3 in {1,2,3,4,5})");
// }
@@ -399,14 +399,14 @@ public class ParsingTests {
parseCheck("#var1='value1'");
}
// ternary operator
@Test
public void testTernaryOperator01() {
parseCheck("1>2?3:4","(1 > 2) ? 3 : 4");
}
// public void testTernaryOperator01() {
// parseCheck("{1}.#isEven(#this) == 'y'?'it is even':'it is odd'",
// "({1}.#isEven(#this) == 'y') ? 'it is even' : 'it is odd'");
@@ -432,16 +432,16 @@ public class ParsingTests {
public void testTypeReferences02() {
parseCheck("T(String)");
}
@Test
public void testInlineList1() {
parseCheck("{1,2,3,4}");
}
/**
* Parse the supplied expression and then create a string representation of the resultant AST, it should be the same
* as the original expression.
*
*
* @param expression the expression to parse *and* the expected value of the string form of the resultant AST
*/
public void parseCheck(String expression) {
@@ -451,7 +451,7 @@ public class ParsingTests {
/**
* Parse the supplied expression and then create a string representation of the resultant AST, it should be the
* expected value.
*
*
* @param expression the expression to parse
* @param expectedStringFormOfAST the expected string form of the AST
*/

View File

@@ -28,7 +28,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
/**
* Tests the evaluation of real expressions in a real context.
*
*
* @author Andy Clement
*/
public class PerformanceTests {
@@ -40,7 +40,7 @@ public class PerformanceTests {
private static EvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
private static final boolean DEBUG = false;
@Test
public void testPerformanceOfPropertyAccess() throws Exception {
long starttime = 0;
@@ -54,7 +54,7 @@ public class PerformanceTests {
}
expr.getValue(eContext);
}
starttime = System.currentTimeMillis();
for (int i = 0; i < ITERATIONS; i++) {
Expression expr = parser.parseExpression("placeOfBirth.city");
@@ -92,7 +92,7 @@ public class PerformanceTests {
public void testPerformanceOfMethodAccess() throws Exception {
long starttime = 0;
long endtime = 0;
// warmup
for (int i = 0; i < ITERATIONS; i++) {
Expression expr = parser.parseExpression("getPlaceOfBirth().getCity()");

View File

@@ -40,7 +40,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
///CLOVER:OFF
/**
* Spring Security scenarios from https://wiki.springsource.com/display/SECURITY/Spring+Security+Expression-based+Authorization
*
*
* @author Andy Clement
*/
public class ScenariosForSpringSecurity extends ExpressionTestCase {
@@ -55,7 +55,7 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
ctx.setRootObject(new Person("Ben"));
Boolean value = expr.getValue(ctx,Boolean.class);
Assert.assertFalse(value);
ctx.setRootObject(new Manager("Luke"));
value = expr.getValue(ctx,Boolean.class);
Assert.assertTrue(value);
@@ -72,7 +72,7 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
StandardEvaluationContext ctx = new StandardEvaluationContext();
ctx.addPropertyAccessor(new SecurityPrincipalAccessor());
// Multiple options for supporting this expression: "p.name == principal.name"
// (1) If the right person is the root context object then "name==principal.name" is good enough
Expression expr = parser.parseRaw("name == principal.name");
@@ -80,22 +80,22 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
ctx.setRootObject(new Person("Andy"));
Boolean value = expr.getValue(ctx,Boolean.class);
Assert.assertTrue(value);
ctx.setRootObject(new Person("Christian"));
value = expr.getValue(ctx,Boolean.class);
Assert.assertFalse(value);
// (2) Or register an accessor that can understand 'p' and return the right person
expr = parser.parseRaw("p.name == principal.name");
PersonAccessor pAccessor = new PersonAccessor();
ctx.addPropertyAccessor(pAccessor);
ctx.setRootObject(null);
pAccessor.setPerson(new Person("Andy"));
value = expr.getValue(ctx,Boolean.class);
Assert.assertTrue(value);
pAccessor.setPerson(new Person("Christian"));
value = expr.getValue(ctx,Boolean.class);
Assert.assertFalse(value);
@@ -105,18 +105,18 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
public void testScenario03_Arithmetic() throws Exception {
SpelExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext ctx = new StandardEvaluationContext();
// Might be better with a as a variable although it would work as a property too...
// Variable references using a '#'
Expression expr = parser.parseRaw("(hasRole('SUPERVISOR') or (#a < 1.042)) and hasIpAddress('10.10.0.0/16')");
Boolean value = null;
ctx.setVariable("a",1.0d); // referenced as #a in the expression
ctx.setRootObject(new Supervisor("Ben")); // so non-qualified references 'hasRole()' 'hasIpAddress()' are invoked against it
value = expr.getValue(ctx,Boolean.class);
Assert.assertTrue(value);
ctx.setRootObject(new Manager("Luke"));
ctx.setVariable("a",1.043d);
value = expr.getValue(ctx,Boolean.class);
@@ -128,7 +128,7 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
public void testScenario04_ControllingWhichMethodsRun() throws Exception {
SpelExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext ctx = new StandardEvaluationContext();
ctx.setRootObject(new Supervisor("Ben")); // so non-qualified references 'hasRole()' 'hasIpAddress()' are invoked against it);
ctx.addMethodResolver(new MyMethodResolver()); // NEEDS TO OVERRIDE THE REFLECTION ONE - SHOW REORDERING MECHANISM
@@ -138,17 +138,17 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
Expression expr = parser.parseRaw("(hasRole(3) or (#a < 1.042)) and hasIpAddress('10.10.0.0/16')");
Boolean value = null;
ctx.setVariable("a",1.0d); // referenced as #a in the expression
value = expr.getValue(ctx,Boolean.class);
Assert.assertTrue(value);
// ctx.setRootObject(new Manager("Luke"));
// ctx.setVariable("a",1.043d);
// value = (Boolean)expr.getValue(ctx,Boolean.class);
// assertFalse(value);
}
static class Person {
@@ -236,7 +236,7 @@ public class ScenariosForSpringSecurity extends ExpressionTestCase {
public Class<?>[] getSpecificTargetClasses() {
return null;
}
}

View File

@@ -31,7 +31,7 @@ import org.springframework.expression.spel.testresources.PlaceOfBirth;
/**
* Tests set value expressions.
*
*
* @author Keith Donald
* @author Andy Clement
*/
@@ -43,7 +43,7 @@ public class SetValueTests extends ExpressionTestCase {
public void testSetProperty() {
setValue("wonNobelPrize", true);
}
@Test
public void testSetNestedProperty() {
setValue("placeOfBirth.city", "Wien");
@@ -89,17 +89,17 @@ public class SetValueTests extends ExpressionTestCase {
setValueExpectError("arrayContainer.bytes[1]", "NaB");
setValueExpectError("arrayContainer.chars[1]", "NaC");
}
@Test
public void testSetArrayElementNestedValue() {
setValue("placesLived[0].city", "Wien");
}
@Test
public void testSetListElementValue() {
setValue("placesLivedList[0]", new PlaceOfBirth("Wien"));
}
@Test
public void testSetGenericListElementValueTypeCoersion() {
// TODO currently failing since setValue does a getValue and "Wien" string != PlaceOfBirth - check with andy
@@ -110,7 +110,7 @@ public class SetValueTests extends ExpressionTestCase {
public void testSetGenericListElementValueTypeCoersionOK() {
setValue("booleanList[0]", "true", Boolean.TRUE);
}
@Test
public void testSetListElementNestedValue() {
setValue("placesLived[0].city", "Wien");
@@ -121,17 +121,17 @@ public class SetValueTests extends ExpressionTestCase {
setValueExpectError("placesLived[23]", "Wien");
setValueExpectError("placesLivedList[23]", "Wien");
}
@Test
public void testSetMapElements() {
setValue("testMap['montag']","lundi");
}
@Test
public void testIndexingIntoUnsupportedType() {
setValueExpectError("'hello'[3]", 'p');
}
@Test
public void testSetPropertyTypeCoersion() {
setValue("publicBoolean", "true", Boolean.TRUE);
@@ -141,9 +141,9 @@ public class SetValueTests extends ExpressionTestCase {
public void testSetPropertyTypeCoersionThroughSetter() {
setValue("SomeProperty", "true", Boolean.TRUE);
}
@Test
public void testAssign() throws Exception {
public void testAssign() throws Exception {
StandardEvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
Expression e = parse("publicName='Andy'");
Assert.assertFalse(e.isWritable(eContext));
@@ -158,32 +158,32 @@ public class SetValueTests extends ExpressionTestCase {
StandardEvaluationContext eContext = TestScenarioCreator.getTestEvaluationContext();
Expression e = parse("mapOfStringToBoolean[42]");
Assert.assertNull(e.getValue(eContext));
// Key should be coerced to string representation of 42
e.setValue(eContext, "true");
// All keys should be strings
Set ks = parse("mapOfStringToBoolean.keySet()").getValue(eContext,Set.class);
for (Object o: ks) {
Assert.assertEquals(String.class,o.getClass());
}
// All values should be booleans
Collection vs = parse("mapOfStringToBoolean.values()").getValue(eContext,Collection.class);
for (Object o: vs) {
Assert.assertEquals(Boolean.class,o.getClass());
}
// One final test check coercion on the key for a map lookup
Object o = e.getValue(eContext);
Assert.assertEquals(Boolean.TRUE,o);
}
private Expression parse(String expressionString) throws Exception {
return parser.parseExpression(expressionString);
}
/**
* Call setValue() but expect it to fail.
*/

View File

@@ -38,17 +38,17 @@ import org.springframework.expression.spel.testresources.PlaceOfBirth;
/**
* Test the examples specified in the documentation.
*
*
* NOTE: any outgoing changes from this file upon synchronizing with the repo may indicate that
* you need to update the documentation too !
*
*
* @author Andy Clement
*/
public class SpelDocumentationTests extends ExpressionTestCase {
static Inventor tesla ;
static Inventor pupin ;
static {
GregorianCalendar c = new GregorianCalendar();
c.set(1856, 7, 9);
@@ -60,18 +60,18 @@ public class SpelDocumentationTests extends ExpressionTestCase {
pupin = new Inventor("Pupin", c.getTime(), "Idvor");
pupin.setPlaceOfBirth(new PlaceOfBirth("Idvor"));
}
static class IEEE {
private String name;
public Inventor[] Members = new Inventor[1];
public List Members2 = new ArrayList();
public Map<String,Object> officers = new HashMap<String,Object>();
public List<Map<String, Object>> reverse = new ArrayList<Map<String, Object>>();
@SuppressWarnings("unchecked")
IEEE() {
officers.put("president",pupin);
@@ -80,28 +80,28 @@ public class SpelDocumentationTests extends ExpressionTestCase {
officers.put("advisors",linv);
Members2.add(tesla);
Members2.add(pupin);
reverse.add(officers);
}
public boolean isMember(String name) {
return true;
}
public String getName() { return name; }
public void setName(String n) { this.name = n; }
}
@Test
public void testMethodInvocation() {
evaluate("'Hello World'.concat('!')","Hello World!",String.class);
}
@Test
public void testBeanPropertyAccess() {
evaluate("new String('Hello World'.bytes)","Hello World",String.class);
}
@Test
public void testArrayLengthAccess() {
evaluate("'Hello World'.bytes.length",11,Integer.class);
@@ -123,12 +123,12 @@ public class SpelDocumentationTests extends ExpressionTestCase {
String name = (String) exp.getValue(context);
Assert.assertEquals("Nikola Tesla",name);
}
}
@Test
public void testEqualityCheck() throws Exception {
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
context.setRootObject(tesla);
@@ -136,14 +136,14 @@ public class SpelDocumentationTests extends ExpressionTestCase {
boolean isEqual = exp.getValue(context, Boolean.class); // evaluates to true
Assert.assertTrue(isEqual);
}
// Section 7.4.1
@Test
public void testXMLBasedConfig() {
evaluate("(T(java.lang.Math).random() * 100.0 )>0",true,Boolean.class);
}
// Section 7.5
@Test
public void testLiterals() throws Exception {
@@ -151,16 +151,16 @@ public class SpelDocumentationTests extends ExpressionTestCase {
String helloWorld = (String) parser.parseExpression("'Hello World'").getValue(); // evals to "Hello World"
Assert.assertEquals("Hello World",helloWorld);
double avogadrosNumber = (Double) parser.parseExpression("6.0221415E+23").getValue();
double avogadrosNumber = (Double) parser.parseExpression("6.0221415E+23").getValue();
Assert.assertEquals(6.0221415E+23,avogadrosNumber);
int maxValue = (Integer) parser.parseExpression("0x7FFFFFFF").getValue(); // evals to 2147483647
Assert.assertEquals(Integer.MAX_VALUE,maxValue);
boolean trueValue = (Boolean) parser.parseExpression("true").getValue();
Assert.assertTrue(trueValue);
Object nullValue = parser.parseExpression("null").getValue();
Assert.assertNull(nullValue);
}
@@ -170,11 +170,11 @@ public class SpelDocumentationTests extends ExpressionTestCase {
EvaluationContext context = TestScenarioCreator.getTestEvaluationContext();
int year = (Integer) parser.parseExpression("Birthdate.Year + 1900").getValue(context); // 1856
Assert.assertEquals(1856,year);
String city = (String) parser.parseExpression("placeOfBirth.City").getValue(context);
Assert.assertEquals("SmilJan",city);
}
@Test
public void testPropertyNavigation() throws Exception {
ExpressionParser parser = new SpelExpressionParser();
@@ -184,7 +184,7 @@ public class SpelDocumentationTests extends ExpressionTestCase {
// teslaContext.setRootObject(tesla);
// evaluates to "Induction motor"
String invention = parser.parseExpression("inventions[3]").getValue(teslaContext, String.class);
String invention = parser.parseExpression("inventions[3]").getValue(teslaContext, String.class);
Assert.assertEquals("Induction motor",invention);
// Members List
@@ -196,14 +196,14 @@ public class SpelDocumentationTests extends ExpressionTestCase {
// evaluates to "Nikola Tesla"
String name = parser.parseExpression("Members[0].Name").getValue(societyContext, String.class);
Assert.assertEquals("Nikola Tesla",name);
// List and Array navigation
// evaluates to "Wireless communication"
invention = parser.parseExpression("Members[0].Inventions[6]").getValue(societyContext, String.class);
Assert.assertEquals("Wireless communication",invention);
}
@Test
public void testDictionaryAccess() throws Exception {
StandardEvaluationContext societyContext = new StandardEvaluationContext();
@@ -217,14 +217,14 @@ public class SpelDocumentationTests extends ExpressionTestCase {
// setting values
Inventor i = parser.parseExpression("officers['advisors'][0]").getValue(societyContext,Inventor.class);
Assert.assertEquals("Nikola Tesla",i.getName());
parser.parseExpression("officers['advisors'][0].PlaceOfBirth.Country").setValue(societyContext, "Croatia");
Inventor i2 = parser.parseExpression("reverse[0]['advisors'][0]").getValue(societyContext,Inventor.class);
Assert.assertEquals("Nikola Tesla",i2.getName());
}
// 7.5.3
@Test
@@ -232,16 +232,16 @@ public class SpelDocumentationTests extends ExpressionTestCase {
// string literal, evaluates to "bc"
String c = parser.parseExpression("'abc'.substring(1, 3)").getValue(String.class);
Assert.assertEquals("bc",c);
StandardEvaluationContext societyContext = new StandardEvaluationContext();
societyContext.setRootObject(new IEEE());
// evaluates to true
boolean isMember = parser.parseExpression("isMember('Mihajlo Pupin')").getValue(societyContext, Boolean.class);
Assert.assertTrue(isMember);
}
// 7.5.4.1
@Test
public void testRelationalOperators() throws Exception {
boolean result = parser.parseExpression("2 == 2").getValue(Boolean.class);
@@ -249,18 +249,18 @@ public class SpelDocumentationTests extends ExpressionTestCase {
// evaluates to false
result = parser.parseExpression("2 < -5.0").getValue(Boolean.class);
Assert.assertFalse(result);
// evaluates to true
result = parser.parseExpression("'black' < 'block'").getValue(Boolean.class);
Assert.assertTrue(result);
}
@Test
public void testOtherOperators() throws Exception {
// evaluates to false
boolean falseValue = parser.parseExpression("'xyz' instanceof T(int)").getValue(Boolean.class);
Assert.assertFalse(falseValue);
// evaluates to true
boolean trueValue = parser.parseExpression("'5.00' matches '^-?\\d+(\\.\\d{2})?$'").getValue(Boolean.class);
Assert.assertTrue(trueValue);
@@ -269,15 +269,15 @@ public class SpelDocumentationTests extends ExpressionTestCase {
falseValue = parser.parseExpression("'5.0067' matches '^-?\\d+(\\.\\d{2})?$'").getValue(Boolean.class);
Assert.assertFalse(falseValue);
}
// 7.5.4.2
@Test
public void testLogicalOperators() throws Exception {
StandardEvaluationContext societyContext = new StandardEvaluationContext();
societyContext.setRootObject(new IEEE());
// -- AND --
// evaluates to false
@@ -292,12 +292,12 @@ public class SpelDocumentationTests extends ExpressionTestCase {
// evaluates to true
trueValue = parser.parseExpression("true or false").getValue(Boolean.class);
Assert.assertTrue(trueValue);
// evaluates to true
expression = "isMember('Nikola Tesla') or isMember('Albert Einstien')";
trueValue = parser.parseExpression(expression).getValue(societyContext, Boolean.class);
Assert.assertTrue(trueValue);
// -- NOT --
// evaluates to false
@@ -310,56 +310,56 @@ public class SpelDocumentationTests extends ExpressionTestCase {
falseValue = parser.parseExpression(expression).getValue(societyContext, Boolean.class);
Assert.assertFalse(falseValue);
}
// 7.5.4.3
@Test
public void testNumericalOperators() throws Exception {
// Addition
int two = parser.parseExpression("1 + 1").getValue(Integer.class); // 2
Assert.assertEquals(2,two);
String testString = parser.parseExpression("'test' + ' ' + 'string'").getValue(String.class); // 'test string'
Assert.assertEquals("test string",testString);
// Subtraction
int four = parser.parseExpression("1 - -3").getValue(Integer.class); // 4
Assert.assertEquals(4,four);
double d = parser.parseExpression("1000.00 - 1e4").getValue(Double.class); // -9000
Assert.assertEquals(-9000.0d,d);
// Multiplication
int six = parser.parseExpression("-2 * -3").getValue(Integer.class); // 6
Assert.assertEquals(6,six);
double twentyFour = parser.parseExpression("2.0 * 3e0 * 4").getValue(Double.class); // 24.0
Assert.assertEquals(24.0d,twentyFour);
// Division
int minusTwo = parser.parseExpression("6 / -3").getValue(Integer.class); // -2
Assert.assertEquals(-2,minusTwo);
double one = parser.parseExpression("8.0 / 4e0 / 2").getValue(Double.class); // 1.0
Assert.assertEquals(1.0d,one);
// Modulus
int three = parser.parseExpression("7 % 4").getValue(Integer.class); // 3
Assert.assertEquals(3,three);
int oneInt = parser.parseExpression("8 / 5 % 2").getValue(Integer.class); // 1
Assert.assertEquals(1,oneInt);
// Operator precedence
int minusTwentyOne = parser.parseExpression("1+2-3*8").getValue(Integer.class); // -21
Assert.assertEquals(-21,minusTwentyOne);
}
// 7.5.5
@Test
public void testAssignment() throws Exception {
Inventor inventor = new Inventor();
Inventor inventor = new Inventor();
StandardEvaluationContext inventorContext = new StandardEvaluationContext();
inventorContext.setRootObject(inventor);
@@ -372,9 +372,9 @@ public class SpelDocumentationTests extends ExpressionTestCase {
Assert.assertEquals("Alexandar Seovic",parser.parseExpression("foo").getValue(inventorContext,String.class));
Assert.assertEquals("Alexandar Seovic",aleks);
}
// 7.5.6
@Test
public void testTypes() throws Exception {
Class dateClass = parser.parseExpression("T(java.util.Date)").getValue(Class.class);
@@ -382,22 +382,22 @@ public class SpelDocumentationTests extends ExpressionTestCase {
boolean trueValue = parser.parseExpression("T(java.math.RoundingMode).CEILING < T(java.math.RoundingMode).FLOOR").getValue(Boolean.class);
Assert.assertTrue(trueValue);
}
// 7.5.7
@Test
public void testConstructors() throws Exception {
StandardEvaluationContext societyContext = new StandardEvaluationContext();
societyContext.setRootObject(new IEEE());
Inventor einstein =
Inventor einstein =
parser.parseExpression("new org.springframework.expression.spel.testresources.Inventor('Albert Einstein',new java.util.Date(), 'German')").getValue(Inventor.class);
Assert.assertEquals("Albert Einstein", einstein.getName());
//create new inventor instance within add method of List
parser.parseExpression("Members2.add(new org.springframework.expression.spel.testresources.Inventor('Albert Einstein', 'German'))").getValue(societyContext);
}
// 7.5.8
@Test
public void testVariables() throws Exception {
Inventor tesla = new Inventor("Nikola Tesla", "Serbian");
@@ -410,7 +410,7 @@ public class SpelDocumentationTests extends ExpressionTestCase {
Assert.assertEquals("Mike Tesla",tesla.getFoo());
}
@SuppressWarnings("unchecked")
@Test
public void testSpecialVariables() throws Exception {
@@ -427,45 +427,45 @@ public class SpelDocumentationTests extends ExpressionTestCase {
List<Integer> primesGreaterThanTen = (List<Integer>) parser.parseExpression("#primes.?[#this>10]").getValue(context);
Assert.assertEquals("[11, 13, 17]",primesGreaterThanTen.toString());
}
// 7.5.9
@Test
public void testFunctions() throws Exception {
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
context.registerFunction("reverseString",
context.registerFunction("reverseString",
StringUtils.class.getDeclaredMethod("reverseString", new Class[] { String.class }));
String helloWorldReversed = parser.parseExpression("#reverseString('hello world')").getValue(context, String.class);
Assert.assertEquals("dlrow olleh",helloWorldReversed);
}
// 7.5.10
@Test
public void testTernary() throws Exception {
String falseString = parser.parseExpression("false ? 'trueExp' : 'falseExp'").getValue(String.class);
Assert.assertEquals("falseExp",falseString);
StandardEvaluationContext societyContext = new StandardEvaluationContext();
societyContext.setRootObject(new IEEE());
parser.parseExpression("Name").setValue(societyContext, "IEEE");
societyContext.setVariable("queryName", "Nikola Tesla");
String expression = "isMember(#queryName)? #queryName + ' is a member of the ' " +
String expression = "isMember(#queryName)? #queryName + ' is a member of the ' " +
"+ Name + ' Society' : #queryName + ' is not a member of the ' + Name + ' Society'";
String queryResultString = parser.parseExpression(expression).getValue(societyContext, String.class);
Assert.assertEquals("Nikola Tesla is a member of the IEEE Society",queryResultString);
// queryResultString = "Nikola Tesla is a member of the IEEE Society"
}
// 7.5.11
@SuppressWarnings("unchecked")
@Test
public void testSelection() throws Exception {
@@ -475,16 +475,16 @@ public class SpelDocumentationTests extends ExpressionTestCase {
Assert.assertEquals(1,list.size());
Assert.assertEquals("Nikola Tesla",list.get(0).getName());
}
// 7.5.12
@Test
public void testTemplating() throws Exception {
String randomPhrase =
String randomPhrase =
parser.parseExpression("random number is ${T(java.lang.Math).random()}", new TemplatedParserContext()).getValue(String.class);
Assert.assertTrue(randomPhrase.startsWith("random number"));
}
static class TemplatedParserContext implements ParserContext {
public String getExpressionPrefix() {
@@ -494,12 +494,12 @@ public class SpelDocumentationTests extends ExpressionTestCase {
public String getExpressionSuffix() {
return "}";
}
public boolean isTemplate() {
return true;
}
}
static class StringUtils {
public static String reverseString(String input) {
@@ -510,6 +510,6 @@ public class SpelDocumentationTests extends ExpressionTestCase {
return backwards.toString();
}
}
}

View File

@@ -23,7 +23,7 @@ import org.springframework.expression.spel.standard.SpelExpression;
/**
* Utilities for working with Spring Expressions.
*
*
* @author Andy Clement
*/
public class SpelUtilities {

View File

@@ -25,7 +25,7 @@ import org.springframework.expression.spel.support.StandardTypeLocator;
/**
* Unit tests for type comparison
*
*
* @author Andy Clement
*/
public class StandardTypeLocatorTests {
@@ -35,7 +35,7 @@ public class StandardTypeLocatorTests {
StandardTypeLocator locator = new StandardTypeLocator();
Assert.assertEquals(Integer.class,locator.findType("java.lang.Integer"));
Assert.assertEquals(String.class,locator.findType("java.lang.String"));
List<String> prefixes = locator.getImportPrefixes();
Assert.assertEquals(1,prefixes.size());
Assert.assertTrue(prefixes.contains("java.lang"));
@@ -44,7 +44,7 @@ public class StandardTypeLocatorTests {
Assert.assertEquals(Boolean.class,locator.findType("Boolean"));
// currently does not know about java.util by default
// assertEquals(java.util.List.class,locator.findType("List"));
try {
locator.findType("URL");
Assert.fail("Should have failed");
@@ -54,7 +54,7 @@ public class StandardTypeLocatorTests {
}
locator.registerImport("java.net");
Assert.assertEquals(java.net.URL.class,locator.findType("URL"));
}
}

View File

@@ -91,7 +91,7 @@ public class TemplateExpressionParsingTests extends ExpressionTestCase {
Expression expr = parser.parseExpression("${'hello'} world", DEFAULT_TEMPLATE_PARSER_CONTEXT);
Object o = expr.getValue();
Assert.assertEquals("hello world", o.toString());
expr = parser.parseExpression("", DEFAULT_TEMPLATE_PARSER_CONTEXT);
o = expr.getValue();
Assert.assertEquals("", o.toString());
@@ -135,7 +135,7 @@ public class TemplateExpressionParsingTests extends ExpressionTestCase {
Assert.assertEquals(String.class,ex.getValueType(ctx, new Rooty()));
Assert.assertEquals(String.class,ex.getValueTypeDescriptor(new Rooty()).getType());
Assert.assertEquals(String.class,ex.getValueTypeDescriptor(ctx, new Rooty()).getType());
try {
ex.setValue(ctx, null);
Assert.fail();
@@ -155,9 +155,9 @@ public class TemplateExpressionParsingTests extends ExpressionTestCase {
// success
}
}
static class Rooty {}
@Test
public void testNestedExpressions() throws Exception {
SpelExpressionParser parser = new SpelExpressionParser();
@@ -179,22 +179,22 @@ public class TemplateExpressionParsingTests extends ExpressionTestCase {
ex = parser.parseExpression("hello ${listOfNumbersUpToTen.$[#this<5]} ${listOfNumbersUpToTen.$[#this>5]} world",DEFAULT_TEMPLATE_PARSER_CONTEXT);
s = ex.getValue(TestScenarioCreator.getTestEvaluationContext(),String.class);
Assert.assertEquals("hello 4 10 world",s);
try {
ex = parser.parseExpression("hello ${listOfNumbersUpToTen.$[#this<5]} ${listOfNumbersUpToTen.$[#this>5] world",DEFAULT_TEMPLATE_PARSER_CONTEXT);
Assert.fail("Should have failed");
} catch (ParseException pe) {
Assert.assertEquals("No ending suffix '}' for expression starting at character 41: ${listOfNumbersUpToTen.$[#this>5] world",pe.getMessage());
}
}
try {
ex = parser.parseExpression("hello ${listOfNumbersUpToTen.$[#root.listOfNumbersUpToTen.$[#this%2==1==3]} world",DEFAULT_TEMPLATE_PARSER_CONTEXT);
Assert.fail("Should have failed");
} catch (ParseException pe) {
Assert.assertEquals("Found closing '}' at position 74 but most recent opening is '[' at position 30",pe.getMessage());
}
}
}
@Test
public void testClashingWithSuffixes() throws Exception {
@@ -211,7 +211,7 @@ public class TemplateExpressionParsingTests extends ExpressionTestCase {
s = ex.getValue(TestScenarioCreator.getTestEvaluationContext(),String.class);
Assert.assertEquals("hello 7 wo}rld",s);
}
@Test
public void testParsingNormalExpressionThroughTemplateParser() throws Exception {
Expression expr = parser.parseExpression("1+2+3");
@@ -219,7 +219,7 @@ public class TemplateExpressionParsingTests extends ExpressionTestCase {
expr = parser.parseExpression("1+2+3",null);
Assert.assertEquals(6,expr.getValue());
}
@Test
public void testErrorCases() throws Exception {
try {
@@ -240,29 +240,29 @@ public class TemplateExpressionParsingTests extends ExpressionTestCase {
Assert.fail("Should have failed");
} catch (ParseException pe) {
Assert.assertEquals("No expression defined within delimiter '${}' at character 6",pe.getMessage());
}
}
}
@Test
public void testTemplateParserContext() {
TemplateParserContext tpc = new TemplateParserContext("abc","def");
Assert.assertEquals("abc", tpc.getExpressionPrefix());
Assert.assertEquals("def", tpc.getExpressionSuffix());
Assert.assertEquals("def", tpc.getExpressionSuffix());
Assert.assertTrue(tpc.isTemplate());
tpc = new TemplateParserContext();
Assert.assertEquals("#{", tpc.getExpressionPrefix());
Assert.assertEquals("}", tpc.getExpressionSuffix());
Assert.assertEquals("}", tpc.getExpressionSuffix());
Assert.assertTrue(tpc.isTemplate());
ParserContext pc = ParserContext.TEMPLATE_EXPRESSION;
Assert.assertEquals("#{", pc.getExpressionPrefix());
Assert.assertEquals("}", pc.getExpressionSuffix());
Assert.assertEquals("}", pc.getExpressionSuffix());
Assert.assertTrue(pc.isTemplate());
}
// ---
private void checkString(String expectedString, Object value) {
if (!(value instanceof String)) {
Assert.fail("Result was not a string, it was of type " + value.getClass() + " (value=" + value + ")");

View File

@@ -25,7 +25,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
/**
* Tests the evaluation of expressions that access variables and functions (lambda/java).
*
*
* @author Andy Clement
*/
public class VariableAndFunctionTests extends ExpressionTestCase {
@@ -35,7 +35,7 @@ public class VariableAndFunctionTests extends ExpressionTestCase {
evaluate("#answer", "42", Integer.class, SHOULD_BE_WRITABLE);
evaluate("#answer / 2", 21, Integer.class, SHOULD_NOT_BE_WRITABLE);
}
@Test
public void testVariableAccess_WellKnownVariables() {
evaluate("#this.getName()","Nikola Tesla",String.class);

View File

@@ -28,13 +28,13 @@ import static org.junit.Assert.*;
* @author Andy Wilkinson
*/
public class FormatHelperTests {
@Test
public void formatMethodWithSingleArgumentForMessage() {
String message = FormatHelper.formatMethodForMessage("foo", Arrays.asList(TypeDescriptor.forObject("a string")));
assertEquals("foo(java.lang.String)", message);
}
@Test
public void formatMethodWithMultipleArgumentsForMessage() {
String message = FormatHelper.formatMethodForMessage("foo", Arrays.asList(TypeDescriptor.forObject("a string"), TypeDescriptor.forObject(Integer.valueOf(5))));

View File

@@ -40,7 +40,7 @@ import org.springframework.expression.spel.support.ReflectionHelper.ArgsMatchKin
/**
* Tests for any helper code.
*
*
* @author Andy Clement
*/
public class ReflectionHelperTests extends ExpressionTestCase {
@@ -53,7 +53,7 @@ public class ReflectionHelperTests extends ExpressionTestCase {
Assert.assertEquals("int[][]",FormatHelper.formatClassNameForMessage(new int[1][2].getClass()));
Assert.assertEquals("null",FormatHelper.formatClassNameForMessage(null));
}
/*
@Test
public void testFormatHelperForMethod() {
@@ -62,7 +62,7 @@ public class ReflectionHelperTests extends ExpressionTestCase {
Assert.assertEquals("boo()",FormatHelper.formatMethodForMessage("boo"));
}
*/
@Test
public void testUtilities() throws ParseException {
SpelExpression expr = (SpelExpression)parser.parseExpression("3+4+5+6+7-2");
@@ -93,52 +93,52 @@ public class ReflectionHelperTests extends ExpressionTestCase {
Assert.assertTrue(s.indexOf("===> Expression '3+4+5+6+7-2' - AST start")!=-1);
Assert.assertTrue(s.indexOf(" OpPlus value:((((3 + 4) + 5) + 6) + 7) #children:2")!=-1);
}
@Test
public void testTypedValue() {
TypedValue tValue = new TypedValue("hello");
Assert.assertEquals(String.class,tValue.getTypeDescriptor().getType());
Assert.assertEquals("TypedValue: 'hello' of [java.lang.String]",tValue.toString());
}
@Test
public void testReflectionHelperCompareArguments_ExactMatching() {
StandardTypeConverter typeConverter = new StandardTypeConverter();
// Calling foo(String) with (String) is exact match
checkMatch(new Class[]{String.class},new Class[]{String.class},typeConverter,ArgsMatchKind.EXACT);
// Calling foo(String,Integer) with (String,Integer) is exact match
checkMatch(new Class[]{String.class,Integer.class},new Class[]{String.class,Integer.class},typeConverter,ArgsMatchKind.EXACT);
}
@Test
public void testReflectionHelperCompareArguments_CloseMatching() {
StandardTypeConverter typeConverter = new StandardTypeConverter();
// Calling foo(List) with (ArrayList) is close match (no conversion required)
checkMatch(new Class[]{ArrayList.class},new Class[]{List.class},typeConverter,ArgsMatchKind.CLOSE);
// Passing (Sub,String) on call to foo(Super,String) is close match
checkMatch(new Class[]{Sub.class,String.class},new Class[]{Super.class,String.class},typeConverter,ArgsMatchKind.CLOSE);
// Passing (String,Sub) on call to foo(String,Super) is close match
checkMatch(new Class[]{String.class,Sub.class},new Class[]{String.class,Super.class},typeConverter,ArgsMatchKind.CLOSE);
}
@Test
public void testReflectionHelperCompareArguments_RequiresConversionMatching() {
StandardTypeConverter typeConverter = new StandardTypeConverter();
// Calling foo(String,int) with (String,Integer) requires boxing conversion of argument one
checkMatch(new Class[]{String.class,Integer.TYPE},new Class[]{String.class,Integer.class},typeConverter,ArgsMatchKind.CLOSE,1);
// Passing (int,String) on call to foo(Integer,String) requires boxing conversion of argument zero
checkMatch(new Class[]{Integer.TYPE,String.class},new Class[]{Integer.class, String.class},typeConverter,ArgsMatchKind.CLOSE,0);
// Passing (int,Sub) on call to foo(Integer,Super) requires boxing conversion of argument zero
checkMatch(new Class[]{Integer.TYPE,Sub.class},new Class[]{Integer.class, Super.class},typeConverter,ArgsMatchKind.CLOSE,0);
// Passing (int,Sub,boolean) on call to foo(Integer,Super,Boolean) requires boxing conversion of arguments zero and two
// TODO checkMatch(new Class[]{Integer.TYPE,Sub.class,Boolean.TYPE},new Class[]{Integer.class, Super.class,Boolean.class},typeConverter,ArgsMatchKind.REQUIRES_CONVERSION,0,2);
}
@@ -146,7 +146,7 @@ public class ReflectionHelperTests extends ExpressionTestCase {
@Test
public void testReflectionHelperCompareArguments_NotAMatch() {
StandardTypeConverter typeConverter = new StandardTypeConverter();
// Passing (Super,String) on call to foo(Sub,String) is not a match
checkMatch(new Class[]{Super.class,String.class},new Class[]{Sub.class,String.class},typeConverter,null);
}
@@ -156,16 +156,16 @@ public class ReflectionHelperTests extends ExpressionTestCase {
StandardTypeConverter tc = new StandardTypeConverter();
Class<?> stringArrayClass = new String[0].getClass();
Class<?> integerArrayClass = new Integer[0].getClass();
// Passing (String[]) on call to (String[]) is exact match
checkMatch2(new Class[]{stringArrayClass},new Class[]{stringArrayClass},tc,ArgsMatchKind.EXACT);
// Passing (Integer, String[]) on call to (Integer, String[]) is exact match
checkMatch2(new Class[]{Integer.class,stringArrayClass},new Class[]{Integer.class,stringArrayClass},tc,ArgsMatchKind.EXACT);
// Passing (String, Integer, String[]) on call to (String, String, String[]) is exact match
checkMatch2(new Class[]{String.class,Integer.class,stringArrayClass},new Class[]{String.class,Integer.class,stringArrayClass},tc,ArgsMatchKind.EXACT);
// Passing (Sub, String[]) on call to (Super, String[]) is exact match
checkMatch2(new Class[]{Sub.class,stringArrayClass},new Class[]{Super.class,stringArrayClass},tc,ArgsMatchKind.CLOSE);
@@ -174,10 +174,10 @@ public class ReflectionHelperTests extends ExpressionTestCase {
// Passing (Integer, Sub, String[]) on call to (String, Super, String[]) is exact match
checkMatch2(new Class[]{Integer.class,Sub.class,String[].class},new Class[]{String.class,Super.class,String[].class},tc,ArgsMatchKind.REQUIRES_CONVERSION,0);
// Passing (String) on call to (String[]) is exact match
checkMatch2(new Class[]{String.class},new Class[]{stringArrayClass},tc,ArgsMatchKind.EXACT);
// Passing (Integer,String) on call to (Integer,String[]) is exact match
checkMatch2(new Class[]{Integer.class,String.class},new Class[]{Integer.class,stringArrayClass},tc,ArgsMatchKind.EXACT);
@@ -186,7 +186,7 @@ public class ReflectionHelperTests extends ExpressionTestCase {
// Passing (Sub) on call to (Super[]) is close match
checkMatch2(new Class[]{Sub.class},new Class[]{new Super[0].getClass()},tc,ArgsMatchKind.CLOSE);
// Passing (Super) on call to (Sub[]) is not a match
checkMatch2(new Class[]{Super.class},new Class[]{new Sub[0].getClass()},tc,null);
@@ -261,17 +261,17 @@ public class ReflectionHelperTests extends ExpressionTestCase {
catch (SpelEvaluationException se) {
Assert.assertEquals(SpelMessage.TYPE_CONVERSION_ERROR,se.getMessageCode());
}
// null value
args = new Object[]{3,null,3.0f};
ReflectionHelper.convertAllArguments(tc, args, twoArg);
checkArguments(args,"3",null,"3.0");
}
@Test
public void testSetupArguments() {
Object[] newArray = ReflectionHelper.setupArgumentsForVarargsInvocation(new Class[]{new String[0].getClass()},"a","b","c");
Assert.assertEquals(1,newArray.length);
Object firstParam = newArray[0];
Assert.assertEquals(String.class,firstParam.getClass().getComponentType());
@@ -281,7 +281,7 @@ public class ReflectionHelperTests extends ExpressionTestCase {
Assert.assertEquals("b",firstParamArray[1]);
Assert.assertEquals("c",firstParamArray[2]);
}
@Test
public void testReflectivePropertyResolver() throws Exception {
ReflectivePropertyAccessor rpr = new ReflectivePropertyAccessor();
@@ -295,16 +295,16 @@ public class ReflectionHelperTests extends ExpressionTestCase {
Assert.assertTrue(rpr.canRead(ctx, t, "field"));
Assert.assertEquals(3,rpr.read(ctx, t, "field").getValue());
Assert.assertEquals(3,rpr.read(ctx, t, "field").getValue()); // cached accessor used
Assert.assertTrue(rpr.canWrite(ctx, t, "property"));
rpr.write(ctx, t, "property","goodbye");
rpr.write(ctx, t, "property","goodbye"); // cached accessor used
Assert.assertTrue(rpr.canWrite(ctx, t, "field"));
rpr.write(ctx, t, "field",12);
rpr.write(ctx, t, "field",12);
// Attempted write as first activity on this field and property to drive testing
// Attempted write as first activity on this field and property to drive testing
// of populating type descriptor cache
rpr.write(ctx,t,"field2",3);
rpr.write(ctx, t, "property2","doodoo");
@@ -330,7 +330,7 @@ public class ReflectionHelperTests extends ExpressionTestCase {
Assert.assertEquals("id",rpr.read(ctx,t,"Id").getValue());
Assert.assertTrue(rpr.canRead(ctx,t,"Id"));
}
@Test
public void testOptimalReflectivePropertyResolver() throws Exception {
ReflectivePropertyAccessor rpr = new ReflectivePropertyAccessor();
@@ -340,7 +340,7 @@ public class ReflectionHelperTests extends ExpressionTestCase {
// Assert.assertTrue(rpr.canRead(ctx, t, "property"));
// Assert.assertEquals("hello",rpr.read(ctx, t, "property").getValue());
// Assert.assertEquals("hello",rpr.read(ctx, t, "property").getValue()); // cached accessor used
PropertyAccessor optA = rpr.createOptimalAccessor(ctx, t, "property");
Assert.assertTrue(optA.canRead(ctx, t, "property"));
Assert.assertFalse(optA.canRead(ctx, t, "property2"));
@@ -405,7 +405,7 @@ public class ReflectionHelperTests extends ExpressionTestCase {
}
// test classes
static class Tester {
@@ -426,7 +426,7 @@ public class ReflectionHelperTests extends ExpressionTestCase {
public void setProperty2(String value) { property2 = value; }
public String getProperty3() { return property3; }
public boolean isProperty4() { return property4; }
public String getiD() { return iD; }
@@ -435,17 +435,17 @@ public class ReflectionHelperTests extends ExpressionTestCase {
public String getID() { return ID; }
}
static class Super {
}
static class Sub extends Super {
}
static class Unconvertable {}
// ---
/**
* Used to validate the match returned from a compareArguments call.
*/
@@ -459,10 +459,10 @@ public class ReflectionHelperTests extends ExpressionTestCase {
if (expectedMatchKind==ArgsMatchKind.EXACT) {
Assert.assertTrue(matchInfo.isExactMatch());
Assert.assertNull(matchInfo.argsRequiringConversion);
Assert.assertNull(matchInfo.argsRequiringConversion);
} else if (expectedMatchKind==ArgsMatchKind.CLOSE) {
Assert.assertTrue(matchInfo.isCloseMatch());
Assert.assertNull(matchInfo.argsRequiringConversion);
Assert.assertNull(matchInfo.argsRequiringConversion);
} else if (expectedMatchKind==ArgsMatchKind.REQUIRES_CONVERSION) {
Assert.assertTrue("expected to be a match requiring conversion, but was "+matchInfo,matchInfo.isMatchRequiringConversion());
if (argsForConversion==null) {
@@ -488,10 +488,10 @@ public class ReflectionHelperTests extends ExpressionTestCase {
if (expectedMatchKind==ArgsMatchKind.EXACT) {
Assert.assertTrue(matchInfo.isExactMatch());
Assert.assertNull(matchInfo.argsRequiringConversion);
Assert.assertNull(matchInfo.argsRequiringConversion);
} else if (expectedMatchKind==ArgsMatchKind.CLOSE) {
Assert.assertTrue(matchInfo.isCloseMatch());
Assert.assertNull(matchInfo.argsRequiringConversion);
Assert.assertNull(matchInfo.argsRequiringConversion);
} else if (expectedMatchKind==ArgsMatchKind.REQUIRES_CONVERSION) {
Assert.assertTrue("expected to be a match requiring conversion, but was "+matchInfo,matchInfo.isMatchRequiringConversion());
if (argsForConversion==null) {
@@ -510,7 +510,7 @@ public class ReflectionHelperTests extends ExpressionTestCase {
checkArgument(expected[i],args[i]);
}
}
private void checkArgument(Object expected, Object actual) {
Assert.assertEquals(expected,actual);
}

View File

@@ -43,19 +43,19 @@ public class StandardComponentsTests {
context.setTypeLocator(tl);
Assert.assertEquals(tl,context.getTypeLocator());
}
@Test
public void testStandardOperatorOverloader() throws EvaluationException {
OperatorOverloader oo = new StandardOperatorOverloader();
Assert.assertFalse(oo.overridesOperation(Operation.ADD, null, null));
try {
try {
oo.operate(Operation.ADD, 2, 3);
Assert.fail("should have failed");
} catch (EvaluationException e) {
// success
}
}
@Test
public void testStandardTypeLocator() {
StandardTypeLocator tl = new StandardTypeLocator();
@@ -68,7 +68,7 @@ public class StandardComponentsTests {
prefixes = tl.getImportPrefixes();
Assert.assertEquals(1,prefixes.size());
}
@Test
public void testStandardTypeConverter() throws EvaluationException {
TypeConverter tc = new StandardTypeConverter();

View File

@@ -17,7 +17,7 @@
/**
* Hold the various kinds of primitive array for access through the test evaluation context.
*
*
* @author Andy Clement
*/
public class ArrayContainer {
@@ -29,7 +29,7 @@ public class ArrayContainer {
public short[] shorts = new short[3];
public boolean[] booleans = new boolean[3];
public float[] floats = new float[3];
public ArrayContainer() {
// setup some values
ints[0] = 42;

View File

@@ -1,12 +1,12 @@
/**
*
*
*/
package org.springframework.expression.spel.testresources;
///CLOVER:OFF
public class Company {
String address;
public Company(String string) {
this.address = string;
}

View File

@@ -1,5 +1,5 @@
/**
*
*
*/
package org.springframework.expression.spel.testresources;
@@ -11,7 +11,7 @@ public class Fruit {
public Color color; // accessible as property through getter/setter
public String colorName; // accessible as property through getter/setter
public int stringscount = -1;
public Fruit(String name, Color color, String colorName) {
this.name = name;
this.color = color;
@@ -21,15 +21,15 @@ public class Fruit {
public Color getColor() {
return color;
}
public Fruit(String... strings) {
stringscount = strings.length;
}
public Fruit(int i, String... strings) {
stringscount = i + strings.length;
}
public int stringscount() {
return stringscount;
}

View File

@@ -37,7 +37,7 @@ public class Inventor {
public String[] stringArrayOfThreeItems = new String[]{"1","2","3"};
private String foo;
public int counter;
public Inventor(String name, Date birthdate, String nationality) {
this.name = name;
this._name = name;
@@ -88,7 +88,7 @@ public class Inventor {
public String[] getInventions() {
return inventions;
}
public void setInventions(String[] inventions) {
this.inventions = inventions;
}
@@ -96,7 +96,7 @@ public class Inventor {
public PlaceOfBirth getPlaceOfBirth() {
return placeOfBirth;
}
public int throwException(int valueIn) throws Exception {
counter++;
if (valueIn==1) {
@@ -110,9 +110,9 @@ public class Inventor {
}
return valueIn;
}
static class TestException extends Exception {}
public String throwException(PlaceOfBirth pob) {
return pob.getCity();
}
@@ -120,7 +120,7 @@ public class Inventor {
public String getName() {
return name;
}
public boolean getWonNobelPrize() {
return wonNobelPrize;
}
@@ -152,7 +152,7 @@ public class Inventor {
public String sayHelloTo(String person) {
return "hello " + person;
}
public String printDouble(Double d) {
return d.toString();
}
@@ -187,7 +187,7 @@ public class Inventor {
public Inventor(String... strings) {
}
public boolean getSomeProperty() {
return accessedThroughGetSet;
}
@@ -195,7 +195,7 @@ public class Inventor {
public void setSomeProperty(boolean b) {
this.accessedThroughGetSet = b;
}
public Date getBirthdate() { return birthdate;}
public String getFoo() { return foo; }

View File

@@ -8,16 +8,16 @@ public class Person {
public Person(String name) {
this.privateName = name;
}
public Person(String name, Company company) {
this.privateName = name;
this.company = company;
}
public String getName() {
return privateName;
}
public void setName(String n) {
this.privateName = n;
}

View File

@@ -3,9 +3,9 @@ package org.springframework.expression.spel.testresources;
///CLOVER:OFF
public class PlaceOfBirth {
private String city;
public String Country;
/**
* Keith now has a converter that supports String to X, if X has a ctor that takes a String.
* In order for round tripping to work we need toString() for X to return what it was
@@ -25,11 +25,11 @@ public class PlaceOfBirth {
public PlaceOfBirth(String string) {
this.city=string;
}
public int doubleIt(int i) {
return i*2;
}
public boolean equals(Object o) {
if (!(o instanceof PlaceOfBirth)) {
return false;
@@ -37,9 +37,9 @@ public class PlaceOfBirth {
PlaceOfBirth oPOB = (PlaceOfBirth)o;
return (city.equals(oPOB.city));
}
public int hashCode() {
return city.hashCode();
}
}

View File

@@ -5,7 +5,7 @@ import java.util.List;
public class TestAddress{
private String street;
private List<String> crossStreets;
public String getStreet() {
return street;
}

View File

@@ -3,7 +3,7 @@ package org.springframework.expression.spel.testresources;
public class TestPerson {
private String name;
private TestAddress address;
public String getName() {
return name;
}