Search in sources :

Example 1 with EventListenerSupplier

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;
    }
}
Also used : EventListenerSupplier(com.github.robozonky.api.notifications.EventListenerSupplier) Logger(org.slf4j.Logger) Collection(java.util.Collection) ApiProvider(com.github.robozonky.common.remote.ApiProvider) LoggerFactory(org.slf4j.LoggerFactory) RawLoan(com.github.robozonky.api.remote.entities.RawLoan) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) SessionInfo(com.github.robozonky.api.notifications.SessionInfo) List(java.util.List) Stream(java.util.stream.Stream) RequestId(com.github.robozonky.api.confirmations.RequestId) EventListener(com.github.robozonky.api.notifications.EventListener) Optional(java.util.Optional) RoboZonkyTestingEvent(com.github.robozonky.api.notifications.RoboZonkyTestingEvent) Comparator(java.util.Comparator) ConfirmationProvider(com.github.robozonky.api.confirmations.ConfirmationProvider) SessionInfo(com.github.robozonky.api.notifications.SessionInfo) EventListener(com.github.robozonky.api.notifications.EventListener) RoboZonkyTestingEvent(com.github.robozonky.api.notifications.RoboZonkyTestingEvent)

Example 2 with EventListenerSupplier

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"));
}
Also used : ListenerService(com.github.robozonky.api.notifications.ListenerService) Test(org.junit.jupiter.api.Test) EventListenerSupplier(com.github.robozonky.api.notifications.EventListenerSupplier) Mockito(org.mockito.Mockito) Arrays(java.util.Arrays) List(java.util.List) RoboZonkyStartingEvent(com.github.robozonky.api.notifications.RoboZonkyStartingEvent) EventListener(com.github.robozonky.api.notifications.EventListener) Condition(org.assertj.core.api.Condition) Optional(java.util.Optional) Assertions(org.assertj.core.api.Assertions) RoboZonkyTestingEvent(com.github.robozonky.api.notifications.RoboZonkyTestingEvent) ListenerService(com.github.robozonky.api.notifications.ListenerService) RoboZonkyStartingEvent(com.github.robozonky.api.notifications.RoboZonkyStartingEvent) EventListenerSupplier(com.github.robozonky.api.notifications.EventListenerSupplier) Test(org.junit.jupiter.api.Test)

Aggregations

EventListener (com.github.robozonky.api.notifications.EventListener)2 EventListenerSupplier (com.github.robozonky.api.notifications.EventListenerSupplier)2 RoboZonkyTestingEvent (com.github.robozonky.api.notifications.RoboZonkyTestingEvent)2 List (java.util.List)2 Optional (java.util.Optional)2 ConfirmationProvider (com.github.robozonky.api.confirmations.ConfirmationProvider)1 RequestId (com.github.robozonky.api.confirmations.RequestId)1 ListenerService (com.github.robozonky.api.notifications.ListenerService)1 RoboZonkyStartingEvent (com.github.robozonky.api.notifications.RoboZonkyStartingEvent)1 SessionInfo (com.github.robozonky.api.notifications.SessionInfo)1 RawLoan (com.github.robozonky.api.remote.entities.RawLoan)1 ApiProvider (com.github.robozonky.common.remote.ApiProvider)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Assertions (org.assertj.core.api.Assertions)1 Condition (org.assertj.core.api.Condition)1