Search in sources :

Example 1 with BytesOf

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

the class LoggingOutputTest method logWriteText.

@Test
public void logWriteText() throws Exception {
    final Logger logger = new FakeLogger();
    try (OutputStream out = new LoggingOutput(ByteArrayOutputStream::new, "memory", logger).stream()) {
        out.write(new BytesOf("Hello, товарищ!").asBytes());
    }
    new Assertion<>("Must log 22 bytes written to memory", logger.toString(), new StringContains("Written 22 byte(s) to memory in")).affirm();
}
Also used : BytesOf(org.cactoos.bytes.BytesOf) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Logger(java.util.logging.Logger) StringContains(org.hamcrest.core.StringContains) Test(org.junit.Test)

Example 2 with BytesOf

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

the class LoggingOutputTest method logWriteOneByte.

@Test
public void logWriteOneByte() throws Exception {
    final Logger logger = new FakeLogger();
    try (OutputStream out = new LoggingOutput(ByteArrayOutputStream::new, "memory", logger).stream()) {
        out.write(new BytesOf("a").asBytes());
    }
    new Assertion<>("Must log one byte written to memory", logger.toString(), new StringContains("Written 1 byte(s) to memory in")).affirm();
}
Also used : BytesOf(org.cactoos.bytes.BytesOf) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Logger(java.util.logging.Logger) StringContains(org.hamcrest.core.StringContains) Test(org.junit.Test)

Example 3 with BytesOf

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

the class InputOfTest method readsEncodedStringFromReader.

@Test
void readsEncodedStringFromReader() throws Exception {
    final String source = "hello, друг!";
    new Assertion<>("must read encoded string through a reader", new TextOf(new BytesOf(new InputOf(new StringReader(source), StandardCharsets.UTF_8))), new IsText(source)).affirm();
}
Also used : BytesOf(org.cactoos.bytes.BytesOf) StringReader(java.io.StringReader) IsText(org.llorllale.cactoos.matchers.IsText) TextOf(org.cactoos.text.TextOf) HasString(org.llorllale.cactoos.matchers.HasString) Test(org.junit.jupiter.api.Test)

Example 4 with BytesOf

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

the class InputOfTest method readsAnArrayOfBytes.

@Test
void readsAnArrayOfBytes() throws Exception {
    final byte[] bytes = new byte[] { (byte) 0xCA, (byte) 0xFE };
    new Assertion<>("must read array of bytes", new BytesOf(new SyncInput(new InputOf(bytes))).asBytes(), new IsEqual<>(bytes)).affirm();
}
Also used : BytesOf(org.cactoos.bytes.BytesOf) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.jupiter.api.Test)

Example 5 with BytesOf

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

the class InputStreamOfTest method readsBytesArray.

@Test
public void readsBytesArray() throws Exception {
    final String content = "Bytes array content";
    final byte[] bytes = new BytesOf(content).asBytes();
    new Assertion<>("Must read from byte array", new TextOf(new InputStreamOf(bytes)), new IsText(content)).affirm();
}
Also used : BytesOf(org.cactoos.bytes.BytesOf) IsText(org.llorllale.cactoos.matchers.IsText) TextOf(org.cactoos.text.TextOf) 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