Skip to content

Commit

Permalink
JEXL-406: added test/example of context methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Henri Biestro committed Sep 22, 2023
1 parent b5c0a18 commit fcf59af
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/test/java/org/apache/commons/jexl3/Issues400Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public void test404b() {
* Overloads are respected.
*/
public static class XuContext extends MapContext {

public String join(Iterator<?> iterator, String str) {
if (!iterator.hasNext()) {
return "";
Expand All @@ -168,6 +169,7 @@ public String join(Iterator<?> iterator, String str) {
}
return strb.toString();
}

public String join(Iterable<?> list, String str) {
return join(list.iterator(), str);
}
Expand Down Expand Up @@ -195,7 +197,7 @@ public void test406() {
"join((1 .. 4), '-')")) {
JexlScript script = jexl.createScript(src);
Object result = script.execute(context);
Assert.assertEquals("1-2-3-4", result);
Assert.assertEquals(src,"1-2-3-4", result);
}

String src0 = "x.join('*')";
Expand All @@ -206,9 +208,9 @@ public void test406() {
Arrays.asList(1, 2, 3, 4),
new int[]{1, 2, 3, 4})) {
Object result = script0.execute(context, x);
Assert.assertEquals("1*2*3*4", result);
Assert.assertEquals(src0, "1*2*3*4", result);
result = script1.execute(context, x);
Assert.assertEquals("1*2*3*4", result);
Assert.assertEquals(src1, "1*2*3*4", result);
}
}
}

0 comments on commit fcf59af

Please sign in to comment.