Search in sources :

Example 31 with LengthOf

use of org.cactoos.scalar.LengthOf 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 32 with LengthOf

use of org.cactoos.scalar.LengthOf 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)

Example 33 with LengthOf

use of org.cactoos.scalar.LengthOf in project cactoos by yegor256.

the class OutputToTest method writesIntoWriter.

@Test
public void writesIntoWriter() throws Exception {
    final String txt = "Hello, writer!";
    final StringWriter output = new StringWriter();
    new LengthOf(new TeeInput(txt, new OutputTo(output))).value();
    new Assertion<>("Must write into writer", new InputOf(output.getBuffer()), new HasContent(txt)).affirm();
}
Also used : HasContent(org.llorllale.cactoos.matchers.HasContent) StringWriter(java.io.StringWriter) LengthOf(org.cactoos.scalar.LengthOf) Test(org.junit.Test)

Example 34 with LengthOf

use of org.cactoos.scalar.LengthOf in project cactoos by yegor256.

the class OutputToTest method writesIntoWriterWithDecoderAndSize.

@Test
public void writesIntoWriterWithDecoderAndSize() throws Exception {
    final String txt = "Hello, writer with decoder and size!";
    final StringWriter output = new StringWriter();
    new LengthOf(new TeeInput(txt, new OutputTo(output, StandardCharsets.UTF_8.newDecoder(), 1))).value();
    new Assertion<>("Must write into writer with decoder and size", new InputOf(output.getBuffer()), new HasContent(txt)).affirm();
}
Also used : HasContent(org.llorllale.cactoos.matchers.HasContent) StringWriter(java.io.StringWriter) LengthOf(org.cactoos.scalar.LengthOf) Test(org.junit.Test)

Example 35 with LengthOf

use of org.cactoos.scalar.LengthOf in project cactoos by yegor256.

the class OutputToTest method writesIntoWriterWithSize.

@Test
public void writesIntoWriterWithSize() throws Exception {
    final String txt = "Hello, writer with size!";
    final StringWriter output = new StringWriter();
    new LengthOf(new TeeInput(txt, new OutputTo(output, 1))).value();
    new Assertion<>("Must write into writer with size", new InputOf(output.getBuffer()), new HasContent(txt)).affirm();
}
Also used : HasContent(org.llorllale.cactoos.matchers.HasContent) StringWriter(java.io.StringWriter) LengthOf(org.cactoos.scalar.LengthOf) Test(org.junit.Test)

Aggregations

LengthOf (org.cactoos.scalar.LengthOf)103 Test (org.junit.Test)92 HasContent (org.llorllale.cactoos.matchers.HasContent)80 File (java.io.File)75 TextOf (org.cactoos.text.TextOf)20 Test (org.junit.jupiter.api.Test)11 Logger (java.util.logging.Logger)9 StringWriter (java.io.StringWriter)7 HasString (org.llorllale.cactoos.matchers.HasString)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Path (java.nio.file.Path)5 OutputStream (java.io.OutputStream)4 AllOf (org.hamcrest.core.AllOf)4 IsEqual (org.hamcrest.core.IsEqual)4 IsText (org.llorllale.cactoos.matchers.IsText)4 BytesOf (org.cactoos.bytes.BytesOf)3 StringContains (org.hamcrest.core.StringContains)3 OutputStreamWriter (java.io.OutputStreamWriter)2 GZIPOutputStream (java.util.zip.GZIPOutputStream)2 BufferedWriter (java.io.BufferedWriter)1