JoinOnComma implements Function<Object, String> { public String apply(Object o) { checkNotNull(o, "input cannot be null"); if (o.getClass().isArray()) { Builder<Object> builder = ImmutableList.builder(); for (int i = 0; i < Array.getLength(o); i++) builder.add(Array.get(o, i)); o = builder.build(); } checkArgument(o instanceof Iterable<?>, "you must pass an iterable or array"); Iterable<?> toJoin = (Iterable<?>) o; checkArgument(Iterables.size(toJoin) > 0, "you must pass an iterable or array with elements"); return Joiner.on(',').join(toJoin); }  String apply(Object o);  }
@Test public void testIterableLong() { String list = new JoinOnComma().apply(ImmutableList.of(1l, 2l)); assertEquals(list, "1,2"); }
@Test public void testLongArray() { String list = new JoinOnComma().apply(new long[] { 1l, 2l }); assertEquals(list, "1,2"); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testEmptyArrayIllegalArgumentException() { new JoinOnComma().apply(new long[] {}); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testEmptyIterableIllegalArgumentException() { new JoinOnComma().apply(ImmutableList.of()); }
@Test(expectedExceptions = NullPointerException.class) public void testNullPointer() { new JoinOnComma().apply(null); }