Added tests for getting non-existent fields and changed test for parser eval error

This commit is contained in:
Owen Stephens 2018-05-10 16:37:11 -04:00
parent b1bfcb586c
commit 1e2c0c0a04

View File

@ -99,7 +99,7 @@ public class GrelTests extends RefineTest {
public void testEvalError() {
String tests[] = {
// "1=1", // TODO: Throws NullPointerException
"a.value",
"value.datePart()",
};
for (String test : tests) {
try {
@ -167,6 +167,26 @@ public class GrelTests extends RefineTest {
}
}
@Test
public void testGetJsonFieldExists() throws ParsingException {
String test[] = { "\"[{\\\"one\\\": \\\"1\\\"}]\".parseJson()[0].one", "1" };
parseEval(bindings, test);
}
@Test
public void testGetJsonFieldAbsent() throws ParsingException {
String test = "\"[{\\\"one\\\": \\\"1\\\"}]\".parseJson()[0].two";
Evaluable eval = MetaParser.parse("grel:" + test);
Assert.assertNull(eval.evaluate(bindings));
}
@Test
public void testGetFieldFromNull() throws ParsingException {
String test = "null.value";
Evaluable eval = MetaParser.parse("grel:" + test);
Assert.assertNull(eval.evaluate(bindings));
}
// to demonstrate bug fixing for #1204
@Test
public void testCrossFunctionEval() {