Browse Source

Support for Boolean values in ExpressionEvaluator

pull/23/head
Dmytro Kostiuchenko 12 years ago
parent
commit
a3b2684b6f
  1. 9
      json-path/src/main/java/com/jayway/jsonpath/internal/filter/eval/ExpressionEvaluator.java
  2. 18
      json-path/src/test/java/com/jayway/jsonpath/ExpressionEvalTest.java

9
json-path/src/main/java/com/jayway/jsonpath/internal/filter/eval/ExpressionEvaluator.java

@ -90,6 +90,15 @@ public class ExpressionEvaluator {
} else if ("!=".equals(comparator) || "<>".equals(comparator)) { } else if ("!=".equals(comparator) || "<>".equals(comparator)) {
return !a.equals(expected); return !a.equals(expected);
} }
} else if (actual instanceof Boolean) {
Boolean a = (Boolean) actual;
Boolean e = Boolean.valueOf(expected);
if ("==".equals(comparator)) {
return a.equals(e);
} else if ("!=".equals(comparator) || "<>".equals(comparator)) {
return !a.equals(e);
}
} }
return false; return false;

18
json-path/src/test/java/com/jayway/jsonpath/ExpressionEvalTest.java

@ -60,5 +60,23 @@ public class ExpressionEvalTest {
} }
@Test
public void boolean_eval() throws Exception {
assertTrue(ExpressionEvaluator.eval(true, "==", "true"));
assertTrue(ExpressionEvaluator.eval(false, "==", "false"));
assertTrue(ExpressionEvaluator.eval(true, "!=", "false"));
assertTrue(ExpressionEvaluator.eval(true, "<>", "false"));
assertTrue(ExpressionEvaluator.eval(false, "!=", "true"));
assertTrue(ExpressionEvaluator.eval(false, "<>", "true"));
assertFalse(ExpressionEvaluator.eval(true, "==", "false"));
assertFalse(ExpressionEvaluator.eval(false, "==", "true"));
assertFalse(ExpressionEvaluator.eval(true, "!=", "true"));
assertFalse(ExpressionEvaluator.eval(true, "<>", "true"));
assertFalse(ExpressionEvaluator.eval(false, "!=", "false"));
assertFalse(ExpressionEvaluator.eval(false, "<>", "false"));
}
} }

Loading…
Cancel
Save