Search in sources :

Example 1 with ListenerService

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