Search in sources :

Example 71 with LengthOf

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

the class TeeInputFromReaderTest method copiesFromReaderWithCharsetByNameAndSizeToOutput.

@Test
public void copiesFromReaderWithCharsetByNameAndSizeToOutput() throws Exception {
    final String input = "Hello, товарищ output #6 äÄ üÜ öÖ and ß";
    final File output = this.folder.newFile();
    new LengthOf(new TeeInput(new ReaderOf(input), new OutputTo(output), StandardCharsets.UTF_8.name(), input.length())).value();
    new Assertion<>("Must copy from reader with charset by name and size to output.", new InputOf(output), new HasContent(input)).affirm();
}
Also used : HasContent(org.llorllale.cactoos.matchers.HasContent) LengthOf(org.cactoos.scalar.LengthOf) File(java.io.File) Test(org.junit.Test)

Example 72 with LengthOf

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

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

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

the class OutputToTest method writesIntoWriterWithCharset.

@Test
public void writesIntoWriterWithCharset() throws Exception {
    final String txt = "Hello, writer with charset!";
    final StringWriter output = new StringWriter();
    new LengthOf(new TeeInput(txt, new OutputTo(output, StandardCharsets.UTF_8))).value();
    new Assertion<>("Must write into writer with charset", 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 75 with LengthOf

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

the class OutputToTest method writesIntoWriterWithCharsetByNameAndSize.

@Test
public void writesIntoWriterWithCharsetByNameAndSize() throws Exception {
    final String txt = "Hello, writer with charset by name and size!";
    final StringWriter output = new StringWriter();
    new LengthOf(new TeeInput(txt, new OutputTo(output, StandardCharsets.UTF_8.name(), 1))).value();
    new Assertion<>("Must write into writer with charset by name 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)

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