DynamicEventizerProvider implements EventizerProvider { @SuppressWarnings("unchecked") @Override public <T> Eventizer<T> getEventizerForType(Class<T> type) { Eventizer<T> eventizer = (Eventizer<T>) cache.get(type); if (eventizer == null) { eventizer = new DynamicEventizer<>(type); cache.put(type, eventizer); } return eventizer; }  @SuppressWarnings("unchecked") @Override Eventizer<T> getEventizerForType(Class<T> type);  }
@Test public void returns_an_eventizer_for_any_listener_interface() { DynamicEventizerProvider provider = new DynamicEventizerProvider(); Eventizer<DummyListener> eventizer = provider.getEventizerForType(DummyListener.class); assertThat(eventizer.getType()).isEqualTo(DummyListener.class); }
@Test public void caches_the_eventizer_instances() { DynamicEventizerProvider provider = new DynamicEventizerProvider(); Eventizer<DummyListener> eventizer1 = provider.getEventizerForType(DummyListener.class); Eventizer<DummyListener> eventizer2 = provider.getEventizerForType(DummyListener.class); assertThat(eventizer1).isSameAs(eventizer2); }