@Test public void jsonArrayCoercion() throws Exception { addVariable("foo", "first,second"); JSONArray result = evaluate("${foo}", JSONArray.class); JSONArray expected = new JSONArray("['first', 'second']"); assertEquals(expected.toString(), result.toString()); }
@Test @SuppressWarnings("unchecked") public void iterableCoercionOfJSONObjectWithListProperty() throws Exception { addVariable("iter", new JSONObject("{list: [1,2,3]}")); assertEquals(ImmutableList.of(1, 2, 3), ImmutableList.copyOf(evaluate("${iter}", Iterable.class))); }
@Test @SuppressWarnings("unchecked") public void iterableCoercionOfJSONArray() throws Exception { addVariable("iter", new JSONArray("[1,2,3]")); assertEquals(ImmutableList.of(1, 2, 3), ImmutableList.copyOf(evaluate("${iter}", Iterable.class))); }
@Test public void missingMapSubproperty() throws Exception { addVariable("map", ImmutableMap.of("key", "value")); assertNull(evaluate("${map.bar.baz}", Object.class)); }
@Test public void iterableCoercionOfScalar() throws Exception { addVariable("iter", "foo"); assertEquals(ImmutableList.of("foo"), evaluate("${iter}", Iterable.class)); }
@Test public void iterableCoercionOfNull() throws Exception { addVariable("iter", null); assertEquals(ImmutableList.of(), evaluate("${iter}", Iterable.class)); }
@Test public void mapSupport() { addVariable("map", ImmutableMap.of("foo", "bar")); String result = evaluate("${map.foo}${map['foo']}", String.class); assertEquals("barbar", result); }
@Test public void missingJsonSubproperty() throws Exception { addVariable("object", new JSONObject("{foo: 125}")); assertNull(evaluate("${object.bar.baz}", Object.class)); }
@Test public void jsonArraySupport() throws Exception { addVariable("array", new JSONArray("[1, 2]")); int result = evaluate("${array[0] + array[1]}", Integer.class); assertEquals(3, result); }
@Test public void missingJsonSubproperty() throws Exception { addVariable("object", new JSONObject("{foo: 125}")); assertNull(evaluate("${object.bar.baz}", Object.class)); }
@Test public void iterableCoercionOfNull() throws Exception { addVariable("iter", null); assertEquals(ImmutableList.of(), evaluate("${iter}", Iterable.class)); }
@Test public void jsonObjectSupport() throws Exception { addVariable("object", new JSONObject("{foo: 125}")); int result = evaluate("${object.foo}", Integer.class); assertEquals(125, result); }
@Test public void mapSupport() { addVariable("map", ImmutableMap.of("foo", "bar")); String result = evaluate("${map.foo}${map['foo']}", String.class); assertEquals("barbar", result); }
@Test public void missingJsonSubproperty() throws Exception { addVariable("object", new JSONObject("{foo: 125}")); assertNull(evaluate("${object.bar.baz}", Object.class)); }
@Test public void listSupport() { addVariable("list", ImmutableList.of("foo", "bar")); String result = evaluate("${list[0]}${list[1]}", String.class); assertEquals("foobar", result); }
@Test public void missingJsonSubproperty() throws Exception { addVariable("object", new JSONObject("{foo: 125}")); assertNull(evaluate("${object.bar.baz}", Object.class)); }
@Test public void booleanCoercionOfNumbers() throws Exception{ // Negation tests have been moved to EL subdir addVariable("bool", 0); assertFalse(evaluate("${bool}", Boolean.class)); addVariable("bool", 1); assertTrue(evaluate("${bool}", Boolean.class)); }
@Test public void arraySupport() { addVariable("array", new String[]{"foo", "bar"}); String result = evaluate("${array[0]}${array[1]}", String.class); assertEquals("foobar", result); }
@Test public void booleanCoercionOfNull() throws Exception{ addVariable("bool", null); assertFalse(evaluate("${bool}", Boolean.class)); assertTrue(evaluate("${!bool}", Boolean.class)); }
@Test public void booleanCoercionOfNull() throws Exception{ addVariable("bool", null); assertFalse(evaluate("${bool}", Boolean.class)); assertTrue(evaluate("${!bool}", Boolean.class)); }