use of org.cactoos.text.TextOf in project cactoos by yegor256.
the class LoggingInputTest method logReadFromLargeTextFile.
@Test
@SuppressWarnings("unchecked")
void logReadFromLargeTextFile() throws Exception {
final Logger logger = new FakeLogger();
new LengthOf(new LoggingInput(new ResourceOf("org/cactoos/large-text.txt"), "text file", logger)).value();
new Assertion<>("Must log 74536 bytes read from text file", new TextOf(logger.toString()), new AllOf<>(new IsNot<Text>(new HasString("Read 16384 byte(s) from text file")), new HasString("Read 74536 byte(s) from text file in"), new HasString("Closed input stream from text file"))).affirm();
}
use of org.cactoos.text.TextOf 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.text.TextOf 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.text.TextOf in project cactoos by yegor256.
the class GzipInputTest method readFromGzipInput.
@Test
public void readFromGzipInput() throws Exception {
final String content = "Hello!";
final ByteArrayOutputStream out = new ByteArrayOutputStream();
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new GZIPOutputStream(out)))) {
writer.write(content);
}
final byte[] bytes = out.toByteArray();
new Assertion<>("Can't read from a gzip input", new TextOf(new GzipInput(new InputOf(bytes))), new IsText(content)).affirm();
}
use of org.cactoos.text.TextOf in project cactoos by yegor256.
the class InputStreamOfTest method readsFileContent.
@Test
public void readsFileContent() throws Exception {
final File file = this.folder.newFile("readFileContent.txt-2");
final String content = "Content in a file";
new LengthOf(new TeeInput(content, file)).value();
new Assertion<>("Must read from file", new TextOf(new InputStreamOf(file)), new IsText(content)).affirm();
}
Aggregations