use of com.github.robozonky.api.notifications.EventListenerSupplier in project robozonky by RoboZonky.
the class Checker method notifications.
public static boolean notifications(final String username, final List<EventListenerSupplier<RoboZonkyTestingEvent>> refreshables) {
final Collection<EventListener<RoboZonkyTestingEvent>> listeners = refreshables.stream().flatMap(r -> r.get().map(Stream::of).orElse(Stream.empty())).collect(Collectors.toSet());
if (listeners.size() > 0) {
final SessionInfo sessionInfo = new SessionInfo(username);
final RoboZonkyTestingEvent evt = new RoboZonkyTestingEvent();
listeners.forEach(l -> l.handle(evt, sessionInfo));
return true;
} else {
return false;
}
}
use of com.github.robozonky.api.notifications.EventListenerSupplier 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