SessionEvents { @SuppressWarnings("unchecked") static <T extends Event> Class<T> getImplementingEvent(final Class<T> original) { final Stream<Class<?>> provided = ClassUtil.getAllInterfaces(original); final Stream<Class<?>> interfaces = original.isInterface() ? Stream.concat(Stream.of(original), provided) : provided; final String apiPackage = "com.github.robozonky.api.notifications"; return (Class<T>) interfaces.filter(i -> Objects.equals(i.getPackage() .getName(), apiPackage)) .filter(i -> i.getSimpleName() .endsWith("Event")) .filter(i -> !Objects.equals(i.getSimpleName(), "Event")) .findFirst() .orElseThrow(); } private  SessionEvents(final SessionInfo sessionInfo); SessionInfo getSessionInfo(); boolean addListener(final EventFiringListener listener); boolean removeListener(final EventFiringListener listener); CompletableFuture fire(final LazyEvent<? extends SessionEvent> event); @SuppressWarnings("unchecked") CompletableFuture fire(final SessionEvent event); boolean isListenerRegistered(final Class<? extends Event> eventClass);  }
@Test void identifiesEventTypeWhenClass() { Loan l = MockLoanBuilder.fresh(); Investment i = MockInvestmentBuilder.fresh(l, 200) .build(); final LoanDelinquent90DaysOrMoreEvent e = EventFactory.loanDelinquent90plus(i, l); assertThat(SessionEvents.getImplementingEvent(e.getClass())) .isEqualTo(LoanDelinquent90DaysOrMoreEvent.class); }
@Test void identifiesEventTypeWhenInterface() { assertThat(SessionEvents.getImplementingEvent(LoanDelinquent90DaysOrMoreEvent.class)) .isEqualTo(LoanDelinquent90DaysOrMoreEvent.class); }