EventService { public void unsubscribe(EventSubscriber<?> subscriber) { final Class<?> eventType = getEventType(subscriber); doUnsubscribe(subscriber, eventType); } @SuppressWarnings("unchecked")  EventService(); @SuppressWarnings("unchecked") T publish(T event); void subscribe(EventSubscriber<?> subscriber); void subscribe(EventSubscriber<? extends T> subscriber, Class<T> eventType); void unsubscribe(EventSubscriber<?> subscriber); void unsubscribe(EventSubscriber<T> subscriber, Class<T> eventType);  }
@Test public void testUnsubscribe() { final List<String> events = new ArrayList<>(); EventSubscriber<Event> l = new EventSubscriber<Event>() { @Override public void onEvent(Event event) { events.add(event.data); } }; bus.subscribe(l); bus.publish(new Event()); Assert.assertEquals(events.size(), 1); bus.unsubscribe(l); events.clear(); bus.publish(new Event()); Assert.assertEquals(events.size(), 0); }