Search in sources :

Example 6 with HasString

use of org.llorllale.cactoos.matchers.HasString in project cactoos by yegor256.

the class HeadOfTest method readsHeadOfShorterInput.

@Test
void readsHeadOfShorterInput() throws Exception {
    final String input = "readsHeadOfShorterInput";
    new Assertion<>("must limit to at most the number of available bytes", new TextOf(new HeadOf(new InputOf(input), 35)), new HasString(input)).affirm();
}
Also used : HasString(org.llorllale.cactoos.matchers.HasString) TextOf(org.cactoos.text.TextOf) HasString(org.llorllale.cactoos.matchers.HasString) Test(org.junit.jupiter.api.Test)

Example 7 with HasString

use of org.llorllale.cactoos.matchers.HasString 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 8 with HasString

use of org.llorllale.cactoos.matchers.HasString 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 9 with HasString

use of org.llorllale.cactoos.matchers.HasString 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)

Example 10 with HasString

use of org.llorllale.cactoos.matchers.HasString 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)

Aggregations

Test (org.junit.jupiter.api.Test)14 HasString (org.llorllale.cactoos.matchers.HasString)14 TextOf (org.cactoos.text.TextOf)11 Logger (java.util.logging.Logger)10 LengthOf (org.cactoos.scalar.LengthOf)6 AllOf (org.hamcrest.core.AllOf)3 InputStream (java.io.InputStream)1 Text (org.cactoos.Text)1