Search in sources :

Example 1 with IsTrue

use of org.llorllale.cactoos.matchers.IsTrue in project cactoos by yegor256.

the class NoNullsTest method addsToEmptyCollection.

@Test
void addsToEmptyCollection() {
    final Collection<Integer> col = new NoNulls<>(new ListOf<>());
    col.add(1);
    new Assertion<>("Must not be empty after an item was added", col.isEmpty(), new IsNot<>(new IsTrue())).affirm();
}
Also used : IsNot(org.hamcrest.core.IsNot) IsTrue(org.llorllale.cactoos.matchers.IsTrue) Test(org.junit.jupiter.api.Test)

Example 2 with IsTrue

use of org.llorllale.cactoos.matchers.IsTrue in project cactoos by yegor256.

the class BytesOfTest method closesInputStream.

@Test
void closesInputStream() throws Exception {
    final AtomicBoolean closed = new AtomicBoolean();
    final InputStream input = new ByteArrayInputStream("how are you?".getBytes());
    new TextOf(new InputOf(new InputStream() {

        @Override
        public int read() throws IOException {
            return input.read();
        }

        @Override
        public void close() throws IOException {
            input.close();
            closed.set(true);
        }
    }), StandardCharsets.UTF_8).asString();
    new Assertion<>("must close InputStream correctly", closed.get(), new IsTrue()).affirm();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IsTrue(org.llorllale.cactoos.matchers.IsTrue) TextOf(org.cactoos.text.TextOf) IOException(java.io.IOException) InputOf(org.cactoos.io.InputOf) Test(org.junit.jupiter.api.Test)

Example 3 with IsTrue

use of org.llorllale.cactoos.matchers.IsTrue in project cactoos by yegor256.

the class TimedFuncTest method futureTaskIsCancelled.

@Test
@SuppressWarnings("PMD.AvoidCatchingGenericException")
public void futureTaskIsCancelled() {
    final long period = 50L;
    final long time = 2000L;
    final Future<Boolean> future = Executors.newSingleThreadExecutor().submit(() -> {
        Thread.sleep(time);
        return true;
    });
    try {
        new Timed<Boolean, Boolean>(period, input -> future).apply(true);
    // @checkstyle IllegalCatchCheck (1 line)
    } catch (final Exception exp) {
        new Assertion<>("Must be canceled after 1 sec", future.isCancelled(), new IsTrue()).affirm();
    }
}
Also used : IsTrue(org.llorllale.cactoos.matchers.IsTrue) Future(java.util.concurrent.Future) Endless(org.cactoos.iterable.Endless) And(org.cactoos.scalar.And) Assertion(org.llorllale.cactoos.matchers.Assertion) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test) Executors(java.util.concurrent.Executors) IsTrue(org.llorllale.cactoos.matchers.IsTrue) Assertion(org.llorllale.cactoos.matchers.Assertion) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 4 with IsTrue

use of org.llorllale.cactoos.matchers.IsTrue in project cactoos by yegor256.

the class InputOfTest method closesInputStream.

@Test
void closesInputStream() throws Exception {
    final AtomicBoolean closed = new AtomicBoolean();
    final InputStream input = new ByteArrayInputStream("how are you?".getBytes());
    new TextOf(new InputOf(new InputStream() {

        @Override
        public int read() throws IOException {
            return input.read();
        }

        @Override
        public void close() throws IOException {
            input.close();
            closed.set(true);
        }
    })).asString();
    new Assertion<>("must close InputStream correctly", closed.get(), new IsTrue()).affirm();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IsTrue(org.llorllale.cactoos.matchers.IsTrue) TextOf(org.cactoos.text.TextOf) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 5 with IsTrue

use of org.llorllale.cactoos.matchers.IsTrue in project cactoos by yegor256.

the class NoNullsTest method retainsAll.

@Test
void retainsAll() {
    final Collection<Integer> col = new NoNulls<>(new ListOf<>(1, 2, 3));
    new Assertion<>("NoNulls#retainAll(...) must return false for the same elements", col.retainAll(new ListOf<>(1, 2, 3)), new IsNot<>(new IsTrue())).affirm();
}
Also used : IsNot(org.hamcrest.core.IsNot) IsTrue(org.llorllale.cactoos.matchers.IsTrue) Test(org.junit.jupiter.api.Test)

Aggregations

IsTrue (org.llorllale.cactoos.matchers.IsTrue)10 Test (org.junit.jupiter.api.Test)8 IsNot (org.hamcrest.core.IsNot)5 File (java.io.File)3 Path (java.nio.file.Path)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ProcOf (org.cactoos.proc.ProcOf)2 TextOf (org.cactoos.text.TextOf)2 Test (org.junit.Test)2 OutputStreamWriter (java.io.OutputStreamWriter)1 Executors (java.util.concurrent.Executors)1 Future (java.util.concurrent.Future)1 TimeoutException (java.util.concurrent.TimeoutException)1 InputOf (org.cactoos.io.InputOf)1 Endless (org.cactoos.iterable.Endless)1 And (org.cactoos.scalar.And)1 LengthOf (org.cactoos.scalar.LengthOf)1