Skip to content

Commit

Permalink
Fix example in documentation for IteratorTester
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jbduncan authored and cpovirk committed Oct 13, 2020
1 parent 2ebf27f commit e3dc2a7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Expand Up @@ -50,19 +50,21 @@
* verify() method, which is called <em>after</em> each sequence and is guaranteed to be called
* using the latest values obtained from {@link IteratorTester#newTargetIterator()}.
*
* <p>For example, to test {@link java.util.ArrayList#iterator() ArrayList.iterator()}:
* <p>For example, to test {@link java.util.Collections#unmodifiableList(java.util.List)
* Collections.unmodifiableList}'s iterator:
*
* <pre>{@code
* List<String> expectedElements =
* Arrays.asList("a", "b", "c", "d", "e");
* List<String> actualElements =
* new ArrayList<>(Arrays.asList("a", "b", "c", "d", "e"));
* Collections.unmodifiableList(
* Arrays.asList("a", "b", "c", "d", "e"));
* IteratorTester<String> iteratorTester =
* new IteratorTester<String>(
* 5,
* IteratorFeature.MODIFIABLE,
* IteratorFeature.UNMODIFIABLE,
* expectedElements,
* KnownOrder.KNOWN_ORDER) {
* IteratorTester.KnownOrder.KNOWN_ORDER) {
* @Override
* protected Iterator<String> newTargetIterator() {
* return actualElements.iterator();
Expand All @@ -72,6 +74,9 @@
* iteratorTester.testForEachRemaining();
* }</pre>
*
* <p><b>Note</b>: 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
*/
Expand Down
Expand Up @@ -50,19 +50,21 @@
* verify() method, which is called <em>after</em> each sequence and is guaranteed to be called
* using the latest values obtained from {@link IteratorTester#newTargetIterator()}.
*
* <p>For example, to test {@link java.util.ArrayList#iterator() ArrayList.iterator()}:
* <p>For example, to test {@link java.util.Collections#unmodifiableList(java.util.List)
* Collections.unmodifiableList}'s iterator:
*
* <pre>{@code
* List<String> expectedElements =
* Arrays.asList("a", "b", "c", "d", "e");
* List<String> actualElements =
* new ArrayList<>(Arrays.asList("a", "b", "c", "d", "e"));
* Collections.unmodifiableList(
* Arrays.asList("a", "b", "c", "d", "e"));
* IteratorTester<String> iteratorTester =
* new IteratorTester<String>(
* 5,
* IteratorFeature.MODIFIABLE,
* IteratorFeature.UNMODIFIABLE,
* expectedElements,
* KnownOrder.KNOWN_ORDER) {
* IteratorTester.KnownOrder.KNOWN_ORDER) {
* @Override
* protected Iterator<String> newTargetIterator() {
* return actualElements.iterator();
Expand All @@ -72,6 +74,9 @@
* iteratorTester.testForEachRemaining();
* }</pre>
*
* <p><b>Note</b>: 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
*/
Expand Down

0 comments on commit e3dc2a7

Please sign in to comment.