use of org.cactoos.scalar.LengthOf in project cactoos by yegor256.
the class LoggingInputTest method logAllFromLargeTextFile.
@Test
@SuppressWarnings("unchecked")
void logAllFromLargeTextFile() throws Exception {
final Logger logger = new FakeLogger(Level.WARNING);
new LengthOf(new LoggingInput(new ResourceOf("org/cactoos/large-text.txt"), "text file", logger)).value();
new Assertion<>("Must log all read and close operations from text file", new TextOf(logger.toString()), new AllOf<>(new HasString("Read 16384 byte(s) from text file"), new HasString("Read 32768 byte(s) from text file"), new HasString("Read 49152 byte(s) from text file"), new HasString("Read 65536 byte(s) from text file"), new HasString("Read 74536 byte(s) from text file"), new HasString("Closed input stream from text file"))).affirm();
}
use of org.cactoos.scalar.LengthOf in project cactoos by yegor256.
the class LoggingInputTest method logIntoCreatedLogger.
@Test
void logIntoCreatedLogger() throws Exception {
final FakeHandler handler = new FakeHandler();
final String src = "my source";
final Logger logger = Logger.getLogger(src);
logger.addHandler(handler);
try {
new LengthOf(new LoggingInput(new InputOf("Hi there"), src)).value();
new Assertion<>("", new TextOf(handler.toString()), new HasString("Read 8 byte(s)")).affirm();
} finally {
logger.removeHandler(handler);
}
}
use of org.cactoos.scalar.LengthOf 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();
}
use of org.cactoos.scalar.LengthOf 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();
}
use of org.cactoos.scalar.LengthOf 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();
}
Aggregations