Search in sources :

Example 16 with TextOf

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

the class ReaderOfTest method readsUri.

@Test
public void readsUri() throws Exception {
    final String message = "URI on äÄ üÜ öÖ ß жш";
    final File input = this.folder.newFile();
    Files.write(input.toPath(), message.getBytes(StandardCharsets.UTF_8));
    new Assertion<>("Must read from uri", new TextOf(new ReaderOf(input.toURI())), 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)

Example 17 with TextOf

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

the class InputOfTest method readsStringFromReader.

@Test
void readsStringFromReader() throws Exception {
    final String source = "hello, source!";
    new Assertion<>("must read string through a reader", new TextOf(new InputOf(new StringReader(source))), new IsText(source)).affirm();
}
Also used : StringReader(java.io.StringReader) IsText(org.llorllale.cactoos.matchers.IsText) TextOf(org.cactoos.text.TextOf) HasString(org.llorllale.cactoos.matchers.HasString) Test(org.junit.jupiter.api.Test)

Example 18 with TextOf

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

the class InputOfTest 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);
        }
    })).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) Test(org.junit.jupiter.api.Test)

Example 19 with TextOf

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

the class InputOfTest method readsEncodedStringFromReader.

@Test
void readsEncodedStringFromReader() throws Exception {
    final String source = "hello, друг!";
    new Assertion<>("must read encoded string through a reader", new TextOf(new BytesOf(new InputOf(new StringReader(source), StandardCharsets.UTF_8))), new IsText(source)).affirm();
}
Also used : BytesOf(org.cactoos.bytes.BytesOf) StringReader(java.io.StringReader) IsText(org.llorllale.cactoos.matchers.IsText) TextOf(org.cactoos.text.TextOf) HasString(org.llorllale.cactoos.matchers.HasString) Test(org.junit.jupiter.api.Test)

Example 20 with TextOf

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

the class LoggingInputTest method logReadFromOneByte.

@Test
void logReadFromOneByte() throws Exception {
    final Logger logger = new FakeLogger();
    new LengthOf(new LoggingInput(new InputOf("a"), "memory", logger)).value();
    new Assertion<>("Must log one byte read from memory", new TextOf(logger.toString()), new HasString("Read 1 byte(s) from memory in")).affirm();
}
Also used : HasString(org.llorllale.cactoos.matchers.HasString) LengthOf(org.cactoos.scalar.LengthOf) TextOf(org.cactoos.text.TextOf) Logger(java.util.logging.Logger) 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