Search in sources :

Example 76 with LengthOf

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

the class OutputToTest method writesIntoPath.

@Test
public void writesIntoPath() throws Exception {
    final Path temp = this.folder.newFolder("cactoos-1").toPath();
    final Path path = temp.resolve("one/two/three/file.txt");
    final String content = "Hello, товарищ!";
    new LengthOf(new TeeInput(content, new OutputTo(path))).value();
    new Assertion<>("Must write into path", new InputOf(path), new HasContent(content)).affirm();
}
Also used : Path(java.nio.file.Path) HasContent(org.llorllale.cactoos.matchers.HasContent) LengthOf(org.cactoos.scalar.LengthOf) Test(org.junit.Test)

Example 77 with LengthOf

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

the class OutputToTest method writesIntoWriterWithCharsetAndSize.

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

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

the class OutputToTest method writesIntoFile.

@Test
public void writesIntoFile() throws Exception {
    final Path temp = this.folder.newFolder("cactoos-2").toPath();
    final Path path = temp.resolve("a/b/c/file.txt");
    final String txt = "Hello, друг!";
    new LengthOf(new TeeInput(txt, new SyncOutput(new OutputTo(path.toFile())))).value();
    new Assertion<>("Must write into file", new InputOf(path.toFile()), new HasContent(txt)).affirm();
}
Also used : Path(java.nio.file.Path) HasContent(org.llorllale.cactoos.matchers.HasContent) LengthOf(org.cactoos.scalar.LengthOf) Test(org.junit.Test)

Example 79 with LengthOf

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

the class SlowInputTest method calculatesLength.

@Test
void calculatesLength() throws Exception {
    final String text = "What's up, друг?";
    new Assertion<>("Can't calculate the length of Input", new LengthOf(new SlowInput(new InputOf(new TextOf(text)))), new HasValue<>((long) text.getBytes(StandardCharsets.UTF_8).length)).affirm();
}
Also used : LengthOf(org.cactoos.scalar.LengthOf) TextOf(org.cactoos.text.TextOf) HasValue(org.llorllale.cactoos.matchers.HasValue) Test(org.junit.jupiter.api.Test)

Example 80 with LengthOf

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

the class TeeInputFromBytesTest method copiesFromBytesToPath.

@Test
public void copiesFromBytesToPath() throws Exception {
    final String message = "Hello, товарищ path äÄ üÜ öÖ and ß";
    final File output = this.folder.newFile();
    new LengthOf(new TeeInput(new BytesOf(message), output.toPath())).value();
    new Assertion<>("Must copy bytes to file path", 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