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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations