@Test public void given_two_collections_should_iterate_over_all_elements_after_joining() { Iterable<String> strings = Iterables.join(Arrays.asList("1"), Arrays.asList("2", "3")); int i = 1; for (String s : strings) { Assert.assertEquals(Integer.toString(i++), s); } strings = Iterables.join(Arrays.asList("1", "2"), Arrays.asList("3")); i = 1; for (String s : strings) { Assert.assertEquals(Integer.toString(i++), s); } }
@Test public void given_two_collections_with_one_empty_should_iterate_over_all_elements_of_other_collection() { Iterable<String> strings = Iterables.join(Collections.<String>emptyList(), Arrays.asList("1", "2")); int i = 1; for (String s : strings) { Assert.assertEquals(Integer.toString(i++), s); } strings = Iterables.join(Arrays.asList("1", "2"), Collections.<String>emptyList()); i = 1; for (String s : strings) { Assert.assertEquals(Integer.toString(i++), s); } }
@Test public void given_two_collections_both_empty_should_not_iterate_over_anything() { Iterable<String> strings = Iterables.join(Collections.<String>emptyList(), Collections.<String>emptyList()); for (String s : strings) { Assert.fail("should be no items: " + s); } }