public void testFromArray() { assertEquals( ImmutableList.of("1", "2", "3", "4"), Lists.newArrayList(FluentIterable.from(new Object[] {"1", "2", "3", "4"}))); }
public void testFrom() { assertEquals( ImmutableList.of(1, 2, 3, 4), Lists.newArrayList(FluentIterable.from(ImmutableList.of(1, 2, 3, 4)))); }
public void testSkip_skipNoneList() { Collection<String> list = Lists.newArrayList("a", "b"); assertEquals( Lists.newArrayList("a", "b"), Lists.newArrayList(FluentIterable.from(list).skip(0))); }
public void testAppend() { FluentIterable<Integer> result = FluentIterable.<Integer>from(asList(1, 2, 3)).append(Lists.newArrayList(4, 5, 6)); assertEquals(asList(1, 2, 3, 4, 5, 6), Lists.newArrayList(result)); assertEquals("[1, 2, 3, 4, 5, 6]", result.toString()); result = FluentIterable.<Integer>from(asList(1, 2, 3)).append(4, 5, 6); assertEquals(asList(1, 2, 3, 4, 5, 6), Lists.newArrayList(result)); assertEquals("[1, 2, 3, 4, 5, 6]", result.toString()); }
public void testSize2NonCollection() { Iterable<Integer> iterable = new Iterable<Integer>() { @Override public Iterator<Integer> iterator() { return asList(0, 1).iterator(); } }; assertEquals(2, FluentIterable.from(iterable).size()); }
public void testConcatVarargs() { List<Integer> list1 = newArrayList(1); List<Integer> list2 = newArrayList(4); List<Integer> list3 = newArrayList(7, 8); List<Integer> list4 = newArrayList(9); List<Integer> list5 = newArrayList(10); @SuppressWarnings("unchecked") FluentIterable<Integer> result = FluentIterable.concat(list1, list2, list3, list4, list5); assertEquals(asList(1, 4, 7, 8, 9, 10), newArrayList(result)); assertEquals("[1, 4, 7, 8, 9, 10]", result.toString()); }
public void testFilter() { FluentIterable<String> filtered = FluentIterable.from(asList("foo", "bar")).filter(Predicates.equalTo("foo")); List<String> expected = Collections.singletonList("foo"); List<String> actual = Lists.newArrayList(filtered); assertEquals(expected, actual); assertCanIterateAgain(filtered); assertEquals("[foo]", filtered.toString()); }
public void testTransformWith_nullFriendlyTransform() { List<Integer> input = asList(1, 2, null, 3); Iterable<String> result = FluentIterable.from(input).transform(new StringValueOfFunction()); assertEquals(asList("1", "2", "null", "3"), Lists.newArrayList(result)); }
public void testTransformWith() { List<String> input = asList("1", "2", "3"); Iterable<Integer> iterable = FluentIterable.from(input).transform(new IntegerValueOfFunction()); assertEquals(asList(1, 2, 3), Lists.newArrayList(iterable)); assertCanIterateAgain(iterable); assertEquals("[1, 2, 3]", iterable.toString()); }
public void testSkip_skipNone() { Collection<String> set = ImmutableSet.of("a", "b"); assertEquals( Lists.newArrayList("a", "b"), Lists.newArrayList(FluentIterable.from(set).skip(0))); }
public void testGet() { assertEquals("a", FluentIterable.from(Lists.newArrayList("a", "b", "c")).get(0)); assertEquals("b", FluentIterable.from(Lists.newArrayList("a", "b", "c")).get(1)); assertEquals("c", FluentIterable.from(Lists.newArrayList("a", "b", "c")).get(2)); }
public void testToString() { assertEquals("[]", FluentIterable.from(Collections.emptyList()).toString()); assertEquals("[]", FluentIterable.<String>of().toString()); assertEquals( "[yam, bam, jam, ham]", FluentIterable.from(asList("yam", "bam", "jam", "ham")).toString()); }
public void testSkip_nonStructurallyModifiedList() throws Exception { List<String> list = Lists.newArrayList("a", "b", "c"); FluentIterable<String> tail = FluentIterable.from(list).skip(1); Iterator<String> tailIterator = tail.iterator(); list.set(2, "c2"); assertEquals("b", tailIterator.next()); assertEquals("c2", tailIterator.next()); assertFalse(tailIterator.hasNext()); }
public void testSkip_simple() { Collection<String> set = ImmutableSet.of("a", "b", "c", "d", "e"); assertEquals( Lists.newArrayList("c", "d", "e"), Lists.newArrayList(FluentIterable.from(set).skip(2))); assertEquals("[c, d, e]", FluentIterable.from(set).skip(2).toString()); }
public void testSkip_simpleList() { Collection<String> list = Lists.newArrayList("a", "b", "c", "d", "e"); assertEquals( Lists.newArrayList("c", "d", "e"), Lists.newArrayList(FluentIterable.from(list).skip(2))); assertEquals("[c, d, e]", FluentIterable.from(list).skip(2).toString()); }
public void testLimit() { Iterable<String> iterable = Lists.newArrayList("foo", "bar", "baz"); FluentIterable<String> limited = FluentIterable.from(iterable).limit(2); assertEquals(ImmutableList.of("foo", "bar"), Lists.newArrayList(limited)); assertCanIterateAgain(limited); assertEquals("[foo, bar]", limited.toString()); }
public void testTransformAndConcat() { List<Integer> input = asList(1, 2, 3); Iterable<String> result = FluentIterable.from(input).transformAndConcat(new RepeatedStringValueOfFunction()); assertEquals(asList("1", "1", "2", "2", "3", "3"), Lists.newArrayList(result)); }
public void testAppend_toEmpty() { FluentIterable<Integer> result = FluentIterable.<Integer>of().append(Lists.newArrayList(1, 2, 3)); assertEquals(asList(1, 2, 3), Lists.newArrayList(result)); }
public void testToSortedList_withDuplicates() { assertEquals( Lists.newArrayList(4, 3, 1, 1), fluent(1, 4, 1, 3).toSortedList(Ordering.<Integer>natural().reverse())); }
public void testToSortedList_withComparator() { assertEquals( Lists.newArrayList(4, 3, 2, 1), fluent(4, 1, 3, 2).toSortedList(Ordering.<Integer>natural().reverse())); }