Search in sources :

Example 6 with AllOf

use of org.hamcrest.core.AllOf in project cactoos by yegor256.

the class TeeInputStreamTest method copiesContentByteByByte.

@Test
@SuppressWarnings("unchecked")
void copiesContentByteByByte() throws Exception {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final String content = "Hello, товарищ!";
    new Assertion<>("Must copy InputStream to OutputStream byte by byte", new TextOf(new ReaderOf(new TeeInputStream(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)), baos))).asString(), new AllOf<>(new IsEqual<String>(content), new IsEqual<String>(new String(baos.toByteArray(), StandardCharsets.UTF_8)))).affirm();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) TextOf(org.cactoos.text.TextOf) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AllOf(org.hamcrest.core.AllOf) Test(org.junit.jupiter.api.Test)

Example 7 with AllOf

use of org.hamcrest.core.AllOf in project cactoos by yegor256.

the class InputOfTest method readsStringBuilder.

@Test
void readsStringBuilder() throws Exception {
    final String starts = "Name it, ";
    final String ends = "then it exists!";
    new Assertion<>("must receive a string builder", new TextOf(new BytesOf(new InputOf(new StringBuilder(starts).append(ends)))), new AllOf<>(new StartsWith(starts), new EndsWith(ends))).affirm();
}
Also used : BytesOf(org.cactoos.bytes.BytesOf) TextOf(org.cactoos.text.TextOf) 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 8 with AllOf

use of org.hamcrest.core.AllOf in project cactoos by yegor256.

the class InputOfTest method readsStringBuffer.

@Test
void readsStringBuffer() throws Exception {
    final String starts = "The future ";
    final String ends = "is now!";
    new Assertion<>("must receive a string buffer", new TextOf(new BytesOf(new InputOf(new StringBuffer(starts).append(ends)))), new AllOf<>(new StartsWith(starts), new EndsWith(ends))).affirm();
}
Also used : BytesOf(org.cactoos.bytes.BytesOf) TextOf(org.cactoos.text.TextOf) 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 9 with AllOf

use of org.hamcrest.core.AllOf in project cactoos by yegor256.

the class LoggingInputTest method logResetFromLargeTextFile.

@Test
@SuppressWarnings("unchecked")
void logResetFromLargeTextFile() throws Exception {
    final Logger logger = new FakeLogger();
    final InputStream input = new LoggingInput(new ResourceOf("org/cactoos/large-text.txt"), "text file", logger).stream();
    // @checkstyle MagicNumber (1 line)
    input.mark(150);
    input.reset();
    new Assertion<>("Must log mark and reset from text file", new TextOf(logger.toString()), new AllOf<>(new HasString("Marked position 150 from text file"), new HasString("Reset input stream from text file"))).affirm();
}
Also used : HasString(org.llorllale.cactoos.matchers.HasString) InputStream(java.io.InputStream) TextOf(org.cactoos.text.TextOf) Logger(java.util.logging.Logger) AllOf(org.hamcrest.core.AllOf) Test(org.junit.jupiter.api.Test)

Example 10 with AllOf

use of org.hamcrest.core.AllOf in project cactoos by yegor256.

the class TextOfTest method readsStringBuffer.

@Test
void readsStringBuffer() {
    final String starts = "In our daily life, ";
    final String ends = "we can smile!";
    new Assertion<>("Can't process a string builder hahahaha", new TextOf(new StringBuffer(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)

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