### Question:
RestrictedComponentContainer extends AbstractComponentContainer { @Override public <T> Set<T> setOf(Class<T> anInterface) { if (!allowedSetDirectInterfaces.contains(anInterface)) { throw new IllegalArgumentException( String.format("Attempting to request an undeclared dependency Set<%s>.", anInterface)); } return delegateContainer.setOf(anInterface); } 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);  }### Answer:
@Test public void setOf_withAllowedClass_shouldReturnExpectedSet() { Set<Long> set = Collections.emptySet(); when(delegate.setOf(Long.class)).thenReturn(set); assertThat(container.setOf(Long.class)).isSameInstanceAs(set); verify(delegate).setOf(Long.class); }
@Test public void setOf_withNotAllowedClass_shouldThrow() { try { container.setOf(List.class); fail("Expected exception not thrown."); } catch (IllegalArgumentException ex) { assertThat(ex.getMessage()).contains("java.util.List"); } }
@Test public void setOfProvider_withNotAllowedClass_shouldThrow() { try { container.setOf(List.class); fail("Expected exception not thrown."); } catch (IllegalArgumentException ex) { assertThat(ex.getMessage()).contains("java.util.List"); } }