use of org.cactoos.iterable.IterableOf in project cactoos by yegor256.
the class SolidMapTest method mapsEmptyIterableWithKeyFuncAndValueFunc.
@Test
public void mapsEmptyIterableWithKeyFuncAndValueFunc() {
final SolidMap<String, String> map = new SolidMap<>(key -> new SubText(new TextOf(key), 0, 1).asString(), value -> new UpperText(new TextOf(value)).asString(), new IterableOf<String>());
MatcherAssert.assertThat("Empty Iterable cannot be accepted for key and value mapping", map, new MatcherOf<>(m -> m.size() == 0));
}
use of org.cactoos.iterable.IterableOf in project cactoos by yegor256.
the class MappedWithIndexTest method failsIfIteratorExhausted.
@Test
void failsIfIteratorExhausted() {
final Iterator<Text> iterator = new MappedWithIndex<>((item, index) -> new FormattedText("%1$s X %2$s", index, item), new IterableOf<>("1").iterator());
iterator.next();
new Assertion<>("must throw NSEE", iterator::next, new Throws<>(NoSuchElementException.class)).affirm();
}
use of org.cactoos.iterable.IterableOf in project cactoos by yegor256.
the class MappedWithIndexTest method removingElementsFromIterator.
@Test
void removingElementsFromIterator() {
final Iterator<Text> iterator = new MappedWithIndex<>((item, index) -> new FormattedText("%1$s : %2$s", index, item), new ArrayList<>(Arrays.asList("1", "2", "3")).iterator());
iterator.next();
iterator.remove();
new Assertion<>("must map values of changed iterator", new IterableOf<>(iterator), new HasValues<>(new TextOf("1 : 2"), new TextOf("2 : 3"))).affirm();
}
use of org.cactoos.iterable.IterableOf in project cactoos by yegor256.
the class ListOfTest method makesListFromMappedIterable.
@Test
public void makesListFromMappedIterable() throws Exception {
final List<Integer> list = new ListOf<>(new Mapped<Integer>(i -> i + 1, new IterableOf<>(1, -1, 0, 1)));
MatcherAssert.assertThat("Can't turn a mapped iterable into a list", list, new HasSize(4));
MatcherAssert.assertThat("Can't turn a mapped iterable into a list, again", list, new HasSize(4));
}
Aggregations