aboutsummaryrefslogtreecommitdiffstats
path: root/guava-tests/test/com/google/common/collect/IteratorsTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'guava-tests/test/com/google/common/collect/IteratorsTest.java')
-rw-r--r--guava-tests/test/com/google/common/collect/IteratorsTest.java96
1 files changed, 28 insertions, 68 deletions
diff --git a/guava-tests/test/com/google/common/collect/IteratorsTest.java b/guava-tests/test/com/google/common/collect/IteratorsTest.java
index 4c348f6..60f3a3a 100644
--- a/guava-tests/test/com/google/common/collect/IteratorsTest.java
+++ b/guava-tests/test/com/google/common/collect/IteratorsTest.java
@@ -16,15 +16,15 @@
package com.google.common.collect;
-import static com.google.common.collect.Iterators.advance;
import static com.google.common.collect.Iterators.get;
import static com.google.common.collect.Iterators.getLast;
+import static com.google.common.collect.Iterators.skip;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.testing.IteratorFeature.MODIFIABLE;
import static com.google.common.collect.testing.IteratorFeature.UNMODIFIABLE;
import static java.util.Arrays.asList;
import static java.util.Collections.singleton;
-import static org.truth0.Truth.ASSERT;
+import static org.junit.contrib.truth.Truth.ASSERT;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
@@ -44,6 +44,7 @@ import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -51,7 +52,6 @@ import java.util.ConcurrentModificationException;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
-import java.util.ListIterator;
import java.util.NoSuchElementException;
import java.util.RandomAccess;
import java.util.Set;
@@ -88,39 +88,6 @@ public class IteratorsTest extends TestCase {
}
}
- public void testEmptyListIterator() {
- ListIterator<String> iterator = Iterators.emptyListIterator();
- assertFalse(iterator.hasNext());
- assertFalse(iterator.hasPrevious());
- assertEquals(0, iterator.nextIndex());
- assertEquals(-1, iterator.previousIndex());
- try {
- iterator.next();
- fail("no exception thrown");
- } catch (NoSuchElementException expected) {
- }
- try {
- iterator.previous();
- fail("no exception thrown");
- } catch (NoSuchElementException expected) {
- }
- try {
- iterator.remove();
- fail("no exception thrown");
- } catch (UnsupportedOperationException expected) {
- }
- try {
- iterator.set("a");
- fail("no exception thrown");
- } catch (UnsupportedOperationException expected) {
- }
- try {
- iterator.add("a");
- fail("no exception thrown");
- } catch (UnsupportedOperationException expected) {
- }
- }
-
public void testSize0() {
Iterator<String> iterator = Iterators.emptyIterator();
assertEquals(0, Iterators.size(iterator));
@@ -750,7 +717,7 @@ public class IteratorsTest extends TestCase {
boolean changed = Iterators.addAll(alreadyThere,
Iterators.<String>emptyIterator());
- ASSERT.that(alreadyThere).has().allOf("already", "there").inOrder();
+ ASSERT.that(alreadyThere).hasContentsInOrder("already", "there");
assertFalse(changed);
}
@@ -760,7 +727,7 @@ public class IteratorsTest extends TestCase {
boolean changed = Iterators.addAll(alreadyThere, freshlyAdded.iterator());
- ASSERT.that(alreadyThere).has().allOf("already", "there", "freshly", "added");
+ ASSERT.that(alreadyThere).hasContentsInOrder("already", "there", "freshly", "added");
assertTrue(changed);
}
@@ -770,12 +737,12 @@ public class IteratorsTest extends TestCase {
List<String> oneMore = Lists.newArrayList("there");
boolean changed = Iterators.addAll(alreadyThere, oneMore.iterator());
- ASSERT.that(alreadyThere).has().allOf("already", "there").inOrder();
+ ASSERT.that(alreadyThere).hasContentsInOrder("already", "there");
assertFalse(changed);
}
@GwtIncompatible("NullPointerTester")
- public void testNullPointerExceptions() {
+ public void testNullPointerExceptions() throws Exception {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(Iterators.class);
}
@@ -1032,29 +999,29 @@ public class IteratorsTest extends TestCase {
public void testForArrayOffset() {
String[] array = {"foo", "bar", "cat", "dog"};
- Iterator<String> iterator = Iterators.forArray(array, 1, 2, 0);
+ Iterator<String> iterator = Iterators.forArray(array, 1, 2);
assertTrue(iterator.hasNext());
assertEquals("bar", iterator.next());
assertTrue(iterator.hasNext());
assertEquals("cat", iterator.next());
assertFalse(iterator.hasNext());
try {
- Iterators.forArray(array, 2, 3, 0);
+ Iterators.forArray(array, 2, 3);
fail();
} catch (IndexOutOfBoundsException expected) {}
}
public void testForArrayLength0() {
String[] array = {"foo", "bar"};
- assertFalse(Iterators.forArray(array, 0, 0, 0).hasNext());
- assertFalse(Iterators.forArray(array, 1, 0, 0).hasNext());
- assertFalse(Iterators.forArray(array, 2, 0, 0).hasNext());
+ assertFalse(Iterators.forArray(array, 0, 0).hasNext());
+ assertFalse(Iterators.forArray(array, 1, 0).hasNext());
+ assertFalse(Iterators.forArray(array, 2, 0).hasNext());
try {
- Iterators.forArray(array, -1, 0, 0);
+ Iterators.forArray(array, -1, 0);
fail();
} catch (IndexOutOfBoundsException expected) {}
try {
- Iterators.forArray(array, 3, 0, 0);
+ Iterators.forArray(array, 3, 0);
fail();
} catch (IndexOutOfBoundsException expected) {}
}
@@ -1074,7 +1041,7 @@ public class IteratorsTest extends TestCase {
new IteratorTester<Integer>(6, UNMODIFIABLE, asList(1, 2, 3),
IteratorTester.KnownOrder.KNOWN_ORDER) {
@Override protected Iterator<Integer> newTargetIterator() {
- return Iterators.forArray(new Integer[] { 0, 1, 2, 3, 4 }, 1, 3, 0);
+ return Iterators.forArray(new Integer[] { 0, 1, 2, 3, 4 }, 1, 3);
}
}.test();
}
@@ -1171,18 +1138,11 @@ public class IteratorsTest extends TestCase {
}
public void testToString() {
- Iterator<String> iterator = Lists.newArrayList("yam", "bam", "jam", "ham").iterator();
- assertEquals("[yam, bam, jam, ham]", Iterators.toString(iterator));
- }
+ List<String> list = Collections.emptyList();
+ assertEquals("[]", Iterators.toString(list.iterator()));
- public void testToStringWithNull() {
- Iterator<String> iterator = Lists.newArrayList("hello", null, "world").iterator();
- assertEquals("[hello, null, world]", Iterators.toString(iterator));
- }
-
- public void testToStringEmptyIterator() {
- Iterator<String> iterator = Collections.<String>emptyList().iterator();
- assertEquals("[]", Iterators.toString(iterator));
+ list = Lists.newArrayList("yam", "bam", "jam", "ham");
+ assertEquals("[yam, bam, jam, ham]", Iterators.toString(list.iterator()));
}
public void testLimit() {
@@ -1382,29 +1342,29 @@ public class IteratorsTest extends TestCase {
assertTrue(iterator.hasNext());
}
- public void testAdvance_basic() {
+ public void testSkip_basic() {
List<String> list = newArrayList();
list.add("a");
list.add("b");
Iterator<String> iterator = list.iterator();
- advance(iterator, 1);
+ skip(iterator, 1);
assertEquals("b", iterator.next());
}
- public void testAdvance_pastEnd() {
+ public void testSkip_pastEnd() {
List<String> list = newArrayList();
list.add("a");
list.add("b");
Iterator<String> iterator = list.iterator();
- advance(iterator, 5);
+ skip(iterator, 5);
assertFalse(iterator.hasNext());
}
- public void testAdvance_illegalArgument() {
+ public void testSkip_illegalArgument() {
List<String> list = newArrayList("a", "b", "c");
Iterator<String> iterator = list.iterator();
try {
- advance(iterator, -1);
+ skip(iterator, -1);
fail();
} catch (IllegalArgumentException expected) {}
}
@@ -1506,12 +1466,12 @@ public class IteratorsTest extends TestCase {
Iterator<String> consumingIterator =
Iterators.consumingIterator(list.iterator());
- ASSERT.that(list).has().allOf("a", "b").inOrder();
+ ASSERT.that(list).hasContentsInOrder("a", "b");
assertTrue(consumingIterator.hasNext());
- ASSERT.that(list).has().allOf("a", "b").inOrder();
+ ASSERT.that(list).hasContentsInOrder("a", "b");
assertEquals("a", consumingIterator.next());
- ASSERT.that(list).has().item("b");
+ ASSERT.that(list).hasContentsInOrder("b");
assertTrue(consumingIterator.hasNext());
assertEquals("b", consumingIterator.next());