From 33f2b153a14e981e9bb1bc3dbc916c66dac00837 Mon Sep 17 00:00:00 2001 From: Jonathan Bluett-Duncan Date: Fri, 16 Oct 2020 11:13:03 -0700 Subject: [PATCH] Update IteratorTester example with a greater "steps" value This allows IteratorTester to check the edge case that when an iterator has been exhausted (that is, "next" has been called repeatedly until "hasNext" returns false) then calling "next" on the iterator again exhibits the same behavior as the user's chosen "known good" reference implementation. Fixes #5281 RELNOTES=n/a ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=337541752 --- .../com/google/common/collect/testing/IteratorTester.java | 7 +++++-- .../com/google/common/collect/testing/IteratorTester.java | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/android/guava-testlib/src/com/google/common/collect/testing/IteratorTester.java b/android/guava-testlib/src/com/google/common/collect/testing/IteratorTester.java index 111d337e1521..fdc418a73745 100644 --- a/android/guava-testlib/src/com/google/common/collect/testing/IteratorTester.java +++ b/android/guava-testlib/src/com/google/common/collect/testing/IteratorTester.java @@ -50,6 +50,9 @@ * verify() method, which is called after each sequence and is guaranteed to be called * using the latest values obtained from {@link IteratorTester#newTargetIterator()}. * + *

The value you pass to the parameter {@code steps} should be greater than the length of your + * iterator, so that this class can check that your iterator behaves correctly when it is exhausted. + * *

For example, to test {@link java.util.Collections#unmodifiableList(java.util.List) * Collections.unmodifiableList}'s iterator: * @@ -61,7 +64,7 @@ * Arrays.asList("a", "b", "c", "d", "e")); * IteratorTester iteratorTester = * new IteratorTester( - * 5, + * 6, * IteratorFeature.UNMODIFIABLE, * expectedElements, * IteratorTester.KnownOrder.KNOWN_ORDER) { @@ -75,7 +78,7 @@ * } * *

Note: It is necessary to use {@code IteratorTester.KnownOrder} as shown above, rather - * than {@code KnownOrder} directly, because otherwise the code is not compilable. + * than {@code KnownOrder} directly, because otherwise the code cannot be compiled. * * @author Kevin Bourrillion * @author Chris Povirk diff --git a/guava-testlib/src/com/google/common/collect/testing/IteratorTester.java b/guava-testlib/src/com/google/common/collect/testing/IteratorTester.java index 111d337e1521..fdc418a73745 100644 --- a/guava-testlib/src/com/google/common/collect/testing/IteratorTester.java +++ b/guava-testlib/src/com/google/common/collect/testing/IteratorTester.java @@ -50,6 +50,9 @@ * verify() method, which is called after each sequence and is guaranteed to be called * using the latest values obtained from {@link IteratorTester#newTargetIterator()}. * + *

The value you pass to the parameter {@code steps} should be greater than the length of your + * iterator, so that this class can check that your iterator behaves correctly when it is exhausted. + * *

For example, to test {@link java.util.Collections#unmodifiableList(java.util.List) * Collections.unmodifiableList}'s iterator: * @@ -61,7 +64,7 @@ * Arrays.asList("a", "b", "c", "d", "e")); * IteratorTester iteratorTester = * new IteratorTester( - * 5, + * 6, * IteratorFeature.UNMODIFIABLE, * expectedElements, * IteratorTester.KnownOrder.KNOWN_ORDER) { @@ -75,7 +78,7 @@ * } * *

Note: It is necessary to use {@code IteratorTester.KnownOrder} as shown above, rather - * than {@code KnownOrder} directly, because otherwise the code is not compilable. + * than {@code KnownOrder} directly, because otherwise the code cannot be compiled. * * @author Kevin Bourrillion * @author Chris Povirk