Search in sources :

Example 1 with HasString

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

the class RotatedTest method noRotateWhenShiftZero.

@Test
void noRotateWhenShiftZero() {
    final String nonrotate = "Cactoos!";
    new Assertion<>("Rotate text shift zero", new Rotated(new TextOf(nonrotate), 0), new HasString(nonrotate)).affirm();
}
Also used : HasString(org.llorllale.cactoos.matchers.HasString) HasString(org.llorllale.cactoos.matchers.HasString) Test(org.junit.jupiter.api.Test)

Example 2 with HasString

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

Example 3 with HasString

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

the class LoggingInputTest method logReadFromLargeTextFile.

@Test
@SuppressWarnings("unchecked")
void logReadFromLargeTextFile() throws Exception {
    final Logger logger = new FakeLogger();
    new LengthOf(new LoggingInput(new ResourceOf("org/cactoos/large-text.txt"), "text file", logger)).value();
    new Assertion<>("Must log 74536 bytes read from text file", new TextOf(logger.toString()), new AllOf<>(new IsNot<Text>(new HasString("Read 16384 byte(s) from text file")), new HasString("Read 74536 byte(s) from text file in"), new HasString("Closed input stream from text file"))).affirm();
}
Also used : HasString(org.llorllale.cactoos.matchers.HasString) LengthOf(org.cactoos.scalar.LengthOf) TextOf(org.cactoos.text.TextOf) Text(org.cactoos.Text) Logger(java.util.logging.Logger) AllOf(org.hamcrest.core.AllOf) Test(org.junit.jupiter.api.Test)

Example 4 with HasString

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

the class LoggingInputTest method logAllFromLargeTextFile.

@Test
@SuppressWarnings("unchecked")
void logAllFromLargeTextFile() throws Exception {
    final Logger logger = new FakeLogger(Level.WARNING);
    new LengthOf(new LoggingInput(new ResourceOf("org/cactoos/large-text.txt"), "text file", logger)).value();
    new Assertion<>("Must log all read and close operations from text file", new TextOf(logger.toString()), new AllOf<>(new HasString("Read 16384 byte(s) from text file"), new HasString("Read 32768 byte(s) from text file"), new HasString("Read 49152 byte(s) from text file"), new HasString("Read 65536 byte(s) from text file"), new HasString("Read 74536 byte(s) from text file"), new HasString("Closed input stream from text file"))).affirm();
}
Also used : HasString(org.llorllale.cactoos.matchers.HasString) LengthOf(org.cactoos.scalar.LengthOf) TextOf(org.cactoos.text.TextOf) Logger(java.util.logging.Logger) AllOf(org.hamcrest.core.AllOf) Test(org.junit.jupiter.api.Test)

Example 5 with HasString

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

the class LoggingInputTest method logIntoCreatedLogger.

@Test
void logIntoCreatedLogger() throws Exception {
    final FakeHandler handler = new FakeHandler();
    final String src = "my source";
    final Logger logger = Logger.getLogger(src);
    logger.addHandler(handler);
    try {
        new LengthOf(new LoggingInput(new InputOf("Hi there"), src)).value();
        new Assertion<>("", new TextOf(handler.toString()), new HasString("Read 8 byte(s)")).affirm();
    } finally {
        logger.removeHandler(handler);
    }
}
Also used : HasString(org.llorllale.cactoos.matchers.HasString) LengthOf(org.cactoos.scalar.LengthOf) TextOf(org.cactoos.text.TextOf) HasString(org.llorllale.cactoos.matchers.HasString) 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