improved javadoc, error handling and testing of matches

This commit is contained in:
Andy Clement
2008-08-17 01:28:26 +00:00
parent bb2ade5fdd
commit c6db7c41a4
4 changed files with 73 additions and 20 deletions

View File

@@ -101,6 +101,18 @@ public class EvaluationTests extends ExpressionTestCase {
evaluate("{1, 2, 3, 4, 5} is T(List)", "true", Boolean.class);
}
public void testRelOperatorsIs04() {
evaluate("null is T(String)", "false", Boolean.class);
}
public void testRelOperatorsIs05() {
evaluate("null is T(Integer)", "false", Boolean.class);
}
public void testRelOperatorsIs06() {
evaluateAndCheckError("'A' is null", SpelMessages.IS_OPERATOR_NEEDS_CLASS_OPERAND, 7, "null");
}
public void testRelOperatorsMatches01() {
evaluate("'5.0067' matches '^-?\\d+(\\.\\d{2})?$'", "false", Boolean.class);
}
@@ -109,6 +121,18 @@ public class EvaluationTests extends ExpressionTestCase {
evaluate("'5.00' matches '^-?\\d+(\\.\\d{2})?$'", "true", Boolean.class);
}
public void testRelOperatorsMatches03() {
evaluateAndCheckError("null matches '^.*$'", SpelMessages.INVALID_FIRST_OPERAND_FOR_LIKE_OPERATOR, 0, null);
}
public void testRelOperatorsMatches04() {
evaluateAndCheckError("'abc' matches null", SpelMessages.INVALID_SECOND_OPERAND_FOR_LIKE_OPERATOR, 14, null);
}
public void testRelOperatorsMatches05() {
evaluate("27 matches '^.*2.*$'", true, Boolean.class); // conversion int>string
}
// mathematical operators
public void testMathOperatorAdd01() {
evaluate("2 + 4", "6", Integer.class);
@@ -336,7 +360,7 @@ public class EvaluationTests extends ExpressionTestCase {
SpelMessages.RESULT_OF_SELECTION_CRITERIA_IS_NOT_BOOLEAN);
}
// TODO 3 Q Is $index within projection/selection useful or just cute?
// TODO Is $index within projection/selection useful or just cute?
public void testSelectionUsingIndex() {
evaluate("{1,2,3,4,5,6,7,8,9,10}.?{$index > 5 }", "[7, 8, 9, 10]", ArrayList.class);
}

View File

@@ -164,7 +164,7 @@ public abstract class ExpressionTestCase extends TestCase {
assertEquals("Type of the result was not as expected. Expected '" + expectedClassOfResult
+ "' but result was of type '" + resultType + "'", expectedClassOfResult
.equals/* isAssignableFrom */(resultType), true);
// TODO 4 isAssignableFrom would allow some room for compatibility
// TODO isAssignableFrom would allow some room for compatibility
// in the above expression...
boolean isWritable = e.isWritable(eContext);
@@ -243,7 +243,19 @@ public abstract class ExpressionTestCase extends TestCase {
+ " properties of the exception, it only has " + inserts.length + " inserts");
}
for (int i = 1; i < otherProperties.length; i++) {
if (!inserts[i - 1].equals(otherProperties[i])) {
if (otherProperties[i] == null) {
if (inserts[i - 1] != null) {
ex.printStackTrace();
fail("Insert does not match, expected 'null' but insert value was '" + inserts[i - 1]
+ "'");
}
} else if (inserts[i - 1] == null) {
if (otherProperties[i] != null) {
ex.printStackTrace();
fail("Insert does not match, expected '" + otherProperties[i]
+ "' but insert value was 'null'");
}
} else if (!inserts[i - 1].equals(otherProperties[i])) {
ex.printStackTrace();
fail("Insert does not match, expected '" + otherProperties[i] + "' but insert value was '"
+ inserts[i - 1] + "'");

View File

@@ -97,7 +97,7 @@ public class LiteralTests extends ExpressionTestCase {
evaluate("null", null, null);
}
// TODO 3 'default' format for date varies too much, we need to standardize on a format for EL
// TODO 'default' format for date varies too much, we need to standardize on a format for EL
// public void testLiteralDate01() {
// eval("date('3-Feb-2008 4:50:20 PM').getTime()>0", "true", Boolean.class);
// }