use of com.github.robozonky.api.notifications.ListenerService 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"));
}
Aggregations