use of org.cactoos.text.TextOf in project cactoos by yegor256.
the class SolidMapTest method mapsIterableWithKeyFuncAndValueFunc.
@Test
public void mapsIterableWithKeyFuncAndValueFunc() {
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<>("aa", "bb"));
MatcherAssert.assertThat("Functions are not applied to key and value", map, Matchers.allOf(Matchers.hasEntry(Matchers.equalTo("a"), Matchers.equalTo("AA")), Matchers.hasEntry(Matchers.equalTo("b"), Matchers.equalTo("BB")), new MatcherOf<>(m -> m.size() == 2)));
}
use of org.cactoos.text.TextOf in project cactoos by yegor256.
the class IteratorOfBytesTest method canBeConstructedFromText.
@Test
public void canBeConstructedFromText() throws Exception {
final Iterator<Byte> itr = new IteratorOfBytes(new TextOf("ABC"));
new Assertion<>("Must have 3 elements", new ListOf<Object>(itr.next(), itr.next(), itr.next(), itr.hasNext()), new HasValues<Object>((byte) 'A', (byte) 'B', (byte) 'C', false)).affirm();
}
use of org.cactoos.text.TextOf 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.text.TextOf in project cactoos by yegor256.
the class UncheckedBytesTest method worksNormallyWhenNoExceptionIsThrown.
@Test
void worksNormallyWhenNoExceptionIsThrown() throws Exception {
final Text source = new TextOf("hello, cactoos!");
new Assertion<>("Must work normally when no exception is thrown", new UncheckedBytes(new BytesOf(source)).asBytes(), new IsEqual<>(new BytesOf(source).asBytes())).affirm();
}
use of org.cactoos.text.TextOf in project cactoos by yegor256.
the class BytesOfTest method asBytesFromIterable.
@Test
void asBytesFromIterable() throws Exception {
final Text text = new TextOf("Good bye");
new Assertion<>("Must convert iterable into bytes", new BytesOf(new IterableOfBytes(text)).asBytes(), new IsEqual<>(new BytesOf(text).asBytes())).affirm();
}
Aggregations