use of org.hamcrest.core.AllOf in project cactoos by yegor256.
the class TextOfTest method readsStringBuilder.
@Test
void readsStringBuilder() {
final String starts = "Name it, ";
final String ends = "then it exists!";
new Assertion<>("Can't process a string builder", new TextOf(new StringBuilder(starts).append(ends)), new AllOf<>(new StartsWith(starts), new EndsWith(ends))).affirm();
}
use of org.hamcrest.core.AllOf in project cactoos by yegor256.
the class LoggingOutputTest method logAllWriteToLargeTextFile.
@Test
@SuppressWarnings("unchecked")
public void logAllWriteToLargeTextFile() throws Exception {
final Logger logger = new FakeLogger(Level.WARNING);
final Path temp = this.folder.newFolder("ccts-2").toPath();
final Path path = temp.resolve("a/b/c/file.txt");
try (OutputStream output = new LoggingOutput(new OutputTo(path), "text file", logger).stream()) {
new LengthOf(new TeeInput(new ResourceOf("org/cactoos/large-text.txt"), new OutputTo(output))).value();
}
new Assertion<>("Must log all write and close operations to text file", logger.toString(), new AllOf<>(new StringContains("Written 16384 byte(s) to text file"), new StringContains("Written 32768 byte(s) to text file"), new StringContains("Written 49152 byte(s) to text file"), new StringContains("Written 65536 byte(s) to text file"), new StringContains("Written 74536 byte(s) to text file"), new StringContains("Closed output stream from text file"))).affirm();
}
use of org.hamcrest.core.AllOf in project cactoos by yegor256.
the class LoggingOutputTest method logWriteToLargeTextFile.
@Test
@SuppressWarnings("unchecked")
public void logWriteToLargeTextFile() throws Exception {
final Logger logger = new FakeLogger();
final Path temp = this.folder.newFolder("ccts-1").toPath();
final Path path = temp.resolve("x/y/z/file.txt");
try (OutputStream output = new LoggingOutput(new OutputTo(path), "text file", logger).stream()) {
new LengthOf(new TeeInput(new ResourceOf("org/cactoos/large-text.txt"), new OutputTo(output))).value();
}
new Assertion<>("Must log write and close operations to text file", logger.toString(), new AllOf<>(new IsNot<String>(new StringContains("Written 16384 byte(s) to text file")), new StringContains("Written 74536 byte(s) to text file"), new StringContains("Closed output stream from text file"))).affirm();
}
use of org.hamcrest.core.AllOf 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.hamcrest.core.AllOf 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();
}
Aggregations