EventComponentImpl implements EventComponent { @Override @SuppressWarnings("unchecked") public <E extends Event> void on(Class<E> event, Consumer<E> action) { listeners(event).add((Consumer<Event>) action); } EventComponentImpl(); @Override void notify(Event event); @Override @SuppressWarnings("unchecked") void on(Class<E> event, Consumer<E> action); @Override void on(DefaultEvent event, Consumer<DefaultEvent> action); @Override void onAny(Consumer<Event> action);  }
@Test void on() { final FooEventConsumer eventConsumer = new FooEventConsumer(); instance.on(FooEvent.class, eventConsumer); final List<Event> events = Arrays.asList(new FooEvent(), new BarEvent()); final List<Event> expected = events.stream().filter(FooEvent.class::isInstance).collect(Collectors.toList()); expected.forEach(instance::notify); assertEquals(expected, eventConsumer.events()); }