Search in sources :

Example 1 with AllOf

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();
}
Also used : HasString(org.llorllale.cactoos.matchers.HasString) StartsWith(org.llorllale.cactoos.matchers.StartsWith) AllOf(org.hamcrest.core.AllOf) EndsWith(org.llorllale.cactoos.matchers.EndsWith) Test(org.junit.jupiter.api.Test)

Example 2 with AllOf

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();
}
Also used : Path(java.nio.file.Path) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LengthOf(org.cactoos.scalar.LengthOf) Logger(java.util.logging.Logger) AllOf(org.hamcrest.core.AllOf) StringContains(org.hamcrest.core.StringContains) Test(org.junit.Test)

Example 3 with AllOf

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();
}
Also used : Path(java.nio.file.Path) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Logger(java.util.logging.Logger) LengthOf(org.cactoos.scalar.LengthOf) AllOf(org.hamcrest.core.AllOf) StringContains(org.hamcrest.core.StringContains) Test(org.junit.Test)

Example 4 with AllOf

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();
}
Also used : HasString(org.llorllale.cactoos.matchers.HasString) LengthOf(org.cactoos.scalar.LengthOf) TextOf(org.cactoos.text.TextOf) Text(org.cactoos.Text) Logger(java.util.logging.Logger) AllOf(org.hamcrest.core.AllOf) Test(org.junit.jupiter.api.Test)

Example 5 with AllOf

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();
}
Also used : HasString(org.llorllale.cactoos.matchers.HasString) LengthOf(org.cactoos.scalar.LengthOf) TextOf(org.cactoos.text.TextOf) Logger(java.util.logging.Logger) AllOf(org.hamcrest.core.AllOf) Test(org.junit.jupiter.api.Test)

Aggregations

AllOf (org.hamcrest.core.AllOf)13 Test (org.junit.jupiter.api.Test)11 TextOf (org.cactoos.text.TextOf)7 HasString (org.llorllale.cactoos.matchers.HasString)7 Logger (java.util.logging.Logger)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 LengthOf (org.cactoos.scalar.LengthOf)4 EndsWith (org.llorllale.cactoos.matchers.EndsWith)4 StartsWith (org.llorllale.cactoos.matchers.StartsWith)4 Text (org.cactoos.Text)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 OutputStream (java.io.OutputStream)2 Path (java.nio.file.Path)2 BytesOf (org.cactoos.bytes.BytesOf)2 StringContains (org.hamcrest.core.StringContains)2 Test (org.junit.Test)2 IsText (org.llorllale.cactoos.matchers.IsText)2 InputStream (java.io.InputStream)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 IsEqual (org.hamcrest.core.IsEqual)1