removed redundant test - there is no non-optimal reflection accessor to test now
This commit is contained in:
parent
3987316e4c
commit
8730cde270
|
|
@ -20,7 +20,6 @@ import org.springframework.expression.EvaluationContext;
|
||||||
import org.springframework.expression.EvaluationException;
|
import org.springframework.expression.EvaluationException;
|
||||||
import org.springframework.expression.Expression;
|
import org.springframework.expression.Expression;
|
||||||
import org.springframework.expression.PropertyAccessor;
|
import org.springframework.expression.PropertyAccessor;
|
||||||
import org.springframework.expression.spel.reflection.ReflectionPropertyResolver;
|
|
||||||
import org.springframework.expression.spel.standard.StandardEvaluationContext;
|
import org.springframework.expression.spel.standard.StandardEvaluationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -38,24 +37,6 @@ public class PropertyAccessTests extends ExpressionTestCase {
|
||||||
evaluate("placeOfBirth.city", "SmilJan", String.class);
|
evaluate("placeOfBirth.city", "SmilJan", String.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimpleAccess03() {
|
|
||||||
try {
|
|
||||||
ReflectionPropertyResolver.useResolverExecutorModel = false;
|
|
||||||
evaluate("name", "Nikola Tesla", String.class);
|
|
||||||
} finally {
|
|
||||||
ReflectionPropertyResolver.useResolverExecutorModel = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testSimpleAccess04() {
|
|
||||||
try {
|
|
||||||
ReflectionPropertyResolver.useResolverExecutorModel = false;
|
|
||||||
evaluate("placeOfBirth.city", "SmilJan", String.class);
|
|
||||||
} finally {
|
|
||||||
ReflectionPropertyResolver.useResolverExecutorModel = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testNonExistentPropertiesAndMethods() {
|
public void testNonExistentPropertiesAndMethods() {
|
||||||
// madeup does not exist as a property
|
// madeup does not exist as a property
|
||||||
evaluateAndCheckError("madeup", SpelMessages.PROPERTY_OR_FIELD_NOT_FOUND, 0);
|
evaluateAndCheckError("madeup", SpelMessages.PROPERTY_OR_FIELD_NOT_FOUND, 0);
|
||||||
|
|
@ -74,24 +55,27 @@ public class PropertyAccessTests extends ExpressionTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canRead(EvaluationContext context, Object target, Object name) throws AccessException {
|
public boolean canRead(EvaluationContext context, Object target, Object name) throws AccessException {
|
||||||
if (!(target instanceof String)) throw new RuntimeException("Assertion Failed! target should be String");
|
if (!(target instanceof String))
|
||||||
|
throw new RuntimeException("Assertion Failed! target should be String");
|
||||||
return (name.equals("flibbles"));
|
return (name.equals("flibbles"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canWrite(EvaluationContext context, Object target, Object name) throws AccessException {
|
public boolean canWrite(EvaluationContext context, Object target, Object name) throws AccessException {
|
||||||
if (!(target instanceof String)) throw new RuntimeException("Assertion Failed! target should be String");
|
if (!(target instanceof String))
|
||||||
|
throw new RuntimeException("Assertion Failed! target should be String");
|
||||||
return (name.equals("flibbles"));
|
return (name.equals("flibbles"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Object read(EvaluationContext context, Object target, Object name) throws AccessException {
|
public Object read(EvaluationContext context, Object target, Object name) throws AccessException {
|
||||||
if (!name.equals("flibbles") ) throw new RuntimeException("Assertion Failed! name should be flibbles");
|
if (!name.equals("flibbles"))
|
||||||
|
throw new RuntimeException("Assertion Failed! name should be flibbles");
|
||||||
return flibbles;
|
return flibbles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(EvaluationContext context, Object target, Object name, Object newValue)
|
public void write(EvaluationContext context, Object target, Object name, Object newValue)
|
||||||
throws AccessException {
|
throws AccessException {
|
||||||
if (!name.equals("flibbles") ) throw new RuntimeException("Assertion Failed! name should be flibbles");
|
if (!name.equals("flibbles"))
|
||||||
|
throw new RuntimeException("Assertion Failed! name should be flibbles");
|
||||||
try {
|
try {
|
||||||
flibbles = (Integer) context.getTypeUtils().getTypeConverter().convertValue(newValue, Integer.class);
|
flibbles = (Integer) context.getTypeUtils().getTypeConverter().convertValue(newValue, Integer.class);
|
||||||
} catch (EvaluationException e) {
|
} catch (EvaluationException e) {
|
||||||
|
|
@ -124,13 +108,13 @@ public class PropertyAccessTests extends ExpressionTestCase {
|
||||||
i = (Integer) expr.getValue(ctx, Integer.class);
|
i = (Integer) expr.getValue(ctx, Integer.class);
|
||||||
assertEquals((int) i, 99);
|
assertEquals((int) i, 99);
|
||||||
|
|
||||||
|
|
||||||
// Cannot set it to a string value
|
// Cannot set it to a string value
|
||||||
try {
|
try {
|
||||||
expr.setValue(ctx, "not allowed");
|
expr.setValue(ctx, "not allowed");
|
||||||
fail("Should not have been allowed");
|
fail("Should not have been allowed");
|
||||||
} catch (EvaluationException e) {
|
} catch (EvaluationException e) {
|
||||||
// success - message will be: EL1063E:(pos 20): A problem occurred whilst attempting to set the property 'flibbles': 'Cannot set flibbles to an object of type 'class java.lang.String''
|
// success - message will be: EL1063E:(pos 20): A problem occurred whilst attempting to set the property
|
||||||
|
// 'flibbles': 'Cannot set flibbles to an object of type 'class java.lang.String''
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue