Search in sources :

Example 1 with IterableOf

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));
}
Also used : UpperText(org.cactoos.text.UpperText) MatcherAssert(org.hamcrest.MatcherAssert) Map(java.util.Map) IterableOf(org.cactoos.iterable.IterableOf) Matchers(org.hamcrest.Matchers) TextOf(org.cactoos.text.TextOf) Test(org.junit.Test) SubText(org.cactoos.text.SubText) Scalar(org.cactoos.Scalar) MatcherOf(org.cactoos.matchers.MatcherOf) RunsInThreads(org.cactoos.matchers.RunsInThreads) UpperText(org.cactoos.text.UpperText) SubText(org.cactoos.text.SubText) TextOf(org.cactoos.text.TextOf) Test(org.junit.Test)

Example 2 with IterableOf

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();
}
Also used : IterableOf(org.cactoos.iterable.IterableOf) Text(org.cactoos.Text) FormattedText(org.cactoos.text.FormattedText) FormattedText(org.cactoos.text.FormattedText) Throws(org.llorllale.cactoos.matchers.Throws) Test(org.junit.jupiter.api.Test)

Example 3 with IterableOf

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();
}
Also used : HasValues(org.llorllale.cactoos.matchers.HasValues) IterableOf(org.cactoos.iterable.IterableOf) ArrayList(java.util.ArrayList) Text(org.cactoos.Text) FormattedText(org.cactoos.text.FormattedText) TextOf(org.cactoos.text.TextOf) FormattedText(org.cactoos.text.FormattedText) Test(org.junit.jupiter.api.Test)

Example 4 with IterableOf

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));
}
Also used : List(java.util.List) MatcherAssert(org.hamcrest.MatcherAssert) HasSize(org.llorllale.cactoos.matchers.HasSize) IsEqual(org.hamcrest.core.IsEqual) IterableOf(org.cactoos.iterable.IterableOf) Test(org.junit.Test) Collections(java.util.Collections) Mapped(org.cactoos.iterable.Mapped) IterableOf(org.cactoos.iterable.IterableOf) HasSize(org.llorllale.cactoos.matchers.HasSize) Test(org.junit.Test)

Aggregations

IterableOf (org.cactoos.iterable.IterableOf)4 Text (org.cactoos.Text)2 FormattedText (org.cactoos.text.FormattedText)2 TextOf (org.cactoos.text.TextOf)2 MatcherAssert (org.hamcrest.MatcherAssert)2 Test (org.junit.Test)2 Test (org.junit.jupiter.api.Test)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Scalar (org.cactoos.Scalar)1 Mapped (org.cactoos.iterable.Mapped)1 MatcherOf (org.cactoos.matchers.MatcherOf)1 RunsInThreads (org.cactoos.matchers.RunsInThreads)1 SubText (org.cactoos.text.SubText)1 UpperText (org.cactoos.text.UpperText)1 Matchers (org.hamcrest.Matchers)1 IsEqual (org.hamcrest.core.IsEqual)1 HasSize (org.llorllale.cactoos.matchers.HasSize)1