use of org.assertj.core.api.Condition in project robozonky by RoboZonky.
the class ListenerServiceLoaderTest method correctLoading.
@Test
void correctLoading() {
final RoboZonkyStartingEvent e = new RoboZonkyStartingEvent();
final EventListener<RoboZonkyStartingEvent> l = mock(EventListener.class);
final ListenerService s1 = mock(ListenerService.class);
final EventListenerSupplier<RoboZonkyStartingEvent> returned = () -> Optional.of(l);
doReturn(returned).when(s1).findListener(eq(e.getClass()));
final ListenerService s2 = mock(ListenerService.class);
doReturn((EventListenerSupplier<RoboZonkyStartingEvent>) Optional::empty).when(s2).findListener(eq(e.getClass()));
final Iterable<ListenerService> s = () -> Arrays.asList(s1, s2).iterator();
final List<EventListenerSupplier<RoboZonkyStartingEvent>> r = ListenerServiceLoader.load(RoboZonkyStartingEvent.class, s);
assertThat(r).hasSize(2);
assertThat(r).first().has(new Condition<>(result -> result.get().isPresent() && result.get().get() == l, "Exists"));
assertThat(r).last().has(new Condition<>(result -> !result.get().isPresent(), "Does not exist"));
}
use of org.assertj.core.api.Condition in project sandbox by irof.
the class ParallelStreamSample method sampleInForkJoinWorkerThread.
@Test
public void sampleInForkJoinWorkerThread() throws Exception {
RecursiveTask<List<String>> task = new RecursiveTask<List<String>>() {
@Override
protected List<String> compute() {
// ForkJoinPoolのThreadの中でparallelに実行します。
return IntStream.rangeClosed(1, 5).parallel().mapToObj(i -> Thread.currentThread().getName()).collect(toList());
}
};
ForkJoinPool forkJoinPool = new ForkJoinPool();
List<String> collected = forkJoinPool.invoke(task);
// ForkJoinPoolの中で実行されているので、すべてForkJoinPoolのスレッド名になっているはずです。
assertThat(collected).are(new Condition<>(str -> str.startsWith("ForkJoinPool-"), "start with 'ForkJoinPool-'"));
forkJoinPool.shutdown();
}
use of org.assertj.core.api.Condition in project TestFX by TestFX.
the class Adapter method adaptMatcher.
private static <T> Condition<? super T> adaptMatcher(Matcher<? extends T> matcher, boolean invert) {
return new Condition<T>() {
@Override
public boolean matches(T t) {
boolean matches = matcher.matches(t);
if (invert) {
matches = !matches;
}
if (!matches) {
StringDescription reasonDescription = new StringDescription();
matcher.describeTo(reasonDescription);
// at each "assertThat" call site.
throw new AssertionError(getErrorMessage(matcher, t, invert));
}
return true;
}
};
}
use of org.assertj.core.api.Condition in project reactor-core by reactor.
the class WorkQueueProcessorTest method testCustomRequestTaskThreadNameShare.
@Test
public void testCustomRequestTaskThreadNameShare() {
String expectedName = "workQueueProcessorRequestTaskShare";
// NOTE: the below single executor should not be used usually as requestTask assumes it immediately gets executed
ExecutorService customTaskExecutor = Executors.newSingleThreadExecutor(r -> new Thread(r, expectedName));
WorkQueueProcessor<Object> processor = WorkQueueProcessor.builder().executor(Executors.newCachedThreadPool()).requestTaskExecutor(customTaskExecutor).bufferSize(8).waitStrategy(WaitStrategy.liteBlocking()).autoCancel(true).build();
processor.requestTask(Operators.cancelledSubscription());
processor.subscribe();
Thread[] threads = new Thread[Thread.activeCount()];
Thread.enumerate(threads);
// cleanup to avoid visibility in other tests
customTaskExecutor.shutdownNow();
processor.forceShutdown();
Condition<Thread> customRequestTaskThread = new Condition<>(thread -> expectedName.equals(thread.getName()), "a thread named \"%s\"", expectedName);
Assertions.assertThat(threads).haveExactly(1, customRequestTaskThread);
}
use of org.assertj.core.api.Condition in project reactor-core by reactor.
the class WorkQueueProcessorTest method testCustomRequestTaskThreadNameCreate.
@Test
public void testCustomRequestTaskThreadNameCreate() {
String expectedName = "workQueueProcessorRequestTaskCreate";
// NOTE: the below single executor should not be used usually as requestTask assumes it immediately gets executed
ExecutorService customTaskExecutor = Executors.newSingleThreadExecutor(r -> new Thread(r, expectedName));
WorkQueueProcessor<Object> processor = WorkQueueProcessor.builder().executor(Executors.newCachedThreadPool()).requestTaskExecutor(customTaskExecutor).bufferSize(8).waitStrategy(WaitStrategy.liteBlocking()).autoCancel(true).build();
processor.requestTask(Operators.cancelledSubscription());
processor.subscribe();
Thread[] threads = new Thread[Thread.activeCount()];
Thread.enumerate(threads);
// cleanup to avoid visibility in other tests
customTaskExecutor.shutdownNow();
processor.forceShutdown();
Condition<Thread> customRequestTaskThread = new Condition<>(thread -> expectedName.equals(thread.getName()), "a thread named \"%s\"", expectedName);
Assertions.assertThat(threads).haveExactly(1, customRequestTaskThread);
}
Aggregations