Search in sources :

Example 6 with TextOf

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)));
}
Also used : UpperText(org.cactoos.text.UpperText) SubText(org.cactoos.text.SubText) TextOf(org.cactoos.text.TextOf) MatcherOf(org.cactoos.matchers.MatcherOf) Test(org.junit.Test)

Example 7 with TextOf

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();
}
Also used : HasValues(org.llorllale.cactoos.matchers.HasValues) ListOf(org.cactoos.list.ListOf) TextOf(org.cactoos.text.TextOf) Test(org.junit.Test)

Example 8 with TextOf

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();
}
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 9 with TextOf

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();
}
Also used : Text(org.cactoos.Text) TextOf(org.cactoos.text.TextOf) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.jupiter.api.Test)

Example 10 with TextOf

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();
}
Also used : Text(org.cactoos.Text) IsText(org.llorllale.cactoos.matchers.IsText) TextOf(org.cactoos.text.TextOf) IterableOfBytes(org.cactoos.iterable.IterableOfBytes) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.jupiter.api.Test)

Aggregations

TextOf (org.cactoos.text.TextOf)74 Test (org.junit.Test)41 Test (org.junit.jupiter.api.Test)32 IsText (org.llorllale.cactoos.matchers.IsText)25 File (java.io.File)20 LengthOf (org.cactoos.scalar.LengthOf)20 HasString (org.llorllale.cactoos.matchers.HasString)17 HasContent (org.llorllale.cactoos.matchers.HasContent)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)14 Logger (java.util.logging.Logger)10 Text (org.cactoos.Text)9 AllOf (org.hamcrest.core.AllOf)7 IsEqual (org.hamcrest.core.IsEqual)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 StringReader (java.io.StringReader)5 Path (java.nio.file.Path)5 MatcherOf (org.cactoos.matchers.MatcherOf)5 InputStream (java.io.InputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 BytesOf (org.cactoos.bytes.BytesOf)4