Search in sources :

Example 1 with Assertion

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

the class IoCheckedBiProcTest method executesWrappedProc.

@Test
void executesWrappedProc() throws Exception {
    final AtomicInteger counter = new AtomicInteger();
    new IoCheckedBiProc<>((first, second) -> counter.incrementAndGet()).exec(true, true);
    new Assertion<>("Must execute wrapped proc", counter.get(), new IsEqual<>(1)).affirm();
}
Also used : Test(org.junit.jupiter.api.Test) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Assertion(org.llorllale.cactoos.matchers.Assertion) IsEqual(org.hamcrest.core.IsEqual) IOException(java.io.IOException) IoCheckedBiFunc(org.cactoos.func.IoCheckedBiFunc) Throws(org.llorllale.cactoos.matchers.Throws) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.jupiter.api.Test)

Example 2 with Assertion

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

the class CheckedTest method throwsIoExceptionWithModifiedMessage.

@Test
public void throwsIoExceptionWithModifiedMessage() throws Exception {
    final String message = "error msg";
    new Assertion<>("Must throw io exception with modified message", () -> new Checked<>(() -> {
        throw new IOException("io");
    }, exp -> new IOException(message, exp)).value(), new Throws<>(message, IOException.class)).affirm();
}
Also used : Assertion(org.llorllale.cactoos.matchers.Assertion) IsEqual(org.hamcrest.core.IsEqual) Matchers(org.hamcrest.Matchers) IOException(java.io.IOException) Test(org.junit.Test) AcceptPendingException(java.nio.channels.AcceptPendingException) Throws(org.llorllale.cactoos.matchers.Throws) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Throws(org.llorllale.cactoos.matchers.Throws) Test(org.junit.Test)

Example 3 with Assertion

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

the class CheckedProcTest method noExceptionThrown.

@Test
public void noExceptionThrown() throws Exception {
    final AtomicInteger counter = new AtomicInteger();
    new CheckedProc<>(input -> counter.incrementAndGet(), exp -> exp).exec(false);
    new Assertion<>("Must not throw an exception", counter.get(), new IsEqual<>(1)).affirm();
}
Also used : IsNull(org.hamcrest.core.IsNull) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Assertion(org.llorllale.cactoos.matchers.Assertion) IsEqual(org.hamcrest.core.IsEqual) IOException(java.io.IOException) Test(org.junit.Test) EOFException(java.io.EOFException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.Test)

Example 4 with Assertion

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

the class AsyncTest method runsInBackgroundWithoutFuture.

@Test
void runsInBackgroundWithoutFuture() {
    final CountDownLatch latch = new CountDownLatch(1);
    new Assertion<>("Must run in the background without us touching the Future", new Async<>(new FuncOf<>(input -> latch.countDown(), true)), new IsApplicable<>(true, new Satisfies<>(future -> latch.await(1L, TimeUnit.SECONDS)))).affirm();
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) IsApplicable(org.llorllale.cactoos.matchers.IsApplicable) Assertion(org.llorllale.cactoos.matchers.Assertion) IsEqual(org.hamcrest.core.IsEqual) ThreadFactory(java.util.concurrent.ThreadFactory) Executors(java.util.concurrent.Executors) Satisfies(org.llorllale.cactoos.matchers.Satisfies) IsApplicable(org.llorllale.cactoos.matchers.IsApplicable) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Example 5 with Assertion

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

the class AsyncTest method runsInBackgroundWithExecutorService.

@Test
void runsInBackgroundWithExecutorService() {
    final String name = "secret name for thread executor";
    final ThreadFactory factory = r -> new Thread(r, name);
    final CountDownLatch latch = new CountDownLatch(1);
    new Assertion<>("Must run in the background with specific thread executor", new Async<>(new FuncOf<>(input -> {
        if (!input.equals(Thread.currentThread().getName())) {
            throw new IllegalStateException("Another thread executor was used");
        }
        latch.countDown();
    }, true), Executors.newSingleThreadExecutor(factory)), new IsApplicable<>(name, new Satisfies<>(future -> {
        future.get();
        return latch.getCount() == 0;
    }))).affirm();
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) IsApplicable(org.llorllale.cactoos.matchers.IsApplicable) Assertion(org.llorllale.cactoos.matchers.Assertion) IsEqual(org.hamcrest.core.IsEqual) ThreadFactory(java.util.concurrent.ThreadFactory) Executors(java.util.concurrent.Executors) Satisfies(org.llorllale.cactoos.matchers.Satisfies) ThreadFactory(java.util.concurrent.ThreadFactory) IsApplicable(org.llorllale.cactoos.matchers.IsApplicable) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.jupiter.api.Test)

Aggregations

Assertion (org.llorllale.cactoos.matchers.Assertion)12 IOException (java.io.IOException)7 IsEqual (org.hamcrest.core.IsEqual)7 Test (org.junit.jupiter.api.Test)7 Test (org.junit.Test)5 Throws (org.llorllale.cactoos.matchers.Throws)5 Executors (java.util.concurrent.Executors)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 ThreadFactory (java.util.concurrent.ThreadFactory)3 TimeUnit (java.util.concurrent.TimeUnit)3 IsApplicable (org.llorllale.cactoos.matchers.IsApplicable)3 Satisfies (org.llorllale.cactoos.matchers.Satisfies)3 EOFException (java.io.EOFException)2 IsNull (org.hamcrest.core.IsNull)2 FileNotFoundException (java.io.FileNotFoundException)1 AcceptPendingException (java.nio.channels.AcceptPendingException)1 Future (java.util.concurrent.Future)1 TimeoutException (java.util.concurrent.TimeoutException)1 Proc (org.cactoos.Proc)1