@Test public void get_withNotAllowedClass_shouldThrow() { try { container.get(List.class); fail("Expected exception not thrown."); } catch (IllegalArgumentException ex) { assertThat(ex.getMessage()).contains("java.util.List"); } }
@Override public <T> T get(Class<T> anInterface) { if (!allowedDirectInterfaces.contains(anInterface)) { throw new IllegalArgumentException( String.format("Attempting to request an undeclared dependency %s.", anInterface)); } T value = delegateContainer.get(anInterface); if (!anInterface.equals(Publisher.class)) { return value; } @SuppressWarnings("unchecked") T publisher = (T) new RestrictedPublisher(allowedPublishedEvents, (Publisher) value); return publisher; }
RestrictedComponentContainer extends AbstractComponentContainer { @Override public <T> T get(Class<T> anInterface) { if (!allowedDirectInterfaces.contains(anInterface)) { throw new IllegalArgumentException( String.format("Attempting to request an undeclared dependency %s.", anInterface)); } T value = delegateContainer.get(anInterface); if (!anInterface.equals(Publisher.class)) { return value; } @SuppressWarnings("unchecked") T publisher = (T) new RestrictedPublisher(allowedPublishedEvents, (Publisher) value); return publisher; } }
RestrictedComponentContainer extends AbstractComponentContainer { @Override public <T> T get(Class<T> anInterface) { if (!allowedDirectInterfaces.contains(anInterface)) { throw new IllegalArgumentException( String.format("Attempting to request an undeclared dependency %s.", anInterface)); } T value = delegateContainer.get(anInterface); if (!anInterface.equals(Publisher.class)) { return value; } @SuppressWarnings("unchecked") T publisher = (T) new RestrictedPublisher(allowedPublishedEvents, (Publisher) value); return publisher; } RestrictedComponentContainer(Component<?> component, ComponentContainer container); }
RestrictedComponentContainer extends AbstractComponentContainer { @Override public <T> T get(Class<T> anInterface) { if (!allowedDirectInterfaces.contains(anInterface)) { throw new IllegalArgumentException( String.format("Attempting to request an undeclared dependency %s.", anInterface)); } T value = delegateContainer.get(anInterface); if (!anInterface.equals(Publisher.class)) { return value; } @SuppressWarnings("unchecked") T publisher = (T) new RestrictedPublisher(allowedPublishedEvents, (Publisher) value); return publisher; } RestrictedComponentContainer(Component<?> component, ComponentContainer container); @Override T get(Class<T> anInterface); @Override Provider<T> getProvider(Class<T> anInterface); @Override Provider<Set<T>> setOfProvider(Class<T> anInterface); @Override Set<T> setOf(Class<T> anInterface); }
RestrictedComponentContainer extends AbstractComponentContainer { @Override public <T> T get(Class<T> anInterface) { if (!allowedDirectInterfaces.contains(anInterface)) { throw new IllegalArgumentException( String.format("Attempting to request an undeclared dependency %s.", anInterface)); } T value = delegateContainer.get(anInterface); if (!anInterface.equals(Publisher.class)) { return value; } @SuppressWarnings("unchecked") T publisher = (T) new RestrictedPublisher(allowedPublishedEvents, (Publisher) value); return publisher; } RestrictedComponentContainer(Component<?> component, ComponentContainer container); @Override T get(Class<T> anInterface); @Override Provider<T> getProvider(Class<T> anInterface); @Override Provider<Set<T>> setOfProvider(Class<T> anInterface); @Override Set<T> setOf(Class<T> anInterface);  }