test coverage. now > 95%
This commit is contained in:
parent
233c84e0b9
commit
88e32a3cfe
|
|
@ -119,8 +119,7 @@ public class SpelExpression implements Expression {
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public Class getValueType(EvaluationContext context) throws EvaluationException {
|
public Class getValueType(EvaluationContext context) throws EvaluationException {
|
||||||
// TODO is this a legal implementation? The null return value could be very unhelpful. See other getValueType()
|
// TODO both getValueType() methods could use getValueInternal and return a type descriptor from the resultant TypedValue
|
||||||
// also.
|
|
||||||
Object value = getValue(context);
|
Object value = getValue(context);
|
||||||
return (value != null ? value.getClass() : null);
|
return (value != null ? value.getClass() : null);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,10 +40,8 @@ public abstract class SpelNodeImpl implements SpelNode, CommonTypeDescriptors {
|
||||||
|
|
||||||
public SpelNodeImpl(int pos, SpelNodeImpl... operands) {
|
public SpelNodeImpl(int pos, SpelNodeImpl... operands) {
|
||||||
this.pos = pos;
|
this.pos = pos;
|
||||||
if (pos==0) {
|
// pos combines start and end so can never be zero because tokens cannot be zero length
|
||||||
// pos embodies start and end so can never be zero because tokens cannot be zero length
|
assert pos!=0;
|
||||||
throw new IllegalStateException("Node cannot have zero position: "+this.getClass());
|
|
||||||
}
|
|
||||||
if (operands!=null && operands.length>0) {
|
if (operands!=null && operands.length>0) {
|
||||||
this.children = operands;
|
this.children = operands;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,11 @@ public class SetValueTests extends ExpressionTestCase {
|
||||||
setValue("inventions[0]", "Just the telephone");
|
setValue("inventions[0]", "Just the telephone");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testErrorCase() {
|
||||||
|
setValueExpectError("3=4", null);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetElementOfNull() {
|
public void testSetElementOfNull() {
|
||||||
setValueExpectError("new org.springframework.expression.spel.testresources.Inventor().inventions[1]",SpelMessages.CANNOT_INDEX_INTO_NULL_VALUE);
|
setValueExpectError("new org.springframework.expression.spel.testresources.Inventor().inventions[1]",SpelMessages.CANNOT_INDEX_INTO_NULL_VALUE);
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
import junit.framework.Assert;
|
import junit.framework.Assert;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.springframework.expression.EvaluationContext;
|
||||||
import org.springframework.expression.EvaluationException;
|
import org.springframework.expression.EvaluationException;
|
||||||
import org.springframework.expression.ExpressionException;
|
import org.springframework.expression.ExpressionException;
|
||||||
import org.springframework.expression.ParseException;
|
import org.springframework.expression.ParseException;
|
||||||
|
|
@ -26,6 +27,7 @@ import org.springframework.expression.spel.SpelNode;
|
||||||
import org.springframework.expression.spel.SpelParseException;
|
import org.springframework.expression.spel.SpelParseException;
|
||||||
import org.springframework.expression.spel.ast.OpAnd;
|
import org.springframework.expression.spel.ast.OpAnd;
|
||||||
import org.springframework.expression.spel.ast.OpOr;
|
import org.springframework.expression.spel.ast.OpOr;
|
||||||
|
import org.springframework.expression.spel.support.StandardEvaluationContext;
|
||||||
|
|
||||||
|
|
||||||
public class SpelParserTests {
|
public class SpelParserTests {
|
||||||
|
|
@ -38,6 +40,23 @@ public class SpelParserTests {
|
||||||
Assert.assertNotNull(expr.getAST());
|
Assert.assertNotNull(expr.getAST());
|
||||||
Assert.assertEquals(2,expr.getValue());
|
Assert.assertEquals(2,expr.getValue());
|
||||||
Assert.assertEquals(Integer.class,expr.getValueType());
|
Assert.assertEquals(Integer.class,expr.getValueType());
|
||||||
|
Assert.assertEquals(2,expr.getAST().getValue(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void valueType() throws Exception {
|
||||||
|
SpelExpressionParser parser = new SpelExpressionParser();
|
||||||
|
EvaluationContext ctx = new StandardEvaluationContext();
|
||||||
|
Class c = parser.parse("2").getValueType();
|
||||||
|
Assert.assertEquals(Integer.class,c);
|
||||||
|
c = parser.parse("12").getValueType(ctx);
|
||||||
|
Assert.assertEquals(Integer.class,c);
|
||||||
|
c = parser.parse("null").getValueType();
|
||||||
|
Assert.assertNull(c);
|
||||||
|
c = parser.parse("null").getValueType(ctx);
|
||||||
|
Assert.assertNull(c);
|
||||||
|
Object o = parser.parse("null").getValue(ctx,Integer.class);
|
||||||
|
Assert.assertNull(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue