use of org.cactoos.matchers.MatcherOf in project cactoos by yegor256.
the class AsyncFuncTest method runsInBackgroundWithoutFuture.
@Test
public void runsInBackgroundWithoutFuture() {
final CountDownLatch latch = new CountDownLatch(1);
MatcherAssert.assertThat("Can't run in the background without us touching the Future", new AsyncFunc<>(input -> {
latch.countDown();
}), new FuncApplies<>(true, new MatcherOf<Future<String>>(future -> {
return latch.await(1L, TimeUnit.SECONDS);
})));
}
use of org.cactoos.matchers.MatcherOf in project cactoos by yegor256.
the class RunnableOfTest method convertsProcIntoRunnable.
@Test
public void convertsProcIntoRunnable() {
final AtomicBoolean done = new AtomicBoolean();
MatcherAssert.assertThat("Can't execute Runnable with ProcOf", new RunnableOf<>(new ProcOf<>(input -> {
done.set(true);
return 1;
})), new MatcherOf<Runnable>(input -> {
input.run();
return done.get();
}));
}
use of org.cactoos.matchers.MatcherOf in project cactoos by yegor256.
the class RunnableOfTest method convertsFuncIntoRunnable.
@Test
public void convertsFuncIntoRunnable() {
final AtomicBoolean done = new AtomicBoolean();
MatcherAssert.assertThat("Can't execute Runnable with Func", new RunnableOf<>(input -> {
done.set(true);
return 1;
}), new MatcherOf<Runnable>(input -> {
input.run();
return done.get();
}));
}
use of org.cactoos.matchers.MatcherOf in project cactoos by yegor256.
the class RunnableOfTest method convertsCallableIntoRunnable.
@Test
public void convertsCallableIntoRunnable() {
final AtomicBoolean done = new AtomicBoolean();
MatcherAssert.assertThat("Can't execute Runnable with Callable", new RunnableOf<>(() -> {
done.set(true);
return null;
}), new MatcherOf<Runnable>(input -> {
input.run();
return done.get();
}));
}
use of org.cactoos.matchers.MatcherOf in project cactoos by yegor256.
the class AsyncFuncTest method runsInBackgroundWithThreadFactory.
@Test
public void runsInBackgroundWithThreadFactory() {
final String name = "secret name for thread factory";
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 factory", new AsyncFunc<>(input -> {
if (!input.equals(Thread.currentThread().getName())) {
throw new IllegalStateException("Another thread factory was used");
}
latch.countDown();
}, factory), new FuncApplies<>(name, new MatcherOf<Future<Void>>(future -> {
future.get();
return latch.getCount() == 0;
})));
}
Aggregations