Search in sources :

Example 61 with TextOf

use of org.cactoos.text.TextOf in project cactoos by yegor256.

the class TeeOutputStreamTest method copiesContentByteByByte.

@Test
@SuppressWarnings("unchecked")
void copiesContentByteByByte() throws Exception {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ByteArrayOutputStream copy = new ByteArrayOutputStream();
    final String content = "Hello, товарищ!";
    new Assertion<>("Must copy OutputStream to OutputStream byte by byte", new TextOf(new ReaderOf(new TeeInputStream(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)), new TeeOutputStream(baos, copy)))).asString(), new AllOf<>(new IsEqual<String>(content), new IsEqual<String>(new String(baos.toByteArray(), StandardCharsets.UTF_8)), new IsEqual<String>(new String(copy.toByteArray(), StandardCharsets.UTF_8)))).affirm();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) TextOf(org.cactoos.text.TextOf) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AllOf(org.hamcrest.core.AllOf) Test(org.junit.jupiter.api.Test)

Example 62 with TextOf

use of org.cactoos.text.TextOf in project cactoos by yegor256.

the class WriterToTest method writesLargeContentToFile.

@Test
public void writesLargeContentToFile() throws IOException {
    final Path temp = this.folder.newFile("cactoos-1.txt-1").toPath();
    new Assertion<>("Can't copy Input to Output and return Input", new TeeInput(new ResourceOf("org/cactoos/large-text.txt"), new WriterAsOutput(new WriterTo(temp))), new HasContent(new TextOf(temp))).affirm();
}
Also used : Path(java.nio.file.Path) HasContent(org.llorllale.cactoos.matchers.HasContent) TextOf(org.cactoos.text.TextOf) Test(org.junit.Test)

Example 63 with TextOf

use of org.cactoos.text.TextOf in project cactoos by yegor256.

the class TeeOutputTest method copiesWithWriter.

@Test
public void copiesWithWriter() {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new Assertion<>("Can't copy Output with writer", new TeeInput(new InputOf("Hello, товарищ! writer"), new TeeOutput(new OutputTo(baos), new WriterTo(new ByteArrayOutputStream()))), new HasContent(new TextOf(baos::toByteArray, StandardCharsets.UTF_8))).affirm();
}
Also used : HasContent(org.llorllale.cactoos.matchers.HasContent) TextOf(org.cactoos.text.TextOf) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 64 with TextOf

use of org.cactoos.text.TextOf in project cactoos by yegor256.

the class TeeOutputTest method copiesWithPath.

@Test
public void copiesWithPath() throws Exception {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final File file = this.folder.newFile();
    new Assertion<>("Must copy Output with path", new TextOf(new TeeInput(new InputOf("Hello, товарищ! with path"), new TeeOutput(new OutputTo(baos), file.toPath()))), new IsText(new TextOf(file.toPath()))).affirm();
}
Also used : IsText(org.llorllale.cactoos.matchers.IsText) TextOf(org.cactoos.text.TextOf) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) Test(org.junit.Test)

Example 65 with TextOf

use of org.cactoos.text.TextOf in project cactoos by yegor256.

the class TeeOutputTest method copiesContent.

@Test
public void copiesContent() {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new Assertion<>("Can't copy Output to Output and return Input", new TeeInput(new InputOf("Hello, товарищ!"), new TeeOutput(new OutputTo(baos), new OutputTo(new ByteArrayOutputStream()))), new HasContent(new TextOf(baos::toByteArray, StandardCharsets.UTF_8))).affirm();
}
Also used : HasContent(org.llorllale.cactoos.matchers.HasContent) TextOf(org.cactoos.text.TextOf) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

TextOf (org.cactoos.text.TextOf)74 Test (org.junit.Test)41 Test (org.junit.jupiter.api.Test)32 IsText (org.llorllale.cactoos.matchers.IsText)25 File (java.io.File)20 LengthOf (org.cactoos.scalar.LengthOf)20 HasString (org.llorllale.cactoos.matchers.HasString)17 HasContent (org.llorllale.cactoos.matchers.HasContent)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)14 Logger (java.util.logging.Logger)10 Text (org.cactoos.Text)9 AllOf (org.hamcrest.core.AllOf)7 IsEqual (org.hamcrest.core.IsEqual)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 StringReader (java.io.StringReader)5 Path (java.nio.file.Path)5 MatcherOf (org.cactoos.matchers.MatcherOf)5 InputStream (java.io.InputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 BytesOf (org.cactoos.bytes.BytesOf)4