From e3dc2a7a0f3d89b595f6bb3b944bbe996e3824fe Mon Sep 17 00:00:00 2001 From: Jonathan Bluett-Duncan Date: Tue, 13 Oct 2020 10:55:23 -0700 Subject: Fix example in documentation for `IteratorTester` I made a mistake and accidentally included an example that does not compile. Specifically, importing `KnownOrder` as-is does not compile; instead one needs to import `IteratorTester.KnownOrder`. See #5254 for more information. I also changed the example to use `Collections#unmodifiableList` rather than `ArrayList` because `ArrayList#iterator` does not satisfy all the requirements of `IteratorFeature#MODIFIABLE`. Fixes #5276 RELNOTES=n/a ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=336911192 --- .../com/google/common/collect/testing/IteratorTester.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'android') 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 1e7f44647..111d337e1 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,19 +50,21 @@ import java.util.Iterator; * verify() method, which is called after each sequence and is guaranteed to be called * using the latest values obtained from {@link IteratorTester#newTargetIterator()}. * - *

For example, to test {@link java.util.ArrayList#iterator() ArrayList.iterator()}: + *

For example, to test {@link java.util.Collections#unmodifiableList(java.util.List) + * Collections.unmodifiableList}'s iterator: * *

{@code
  * List expectedElements =
  *     Arrays.asList("a", "b", "c", "d", "e");
  * List actualElements =
- *     new ArrayList<>(Arrays.asList("a", "b", "c", "d", "e"));
+ *     Collections.unmodifiableList(
+ *         Arrays.asList("a", "b", "c", "d", "e"));
  * IteratorTester iteratorTester =
  *     new IteratorTester(
  *         5,
- *         IteratorFeature.MODIFIABLE,
+ *         IteratorFeature.UNMODIFIABLE,
  *         expectedElements,
- *         KnownOrder.KNOWN_ORDER) {
+ *         IteratorTester.KnownOrder.KNOWN_ORDER) {
  *       @Override
  *       protected Iterator newTargetIterator() {
  *         return actualElements.iterator();
@@ -72,6 +74,9 @@ import java.util.Iterator;
  * iteratorTester.testForEachRemaining();
  * }
* + *

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