use of org.cactoos.matchers.MatcherOf in project cactoos by yegor256.
the class AsyncFuncTest method runsInBackgroundWithExecutorService.
@Test
public void runsInBackgroundWithExecutorService() {
final String name = "secret name for thread executor";
final ThreadFactory factory = r -> new Thread(r, name);
final CountDownLatch latch = new CountDownLatch(1);
MatcherAssert.assertThat("Can't run in the background with specific thread executor", new AsyncFunc<>(input -> {
if (!input.equals(Thread.currentThread().getName())) {
throw new IllegalStateException("Another thread executor was used");
}
latch.countDown();
}, Executors.newSingleThreadExecutor(factory)), new FuncApplies<>(name, new MatcherOf<Future<Void>>(future -> {
future.get();
return latch.getCount() == 0;
})));
}
Aggregations