diff --git a/src/test/java/org/cactoos/iterator/IteratorOfTest.java b/src/test/java/org/cactoos/iterator/IteratorOfTest.java index d7e58c5f0e..64a037a8db 100644 --- a/src/test/java/org/cactoos/iterator/IteratorOfTest.java +++ b/src/test/java/org/cactoos/iterator/IteratorOfTest.java @@ -23,6 +23,7 @@ */ package org.cactoos.iterator; +import java.util.Iterator; import java.util.NoSuchElementException; import org.cactoos.iterable.IterableOf; import org.hamcrest.core.IsNot; @@ -34,9 +35,9 @@ /** * Test case for {@link IteratorOf}. - * * @since 0.30 * @checkstyle JavadocMethodCheck (500 lines) + * @checkstyle ClassDataAbstractionCouplingCheck (500 lines) */ public final class IteratorOfTest { @@ -60,7 +61,12 @@ public void emptyIteratorThrowsException() { @Test public void nonEmptyIteratorDoesNotHaveNext() { - final IteratorOf iterator = this.iteratorWithFetchedElements(); + final Iterator iterator = new IteratorOf<>( + 1, 2, 3 + ); + while (iterator.hasNext()) { + iterator.next(); + } new Assertion<>( "Must create non empty iterator", iterator.hasNext(), @@ -70,9 +76,15 @@ public void nonEmptyIteratorDoesNotHaveNext() { @Test public void nonEmptyIteratorThrowsException() { + final Iterator iterator = new IteratorOf<>( + 'a', 'b' + ); + while (iterator.hasNext()) { + iterator.next(); + } new Assertion<>( "Must throw an exception if consumed", - () -> this.iteratorWithFetchedElements().next(), + () -> iterator.next(), new Throws<>(NoSuchElementException.class) ).affirm(); } @@ -91,18 +103,4 @@ public void convertStringsToIterator() { ) ).affirm(); } - - // @todo #1166:30min According to this Yegor's post - // https://www.yegor256.com/2016/05/03/test-methods-must-share-nothing.html - // test methods must share nothing. Refactor this class by inlining the - // the code below and remove the method below. - private IteratorOf iteratorWithFetchedElements() { - final IteratorOf iterator = new IteratorOf<>( - 1, 2, 3 - ); - iterator.next(); - iterator.next(); - iterator.next(); - return iterator; - } }