Search in sources :

Example 16 with LengthOf

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

the class InputStreamOfTest method readsFromUrl.

@Test
public void readsFromUrl() throws Exception {
    final String content = "Content for reading through URL";
    final File file = this.folder.newFile("readFromUrl.txt-4");
    new LengthOf(new TeeInput(content, file)).value();
    new Assertion<>("Must read from URL", new TextOf(new InputStreamOf(file.toURI().toURL())), new IsText(content)).affirm();
}
Also used : LengthOf(org.cactoos.scalar.LengthOf) IsText(org.llorllale.cactoos.matchers.IsText) TextOf(org.cactoos.text.TextOf) File(java.io.File) Test(org.junit.Test)

Example 17 with LengthOf

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

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

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

the class TeeInputFromBytesTest method copiesFromBytesToFile.

@Test
public void copiesFromBytesToFile() throws Exception {
    final String message = "Hello, товарищ file äÄ üÜ öÖ and ß";
    final File output = this.folder.newFile();
    new LengthOf(new TeeInput(new BytesOf(message), output)).value();
    new Assertion<>("Must copy bytes to file", new InputOf(output), new HasContent(message)).affirm();
}
Also used : HasContent(org.llorllale.cactoos.matchers.HasContent) BytesOf(org.cactoos.bytes.BytesOf) LengthOf(org.cactoos.scalar.LengthOf) File(java.io.File) Test(org.junit.Test)

Example 20 with LengthOf

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

the class TeeInputFromBytesTest method copiesFromBytesToOutput.

@Test
public void copiesFromBytesToOutput() throws Exception {
    final String message = "Hello, товарищ output äÄ üÜ öÖ and ß";
    final File output = this.folder.newFile();
    new LengthOf(new TeeInput(new BytesOf(message), new OutputTo(output))).value();
    new Assertion<>("Must bytes to output", new InputOf(output), new HasContent(message)).affirm();
}
Also used : HasContent(org.llorllale.cactoos.matchers.HasContent) BytesOf(org.cactoos.bytes.BytesOf) LengthOf(org.cactoos.scalar.LengthOf) File(java.io.File) 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