use of org.llorllale.cactoos.matchers.Assertion 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();
}
use of org.llorllale.cactoos.matchers.Assertion in project cactoos by yegor256.
the class IoCheckedFuncTest method rethrowsIoException.
@Test
void rethrowsIoException() {
final IOException exception = new IOException("intended");
new Assertion<>("Must rethrow original IOException", () -> new IoCheckedFunc<>(i -> {
throw exception;
}).apply(1), new Throws<>(exception.getMessage(), exception.getClass())).affirm();
}
use of org.llorllale.cactoos.matchers.Assertion 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();
}
}
use of org.llorllale.cactoos.matchers.Assertion in project cactoos by yegor256.
the class IoCheckedBiFuncTest method rethrowsIoException.
@Test
public void rethrowsIoException() {
final IOException exception = new IOException("intended");
new Assertion<>("Must rethrow IOException", () -> new IoCheckedBiFunc<>((fst, scd) -> {
throw exception;
}).apply(1, 2), new Throws<>(exception.getMessage(), exception.getClass())).affirm();
}
use of org.llorllale.cactoos.matchers.Assertion in project cactoos by yegor256.
the class CheckedBiProcTest method noExceptionThrown.
@Test
public void noExceptionThrown() throws Exception {
final AtomicInteger counter = new AtomicInteger();
new CheckedBiProc<>((first, second) -> counter.incrementAndGet(), exp -> exp).exec(true, true);
new Assertion<>("Must not throw an exception", counter.get(), new IsEqual<>(1)).affirm();
}
Aggregations