Search in sources :

Example 11 with AllOf

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

the class TeeOutputStreamTest method copiesContentByteByByte.

@Test
@SuppressWarnings("unchecked")
void copiesContentByteByByte() throws Exception {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ByteArrayOutputStream copy = new ByteArrayOutputStream();
    final String content = "Hello, товарищ!";
    new Assertion<>("Must copy OutputStream to OutputStream byte by byte", new TextOf(new ReaderOf(new TeeInputStream(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)), new TeeOutputStream(baos, copy)))).asString(), new AllOf<>(new IsEqual<String>(content), new IsEqual<String>(new String(baos.toByteArray(), StandardCharsets.UTF_8)), new IsEqual<String>(new String(copy.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 12 with AllOf

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

the class StickyTest method equalsItself.

@Test
void equalsItself() {
    final Text random = new Randomized();
    final Text sticky = new Sticky(random);
    new Assertion<>("must be the same as itself", sticky, new AllOf<Text>(new IsEqual<>(sticky), new IsNot<>(new IsEqual<>(random)))).affirm();
}
Also used : Text(org.cactoos.Text) IsText(org.llorllale.cactoos.matchers.IsText) AllOf(org.hamcrest.core.AllOf) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.jupiter.api.Test)

Example 13 with AllOf

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

the class AbbreviatedTest method abbreviatesTextThatChanges.

@Test
@SuppressWarnings("unchecked")
void abbreviatesTextThatChanges() {
    final AtomicInteger counter = new AtomicInteger(0);
    final Text txt = new TextOf(() -> {
        final String result;
        if (counter.getAndIncrement() == 0) {
            result = "The quick brown fox jumps";
        } else {
            result = "The lazy black dog";
        }
        return result;
    });
    new Assertion<>("Must abbreviate a text that changes", new Abbreviated(txt, 15), new AllOf<>(new IsText("The quick br..."), new IsText("The lazy bla..."))).affirm();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IsText(org.llorllale.cactoos.matchers.IsText) Text(org.cactoos.Text) IsText(org.llorllale.cactoos.matchers.IsText) 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