Search in sources :

Example 1 with HasContent

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

the class AppendToTest method appendsUnicodeToFile.

/**
 * Ensures that AppendTo is appending unicode text to a given file.
 * @throws Exception if fails
 */
@Test
public void appendsUnicodeToFile() throws Exception {
    final File source = this.folder.newFile();
    final String first = "Hello, товарищ output #3 äÄ ";
    new OutputTo(source).stream().write(first.getBytes(StandardCharsets.UTF_8));
    final String second = "#4 äÄ üÜ öÖ and ß";
    new AppendTo(source).stream().write(second.getBytes(StandardCharsets.UTF_8));
    new Assertion<>("Can't find expected unicode text content", new InputOf(source), new HasContent(new Concatenated(first, second))).affirm();
}
Also used : HasContent(org.llorllale.cactoos.matchers.HasContent) Concatenated(org.cactoos.text.Concatenated) File(java.io.File) Test(org.junit.Test)

Example 2 with HasContent

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

the class AppendToTest method appendsToFile.

/**
 * Ensures that AppendTo is appending to a given file.
 * @throws Exception if fails
 */
@Test
public void appendsToFile() throws Exception {
    final File source = this.folder.newFile();
    final String first = "abdcd";
    new OutputTo(source).stream().write(first.getBytes());
    final String second = "efgh";
    new AppendTo(source).stream().write(second.getBytes());
    new Assertion<>("Does not contain expected text", new InputOf(source), new HasContent(new Concatenated(first, second))).affirm();
}
Also used : HasContent(org.llorllale.cactoos.matchers.HasContent) Concatenated(org.cactoos.text.Concatenated) File(java.io.File) Test(org.junit.Test)

Example 3 with HasContent

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

the class OutputToTest method writesIntoWriter.

@Test
public void writesIntoWriter() throws Exception {
    final String txt = "Hello, writer!";
    final StringWriter output = new StringWriter();
    new LengthOf(new TeeInput(txt, new OutputTo(output))).value();
    new Assertion<>("Must write into writer", 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 4 with HasContent

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

the class OutputToTest method writesIntoWriterWithDecoderAndSize.

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

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

the class OutputToTest method writesIntoWriterWithSize.

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

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