Search in sources :

Example 31 with TextOf

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

the class TeeInputFromTextTest method copiesFromTextWithCharsetToFile.

@Test
public void copiesFromTextWithCharsetToFile() throws Exception {
    final String input = "Hello, товарищ file #2 äÄ üÜ öÖ and ß";
    final File output = this.folder.newFile();
    new LengthOf(new TeeInput(new TextOf(input), output, StandardCharsets.UTF_8)).value();
    new Assertion<>("text must be copied to the file with UTF_8 charset", new InputOf(output), new HasContent(input)).affirm();
}
Also used : HasContent(org.llorllale.cactoos.matchers.HasContent) LengthOf(org.cactoos.scalar.LengthOf) TextOf(org.cactoos.text.TextOf) File(java.io.File) Test(org.junit.Test)

Example 32 with TextOf

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

the class WriterAsOutputStreamTest method writesToByteArray.

@Test
public void writesToByteArray() {
    final String content = "Hello, товарищ! How are you?";
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new Assertion<>("Can't copy Input to Writer", new TeeInput(new InputOf(content), new OutputTo(new WriterAsOutputStream(new OutputStreamWriter(baos, StandardCharsets.UTF_8), StandardCharsets.UTF_8, // @checkstyle MagicNumber (1 line)
    13))), new HasContent(new TextOf(baos::toByteArray, StandardCharsets.UTF_8))).affirm();
}
Also used : HasContent(org.llorllale.cactoos.matchers.HasContent) OutputStreamWriter(java.io.OutputStreamWriter) TextOf(org.cactoos.text.TextOf) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 33 with TextOf

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

the class TeeInputStreamTest method copiesContentByteByByte.

@Test
@SuppressWarnings("unchecked")
void copiesContentByteByByte() throws Exception {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final String content = "Hello, товарищ!";
    new Assertion<>("Must copy InputStream to OutputStream byte by byte", new TextOf(new ReaderOf(new TeeInputStream(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)), baos))).asString(), new AllOf<>(new IsEqual<String>(content), new IsEqual<String>(new String(baos.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 34 with TextOf

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

the class TeeOutputTest method copiesWithWriterAndCharset.

@Test
public void copiesWithWriterAndCharset() {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new Assertion<>("Can't copy Output with writer and charset", new TeeInput(new InputOf("Hello, товарищ! writer and charset"), new TeeOutput(new OutputTo(baos), new WriterTo(new ByteArrayOutputStream()), StandardCharsets.UTF_8)), 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 35 with TextOf

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

the class TeeOutputTest method copiesWithFile.

@Test
public void copiesWithFile() throws Exception {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final File file = this.folder.newFile();
    new Assertion<>("Must copy Output with file", new TextOf(new TeeInput(new InputOf("Hello, товарищ! with file"), new TeeOutput(new OutputTo(baos), file))), 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)

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