Search in sources :

Example 11 with TextOf

use of org.cactoos.text.TextOf in project cactoos by yegor256.

the class BytesOfTest method closesInputStream.

@Test
void closesInputStream() throws Exception {
    final AtomicBoolean closed = new AtomicBoolean();
    final InputStream input = new ByteArrayInputStream("how are you?".getBytes());
    new TextOf(new InputOf(new InputStream() {

        @Override
        public int read() throws IOException {
            return input.read();
        }

        @Override
        public void close() throws IOException {
            input.close();
            closed.set(true);
        }
    }), StandardCharsets.UTF_8).asString();
    new Assertion<>("must close InputStream correctly", closed.get(), new IsTrue()).affirm();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IsTrue(org.llorllale.cactoos.matchers.IsTrue) TextOf(org.cactoos.text.TextOf) IOException(java.io.IOException) InputOf(org.cactoos.io.InputOf) Test(org.junit.jupiter.api.Test)

Example 12 with TextOf

use of org.cactoos.text.TextOf in project cactoos by yegor256.

the class BytesOfTest method asBytesFromIterator.

@Test
void asBytesFromIterator() throws Exception {
    final Text text = new TextOf("Good bye!");
    new Assertion<>("Can't convert iterator into bytes", new BytesOf(new IteratorOfBytes(text)).asBytes(), new IsEqual<>(new BytesOf(text).asBytes())).affirm();
}
Also used : IteratorOfBytes(org.cactoos.iterator.IteratorOfBytes) Text(org.cactoos.Text) IsText(org.llorllale.cactoos.matchers.IsText) TextOf(org.cactoos.text.TextOf) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.jupiter.api.Test)

Example 13 with TextOf

use of org.cactoos.text.TextOf in project cactoos by yegor256.

the class BytesOfTest method readsLargeInMemoryContent.

@Test
void readsLargeInMemoryContent() throws Exception {
    final int multiplier = 5_000;
    final String body = "1234567890";
    new Assertion<>("must read large content from in-memory Input", new BytesOf(new InputOf(new Concatenated(new HeadOf<>(multiplier, new Endless<>(new TextOf(body)))))).asBytes().length, new IsEqual<>(body.length() * multiplier)).affirm();
}
Also used : Endless(org.cactoos.iterable.Endless) Concatenated(org.cactoos.text.Concatenated) TextOf(org.cactoos.text.TextOf) HasString(org.llorllale.cactoos.matchers.HasString) InputOf(org.cactoos.io.InputOf) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.jupiter.api.Test)

Example 14 with TextOf

use of org.cactoos.text.TextOf in project cactoos by yegor256.

the class TextTest method okForNoNulls.

@Test
void okForNoNulls() {
    final String message = "Hello";
    new Assertion<>("Must work with NoNulls", new NoNulls(new TextOf(message)), new IsText(message)).affirm();
}
Also used : IsText(org.llorllale.cactoos.matchers.IsText) NoNulls(org.cactoos.text.NoNulls) TextOf(org.cactoos.text.TextOf) Test(org.junit.jupiter.api.Test)

Example 15 with TextOf

use of org.cactoos.text.TextOf in project cactoos by yegor256.

the class ReaderOfTest method readsFile.

@Test
public void readsFile() throws Exception {
    final String message = "file on äÄ üÜ öÖ ß жш";
    final File input = this.folder.newFile();
    Files.write(input.toPath(), message.getBytes(StandardCharsets.UTF_8));
    new Assertion<>("Must read from file", new TextOf(new ReaderOf(input)), new IsText(message)).affirm();
}
Also used : IsText(org.llorllale.cactoos.matchers.IsText) TextOf(org.cactoos.text.TextOf) File(java.io.File) Test(org.junit.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