Skip to content

Commit

Permalink
(yegor256#1183) Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoss committed Sep 11, 2020
1 parent 12cb3e8 commit 7277f18
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions src/test/java/org/cactoos/iterable/PagedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@
package org.cactoos.iterable;

import java.util.Iterator;
import java.util.NoSuchElementException;
import org.cactoos.Scalar;
import org.cactoos.iterator.IteratorOf;
import org.cactoos.scalar.LengthOf;
import org.cactoos.scalar.ScalarOfCallable;
import org.cactoos.scalar.Ternary;
import org.hamcrest.collection.IsIterableWithSize;
import org.hamcrest.core.IsEqual;
import org.junit.jupiter.api.Test;
import org.llorllale.cactoos.matchers.Assertion;
import org.llorllale.cactoos.matchers.Throws;

/**
* Test case for {@link Paged}.
Expand All @@ -40,16 +44,15 @@
final class PagedTest {

@Test
@SuppressWarnings({"unchecked", "PMD.AvoidDuplicateLiterals"})
void containAllPagedContentInOrder() throws Exception {
@SuppressWarnings("unchecked")
void containAllPagedContentInOrder() {
final Iterable<String> first = new IterableOf<>("one", "two");
final Iterable<String> second = new IterableOf<>("three", "four");
final Iterable<String> third = new IterableOf<>("five");
final Iterable<Iterable<String>> service = new IterableOf<>(
final Iterator<Iterable<String>> pages = new IteratorOf<>(
first, second, third
);
final Iterator<Iterable<String>> pages = service.iterator();
new Assertion<Iterable<?>>(
new Assertion<Iterable<String>>(
"must have all page values",
new Paged<>(
() -> pages.next().iterator(),
Expand All @@ -65,8 +68,8 @@ void containAllPagedContentInOrder() throws Exception {

@Test
@SuppressWarnings("unchecked")
void reportTotalPagedLength() throws Exception {
final Iterable<String> first = new IterableOf<>("A", "five");
void reportTotalPagedLength() {
final Iterable<String> first = new IterableOf<>("A", "six");
final Iterable<String> second = new IterableOf<>("word", "long");
final Iterable<String> third = new IterableOf<>("sentence");
final Iterable<Iterable<String>> service = new IterableOf<>(
Expand All @@ -93,5 +96,26 @@ void reportTotalPagedLength() throws Exception {
).affirm();
}

@Test
@SuppressWarnings("unchecked")
void throwsNoSuchElement() {
final Iterable<Iterable<String>> service = new IterableOf<>();
final Iterator<Iterable<String>> pages = service.iterator();
new Assertion<Scalar<String>>(
"must throw an exception when first iterator is empty",
new ScalarOfCallable<String>(
() -> new Paged<>(
() -> pages.next().iterator(),
page -> new Ternary<>(
() -> pages.hasNext(),
() -> pages.next().iterator(),
() -> new IteratorOf<String>()
).value()
).iterator().next()
),
new Throws<>(NoSuchElementException.class)
).affirm();
}

}

0 comments on commit 7277f18

Please sign in to comment.