use of org.llorllale.cactoos.matchers.IsApplicable 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();
}
use of org.llorllale.cactoos.matchers.IsApplicable 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();
}
use of org.llorllale.cactoos.matchers.IsApplicable in project cactoos by yegor256.
the class AsyncTest method runsInBackgroundWithThreadFactory.
@Test
void runsInBackgroundWithThreadFactory() {
final String name = "secret name for thread factory";
final ThreadFactory factory = r -> new Thread(r, name);
final CountDownLatch latch = new CountDownLatch(1);
new Assertion<>("Must run in the background with specific thread factory", new Async<>(new FuncOf<>(input -> {
if (!input.equals(Thread.currentThread().getName())) {
throw new IllegalStateException("Another thread factory was used");
}
latch.countDown();
}, true), factory), new IsApplicable<>(name, new Satisfies<>(future -> {
future.get();
return latch.getCount() == 0;
}))).affirm();
}
Aggregations