Search in sources :

Example 51 with TextOf

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

the class LoggingInputTest method logReadFromDeadInput.

@Test
void logReadFromDeadInput() throws Exception {
    final Logger logger = new FakeLogger();
    new LengthOf(new LoggingInput(new DeadInput(), "dead input", logger)).value();
    new Assertion<>("Must log zero byte read from dead input", new TextOf(logger.toString()), new HasString("Read 0 byte(s) from dead input 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 52 with TextOf

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

the class LoggingInputTest method logMarkSupportedFromLargeTextFile.

@Test
void logMarkSupportedFromLargeTextFile() throws Exception {
    final Logger logger = new FakeLogger();
    new LoggingInput(new ResourceOf("org/cactoos/large-text.txt"), "text file", logger).stream().markSupported();
    new Assertion<>("Must log mark and reset are not supported from text file", new TextOf(logger.toString()), new HasString("Mark and reset are supported 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)

Example 53 with TextOf

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

the class LoggingInputTest method logAvailableFromLargeTextFile.

@Test
void logAvailableFromLargeTextFile() throws Exception {
    final Logger logger = new FakeLogger();
    new LoggingInput(new ResourceOf("org/cactoos/large-text.txt"), "text file", logger).stream().available();
    new Assertion<>("Must log avaliable byte(s) from text file", new TextOf(logger.toString()), new HasString("There is(are) 74536 byte(s) available 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)

Example 54 with TextOf

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

the class SlowInputTest method calculatesLength.

@Test
void calculatesLength() throws Exception {
    final String text = "What's up, друг?";
    new Assertion<>("Can't calculate the length of Input", new LengthOf(new SlowInput(new InputOf(new TextOf(text)))), new HasValue<>((long) text.getBytes(StandardCharsets.UTF_8).length)).affirm();
}
Also used : LengthOf(org.cactoos.scalar.LengthOf) TextOf(org.cactoos.text.TextOf) HasValue(org.llorllale.cactoos.matchers.HasValue) Test(org.junit.jupiter.api.Test)

Example 55 with TextOf

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

the class CloseShieldOutputStreamTest method writesContentToFile.

@Test
void writesContentToFile(@TempDir final Path tempdir) throws IOException {
    final File file = new File(tempdir.toFile(), "cactoos-1.txt-1");
    file.createNewFile();
    final Path temp = file.toPath();
    try (OutputStream out = new OutputStreamTo(temp)) {
        new Assertion<>("Must copy Input to Output and return Input", new TextOf(new Sticky(new TeeInput(new ResourceOf("org/cactoos/small-text.txt"), new OutputTo(new CloseShieldOutputStream(out))))), new IsText(new TextOf(temp))).affirm();
    }
}
Also used : Path(java.nio.file.Path) OutputStream(java.io.OutputStream) IsText(org.llorllale.cactoos.matchers.IsText) TextOf(org.cactoos.text.TextOf) File(java.io.File) 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