JoinFunction implements DDMExpressionFunction.Function1<JSONArray, String> { @Override public String apply(JSONArray jsonArray) { StringBundler sb = new StringBundler((jsonArray.length() * 2) - 1); for (int i = 0; i < jsonArray.length(); i++) { sb.append(GetterUtil.getString(jsonArray.get(i))); if (i < (jsonArray.length() - 1)) { sb.append(CharPool.COMMA); } } return sb.toString(); }  @Override String apply(JSONArray jsonArray); @Override String getName(); static final String NAME; }
@Test public void testArray() { JSONArray jsonArray = new JSONArrayImpl(); jsonArray.put( "value1" ).put( "value2" ); JoinFunction joinFunction = new JoinFunction(); String actual = joinFunction.apply(jsonArray); Assert.assertEquals("value1,value2", actual); }
@Test public void testEmptyArray() { JSONArray jsonArray = new JSONArrayImpl(); JoinFunction joinFunction = new JoinFunction(); String actual = joinFunction.apply(jsonArray); Assert.assertEquals(StringPool.BLANK, actual); }
@Test public void testSingleValue() { JSONArray jsonArray = new JSONArrayImpl(); jsonArray.put("value1"); JoinFunction joinFunction = new JoinFunction(); String actual = joinFunction.apply(jsonArray); Assert.assertEquals("value1", actual); }