Remove trailing whitespace
This commit is contained in:
@@ -40,7 +40,7 @@ import org.springframework.expression.spel.testresources.PlaceOfBirth;
|
||||
|
||||
/**
|
||||
* Tests invocation of methods.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class MethodInvocationTests extends ExpressionTestCase {
|
||||
@@ -89,7 +89,7 @@ public class MethodInvocationTests extends ExpressionTestCase {
|
||||
evaluate("new String('hello 2.0 to you').startsWith(7.0d)", false, Boolean.class);
|
||||
evaluate("new String('7.0 foobar').startsWith(7.0d)", true, Boolean.class);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMethodThrowingException_SPR6760() {
|
||||
// Test method on inventor: throwException()
|
||||
@@ -97,7 +97,7 @@ public class MethodInvocationTests extends ExpressionTestCase {
|
||||
// On 2 it will throw a RuntimeException
|
||||
// On 3 it will exit normally
|
||||
// In each case it increments the Inventor field 'counter' when invoked
|
||||
|
||||
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expr = parser.parseExpression("throwException(#bar)");
|
||||
|
||||
@@ -115,18 +115,18 @@ public class MethodInvocationTests extends ExpressionTestCase {
|
||||
o = expr.getValue(eContext);
|
||||
Assert.assertEquals("London", 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);
|
||||
Assert.assertEquals(3, o);
|
||||
Assert.assertEquals(2,parser.parseExpression("counter").getValue(eContext));
|
||||
|
||||
|
||||
|
||||
// Now cause it to throw an exception:
|
||||
eContext.setVariable("bar",1);
|
||||
try {
|
||||
@@ -157,7 +157,7 @@ public class MethodInvocationTests extends ExpressionTestCase {
|
||||
// If counter is 5 then the method got called twice!
|
||||
Assert.assertEquals(4,parser.parseExpression("counter").getValue(eContext));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check on first usage (when the cachedExecutor in MethodReference is null) that the exception is not wrapped.
|
||||
*/
|
||||
@@ -168,10 +168,10 @@ public class MethodInvocationTests extends ExpressionTestCase {
|
||||
// On 2 it will throw a RuntimeException
|
||||
// On 3 it will exit normally
|
||||
// In each case it increments the Inventor field 'counter' when invoked
|
||||
|
||||
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expr = parser.parseExpression("throwException(#bar)");
|
||||
|
||||
|
||||
eContext.setVariable("bar",2);
|
||||
try {
|
||||
expr.getValue(eContext);
|
||||
@@ -184,7 +184,7 @@ public class MethodInvocationTests extends ExpressionTestCase {
|
||||
// normal
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMethodThrowingException_SPR6941_2() {
|
||||
// Test method on inventor: throwException()
|
||||
@@ -192,10 +192,10 @@ public class MethodInvocationTests extends ExpressionTestCase {
|
||||
// On 2 it will throw a RuntimeException
|
||||
// On 3 it will exit normally
|
||||
// In each case it increments the Inventor field 'counter' when invoked
|
||||
|
||||
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expr = parser.parseExpression("throwException(#bar)");
|
||||
|
||||
|
||||
eContext.setVariable("bar",4);
|
||||
try {
|
||||
expr.getValue(eContext);
|
||||
@@ -207,7 +207,7 @@ public class MethodInvocationTests extends ExpressionTestCase {
|
||||
}
|
||||
Assert.fail("Should not be a SpelEvaluationException");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMethodFiltering_SPR6764() {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
@@ -215,13 +215,13 @@ public class MethodInvocationTests extends ExpressionTestCase {
|
||||
context.setRootObject(new TestObject());
|
||||
LocalFilter filter = new LocalFilter();
|
||||
context.registerMethodFilter(TestObject.class,filter);
|
||||
|
||||
|
||||
// Filter will be called but not do anything, so first doit() will be invoked
|
||||
SpelExpression expr = (SpelExpression) parser.parseExpression("doit(1)");
|
||||
String result = expr.getValue(context,String.class);
|
||||
Assert.assertEquals("1",result);
|
||||
Assert.assertTrue(filter.filterCalled);
|
||||
|
||||
|
||||
// Filter will now remove non @Anno annotated methods
|
||||
filter.removeIfNotAnnotated = true;
|
||||
filter.filterCalled = false;
|
||||
@@ -229,7 +229,7 @@ public class MethodInvocationTests extends ExpressionTestCase {
|
||||
result = expr.getValue(context,String.class);
|
||||
Assert.assertEquals("double 1.0",result);
|
||||
Assert.assertTrue(filter.filterCalled);
|
||||
|
||||
|
||||
// check not called for other types
|
||||
filter.filterCalled=false;
|
||||
context.setRootObject(new String("abc"));
|
||||
@@ -237,7 +237,7 @@ public class MethodInvocationTests extends ExpressionTestCase {
|
||||
result = expr.getValue(context,String.class);
|
||||
Assert.assertEquals("a",result);
|
||||
Assert.assertFalse(filter.filterCalled);
|
||||
|
||||
|
||||
// check de-registration works
|
||||
filter.filterCalled = false;
|
||||
context.registerMethodFilter(TestObject.class,null);//clear filter
|
||||
@@ -247,14 +247,14 @@ public class MethodInvocationTests extends ExpressionTestCase {
|
||||
Assert.assertEquals("1",result);
|
||||
Assert.assertFalse(filter.filterCalled);
|
||||
}
|
||||
|
||||
|
||||
// Simple filter
|
||||
static class LocalFilter implements MethodFilter {
|
||||
|
||||
|
||||
public boolean removeIfNotAnnotated = false;
|
||||
|
||||
|
||||
public boolean filterCalled = false;
|
||||
|
||||
|
||||
private boolean isAnnotated(Method m) {
|
||||
Annotation[] annos = m.getAnnotations();
|
||||
if (annos==null) {
|
||||
@@ -282,53 +282,53 @@ public class MethodInvocationTests extends ExpressionTestCase {
|
||||
}
|
||||
return methods;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@interface Anno {}
|
||||
|
||||
|
||||
class TestObject {
|
||||
public int doit(int i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
@Anno
|
||||
public String doit(double d) {
|
||||
return "double "+d;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAddingMethodResolvers() {
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext();
|
||||
|
||||
|
||||
// reflective method accessor is the only one by default
|
||||
List<MethodResolver> methodResolvers = ctx.getMethodResolvers();
|
||||
Assert.assertEquals(1,methodResolvers.size());
|
||||
|
||||
|
||||
MethodResolver dummy = new DummyMethodResolver();
|
||||
ctx.addMethodResolver(dummy);
|
||||
Assert.assertEquals(2,ctx.getMethodResolvers().size());
|
||||
|
||||
|
||||
List<MethodResolver> copy = new ArrayList<MethodResolver>();
|
||||
copy.addAll(ctx.getMethodResolvers());
|
||||
Assert.assertTrue(ctx.removeMethodResolver(dummy));
|
||||
Assert.assertFalse(ctx.removeMethodResolver(dummy));
|
||||
Assert.assertEquals(1,ctx.getMethodResolvers().size());
|
||||
|
||||
|
||||
ctx.setMethodResolvers(copy);
|
||||
Assert.assertEquals(2,ctx.getMethodResolvers().size());
|
||||
}
|
||||
|
||||
|
||||
static class DummyMethodResolver implements MethodResolver {
|
||||
|
||||
public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name,
|
||||
List<TypeDescriptor> argumentTypes) throws AccessException {
|
||||
throw new UnsupportedOperationException("Auto-generated method stub");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -355,7 +355,7 @@ public class MethodInvocationTests extends ExpressionTestCase {
|
||||
evaluate("aVarargsMethod2(2,'a',3.0d)", 4, Integer.class);
|
||||
// evaluate("aVarargsMethod2(8,new String[]{'a','b','c'})", 11, Integer.class);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testInvocationOnNullContextObject() {
|
||||
evaluateAndCheckError("null.toString()",SpelMessage.METHOD_CALL_ON_NULL_OBJECT_NOT_ALLOWED);
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||
|
||||
/**
|
||||
* Tests accessing of properties.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class PropertyAccessTests extends ExpressionTestCase {
|
||||
@@ -65,9 +65,9 @@ public class PropertyAccessTests extends ExpressionTestCase {
|
||||
// name is ok but foobar does not exist:
|
||||
evaluateAndCheckError("name.foobar", SpelMessage.PROPERTY_OR_FIELD_NOT_READABLE, 5);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The standard reflection resolver cannot find properties on null objects but some
|
||||
* The standard reflection resolver cannot find properties on null objects but some
|
||||
* supplied resolver might be able to - so null shouldn't crash the reflection resolver.
|
||||
*/
|
||||
@Test
|
||||
@@ -132,25 +132,25 @@ public class PropertyAccessTests extends ExpressionTestCase {
|
||||
// System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAddingRemovingAccessors() {
|
||||
StandardEvaluationContext ctx = new StandardEvaluationContext();
|
||||
|
||||
|
||||
// reflective property accessor is the only one by default
|
||||
List<PropertyAccessor> propertyAccessors = ctx.getPropertyAccessors();
|
||||
Assert.assertEquals(1,propertyAccessors.size());
|
||||
|
||||
|
||||
StringyPropertyAccessor spa = new StringyPropertyAccessor();
|
||||
ctx.addPropertyAccessor(spa);
|
||||
Assert.assertEquals(2,ctx.getPropertyAccessors().size());
|
||||
|
||||
|
||||
List<PropertyAccessor> copy = new ArrayList<PropertyAccessor>();
|
||||
copy.addAll(ctx.getPropertyAccessors());
|
||||
Assert.assertTrue(ctx.removePropertyAccessor(spa));
|
||||
Assert.assertFalse(ctx.removePropertyAccessor(spa));
|
||||
Assert.assertEquals(1,ctx.getPropertyAccessors().size());
|
||||
|
||||
|
||||
ctx.setPropertyAccessors(copy);
|
||||
Assert.assertEquals(2,ctx.getPropertyAccessors().size());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user