Search in sources :

Example 11 with BytesOf

use of org.cactoos.bytes.BytesOf in project cactoos by yegor256.

the class TeeInputFromBytesTest method copiesFromBytesToFile.

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

Example 12 with BytesOf

use of org.cactoos.bytes.BytesOf in project cactoos by yegor256.

the class TeeInputFromBytesTest method copiesFromBytesToOutput.

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

Example 13 with BytesOf

use of org.cactoos.bytes.BytesOf in project cactoos by yegor256.

the class InputOfTest method readsStringBuilder.

@Test
void readsStringBuilder() throws Exception {
    final String starts = "Name it, ";
    final String ends = "then it exists!";
    new Assertion<>("must receive a string builder", new TextOf(new BytesOf(new InputOf(new StringBuilder(starts).append(ends)))), new AllOf<>(new StartsWith(starts), new EndsWith(ends))).affirm();
}
Also used : BytesOf(org.cactoos.bytes.BytesOf) TextOf(org.cactoos.text.TextOf) HasString(org.llorllale.cactoos.matchers.HasString) StartsWith(org.llorllale.cactoos.matchers.StartsWith) AllOf(org.hamcrest.core.AllOf) EndsWith(org.llorllale.cactoos.matchers.EndsWith) Test(org.junit.jupiter.api.Test)

Example 14 with BytesOf

use of org.cactoos.bytes.BytesOf in project cactoos by yegor256.

the class InputOfTest method readsStringBuffer.

@Test
void readsStringBuffer() throws Exception {
    final String starts = "The future ";
    final String ends = "is now!";
    new Assertion<>("must receive a string buffer", new TextOf(new BytesOf(new InputOf(new StringBuffer(starts).append(ends)))), new AllOf<>(new StartsWith(starts), new EndsWith(ends))).affirm();
}
Also used : BytesOf(org.cactoos.bytes.BytesOf) TextOf(org.cactoos.text.TextOf) HasString(org.llorllale.cactoos.matchers.HasString) StartsWith(org.llorllale.cactoos.matchers.StartsWith) AllOf(org.hamcrest.core.AllOf) EndsWith(org.llorllale.cactoos.matchers.EndsWith) Test(org.junit.jupiter.api.Test)

Example 15 with BytesOf

use of org.cactoos.bytes.BytesOf in project cactoos by yegor256.

the class TailOfTest method tailsOnExactStreamAndBuffer.

@Test
public void tailsOnExactStreamAndBuffer() throws Exception {
    final int size = 4;
    final byte[] bytes = this.generate(size);
    new Assertion<>("Can't tail exact stream and buffer", new BytesOf(new TailOf(new InputOf(new BytesOf(bytes)), size, size)).asBytes(), new IsEqual<>(bytes)).affirm();
}
Also used : BytesOf(org.cactoos.bytes.BytesOf) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.Test)

Aggregations

BytesOf (org.cactoos.bytes.BytesOf)17 Test (org.junit.Test)12 IsEqual (org.hamcrest.core.IsEqual)6 File (java.io.File)4 TextOf (org.cactoos.text.TextOf)4 Test (org.junit.jupiter.api.Test)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 LengthOf (org.cactoos.scalar.LengthOf)3 HasContent (org.llorllale.cactoos.matchers.HasContent)3 HasString (org.llorllale.cactoos.matchers.HasString)3 OutputStream (java.io.OutputStream)2 Logger (java.util.logging.Logger)2 AllOf (org.hamcrest.core.AllOf)2 StringContains (org.hamcrest.core.StringContains)2 EndsWith (org.llorllale.cactoos.matchers.EndsWith)2 IsText (org.llorllale.cactoos.matchers.IsText)2 StartsWith (org.llorllale.cactoos.matchers.StartsWith)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 StringReader (java.io.StringReader)1