Search in sources :

Example 11 with HasContent

use of org.llorllale.cactoos.matchers.HasContent in project cactoos by yegor256.

the class TeeInputFromUrlTest method copiesFromUrlToFile.

@Test
public void copiesFromUrlToFile() throws Exception {
    final String message = "Hello, товарищ file #1 äÄ üÜ öÖ and ß";
    final File input = this.folder.newFile();
    Files.write(input.toPath(), message.getBytes(StandardCharsets.UTF_8));
    final File output = this.folder.newFile();
    new LengthOf(new TeeInput(input.toURI().toURL(), output)).value();
    new Assertion<>("Must copy from URL to file.", new InputOf(output), new HasContent(message)).affirm();
}
Also used : HasContent(org.llorllale.cactoos.matchers.HasContent) LengthOf(org.cactoos.scalar.LengthOf) File(java.io.File) Test(org.junit.Test)

Example 12 with HasContent

use of org.llorllale.cactoos.matchers.HasContent in project cactoos by yegor256.

the class TeeReaderTest method testTeeReader.

@Test
void testTeeReader() throws IOException {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final String content = "Hello, товарищ!";
    final Reader reader = new TeeReader(new ReaderOf(content), new WriterTo(baos));
    int done = 0;
    while (done >= 0) {
        done = reader.read();
    }
    reader.close();
    new Assertion<>("Must read content", new InputOf(new ReaderOf(baos.toByteArray())), new HasContent(content)).affirm();
}
Also used : HasContent(org.llorllale.cactoos.matchers.HasContent) Reader(java.io.Reader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 13 with HasContent

use of org.llorllale.cactoos.matchers.HasContent 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 14 with HasContent

use of org.llorllale.cactoos.matchers.HasContent in project cactoos by yegor256.

the class TeeInputFromCharSequenceTest method copiesFromCharSequenceWithCharsetToFile.

@Test
public void copiesFromCharSequenceWithCharsetToFile() throws Exception {
    final String input = "Hello, товарищ file #2 äÄ üÜ öÖ and ß";
    final File output = this.folder.newFile();
    new LengthOf(new TeeInput(input, output, StandardCharsets.UTF_8)).value();
    new Assertion<>("char sequence 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) File(java.io.File) Test(org.junit.Test)

Example 15 with HasContent

use of org.llorllale.cactoos.matchers.HasContent in project cactoos by yegor256.

the class TeeInputFromCharSequenceTest method copiesFromCharSequenceWithCharsetByNameToPath.

@Test
public void copiesFromCharSequenceWithCharsetByNameToPath() throws Exception {
    final String input = "Hello, товарищ path #3 äÄ üÜ öÖ and ß";
    final File output = this.folder.newFile();
    new LengthOf(new TeeInput(input, output.toPath(), StandardCharsets.UTF_8.name())).value();
    new Assertion<>("char sequence must be copied to the path with UTF_8 charset's name", 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)

Aggregations

HasContent (org.llorllale.cactoos.matchers.HasContent)91 Test (org.junit.Test)89 LengthOf (org.cactoos.scalar.LengthOf)80 File (java.io.File)73 TextOf (org.cactoos.text.TextOf)15 StringWriter (java.io.StringWriter)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Path (java.nio.file.Path)5 BytesOf (org.cactoos.bytes.BytesOf)3 Concatenated (org.cactoos.text.Concatenated)2 Test (org.junit.jupiter.api.Test)2 OutputStreamWriter (java.io.OutputStreamWriter)1 Reader (java.io.Reader)1 HasString (org.llorllale.cactoos.matchers.HasString)1