ComposedEventizerProvider implements EventizerProvider { @SuppressWarnings({"unchecked"}) @Override public <T> Eventizer<T> getEventizerForType(Class<T> type) { Eventizer<?> eventizer = eventizers.get(type); if (eventizer == null) { throw new IllegalArgumentException("unsupported type: " + type); } return (Eventizer<T>) eventizer; } ComposedEventizerProvider(Eventizer<?>... eventizers); @SuppressWarnings({"unchecked"}) @Override Eventizer<T> getEventizerForType(Class<T> type);  }
@Test public void returns_an_eventizer_which_corresponds_the_specified_type() { Class<Integer> type1 = Integer.class; Eventizer<Integer> eventizer1 = new DummyEventizer<>(type1); Class<Double> type2 = Double.class; Eventizer<Double> eventizer2 = new DummyEventizer<>(type2); ComposedEventizerProvider provider = new ComposedEventizerProvider(eventizer1, eventizer2); assertThat(provider.getEventizerForType(type1), is(eventizer1)); assertThat(provider.getEventizerForType(type2), is(eventizer2)); }
@Test public void cannot_return_eventizers_for_unsupported_types() { ComposedEventizerProvider provider = new ComposedEventizerProvider(); thrown.expect(IllegalArgumentException.class); thrown.expectMessage("unsupported type"); thrown.expectMessage(NoEventizerForThisListener.class.getName()); provider.getEventizerForType(NoEventizerForThisListener.class); }