Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve JoinedListIterator code coverage #1762

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/test/java/org/cactoos/list/JoinedListIteratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,48 @@ void joinIterableAndItem() {
new IsEqual<>(new IterableOf<>(1, 2, 3, 0))
).affirm();
}

@Test
void nextIndexTest() {
final ListIterator<Integer> joined = new JoinedListIterator<>(
new ListOf<>(1).listIterator(),
new ListOf<>(2).listIterator(),
new ListOf<>(3).listIterator()
);
new Assertion<>(
"Must return index of the next element",
joined.nextIndex(),
new IsEqual<>(0)
).affirm();
joined.next();
new Assertion<>(
"Must return index of the next element",
joined.nextIndex(),
new IsEqual<>(1)
).affirm();
}

@Test
void previousIndexDoesntExistTest() {
new Assertion<>(
"Must return -1 if there is no previous item",
new JoinedListIterator<>(
new ListOf<>(1).listIterator(),
new ListOf<>(2).listIterator(),
new ListOf<>(3).listIterator()
).previousIndex(),
new IsEqual<>(-1)
).affirm();
}

@Test
void nextThrowsIfThereIsNoNext() {
new Assertion<>(
"Must throw error if there is no next element",
() -> new JoinedListIterator<>().next(),
new Throws<>(
NoSuchElementException.class
)
).affirm();
}
}
Loading