Search in sources :

Example 46 with TextOf

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

the class InputOfTest method readsStringBuilder.

@Test
void readsStringBuilder() throws Exception {
    final String starts = "Name it, ";
    final String ends = "then it exists!";
    new Assertion<>("must receive a string builder", new TextOf(new BytesOf(new InputOf(new StringBuilder(starts).append(ends)))), new AllOf<>(new StartsWith(starts), new EndsWith(ends))).affirm();
}
Also used : BytesOf(org.cactoos.bytes.BytesOf) TextOf(org.cactoos.text.TextOf) HasString(org.llorllale.cactoos.matchers.HasString) StartsWith(org.llorllale.cactoos.matchers.StartsWith) AllOf(org.hamcrest.core.AllOf) EndsWith(org.llorllale.cactoos.matchers.EndsWith) Test(org.junit.jupiter.api.Test)

Example 47 with TextOf

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

the class InputOfTest method readsStringBuffer.

@Test
void readsStringBuffer() throws Exception {
    final String starts = "The future ";
    final String ends = "is now!";
    new Assertion<>("must receive a string buffer", new TextOf(new BytesOf(new InputOf(new StringBuffer(starts).append(ends)))), new AllOf<>(new StartsWith(starts), new EndsWith(ends))).affirm();
}
Also used : BytesOf(org.cactoos.bytes.BytesOf) TextOf(org.cactoos.text.TextOf) HasString(org.llorllale.cactoos.matchers.HasString) StartsWith(org.llorllale.cactoos.matchers.StartsWith) AllOf(org.hamcrest.core.AllOf) EndsWith(org.llorllale.cactoos.matchers.EndsWith) Test(org.junit.jupiter.api.Test)

Example 48 with TextOf

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

the class LoggingInputTest method logResetFromLargeTextFile.

@Test
@SuppressWarnings("unchecked")
void logResetFromLargeTextFile() throws Exception {
    final Logger logger = new FakeLogger();
    final InputStream input = new LoggingInput(new ResourceOf("org/cactoos/large-text.txt"), "text file", logger).stream();
    // @checkstyle MagicNumber (1 line)
    input.mark(150);
    input.reset();
    new Assertion<>("Must log mark and reset from text file", new TextOf(logger.toString()), new AllOf<>(new HasString("Marked position 150 from text file"), new HasString("Reset input stream from text file"))).affirm();
}
Also used : HasString(org.llorllale.cactoos.matchers.HasString) InputStream(java.io.InputStream) TextOf(org.cactoos.text.TextOf) Logger(java.util.logging.Logger) AllOf(org.hamcrest.core.AllOf) Test(org.junit.jupiter.api.Test)

Example 49 with TextOf

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

the class LoggingInputTest method logReadFromText.

@Test
void logReadFromText() throws Exception {
    final Logger logger = new FakeLogger();
    new LengthOf(new LoggingInput(new InputOf("Hello, товарищ!"), "memory", logger)).value();
    new Assertion<>("Must log 22 bytes read from memory", new TextOf(logger.toString()), new HasString("Read 22 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)

Example 50 with TextOf

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

the class LoggingInputTest method logSkipFromLargeTextFile.

@Test
void logSkipFromLargeTextFile() throws Exception {
    final Logger logger = new FakeLogger();
    new LoggingInput(new ResourceOf("org/cactoos/large-text.txt"), "text file", logger).stream().skip(100);
    new Assertion<>("Must log skip from text file", new TextOf(logger.toString()), new HasString("Skipped 100 byte(s) from text file.")).affirm();
}
Also used : HasString(org.llorllale.cactoos.matchers.HasString) 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