### Question:
ComponentItems implements Iterable<I> { @Override public Iterator<I> iterator() { return stream(delegate.spliterator(), false) .filter(item -> item.belongsToComponent(component)) .filter(item -> item.belongsToContext(context)) .iterator(); } ComponentItems(String component, String context, Iterable<I> delegate); @Override Iterator<I> iterator();  }### Answer:
@Test public void testSomeMatch(){ FakeComponentItem matching = new FakeComponentItem(true); List<FakeComponentItem> fakes = asList(new FakeComponentItem(false), matching, new FakeComponentItem(false)); ComponentItems<FakeComponentItem> component = new ComponentItems<>("component", Topology.DEFAULT_CONTEXT, fakes); Iterator<FakeComponentItem> iterator = component.iterator(); assertTrue(iterator.hasNext()); assertEquals(matching, iterator.next()); assertFalse(iterator.hasNext()); }
@Test public void testNoMatch(){ List<FakeComponentItem> fakes = asList(new FakeComponentItem(false), new FakeComponentItem(false)); ComponentItems<FakeComponentItem> component = new ComponentItems<>("component", Topology.DEFAULT_CONTEXT, fakes); Iterator<FakeComponentItem> iterator = component.iterator(); assertFalse(iterator.hasNext()); }
@Test public void testAllMatch(){ FakeComponentItem matching = new FakeComponentItem(true); List<FakeComponentItem> fakes = asList(matching, matching); ComponentItems<FakeComponentItem> component = new ComponentItems<>("component", Topology.DEFAULT_CONTEXT, fakes); Iterator<FakeComponentItem> iterator = component.iterator(); assertTrue(iterator.hasNext()); assertEquals(matching, iterator.next()); assertEquals(matching, iterator.next()); assertFalse(iterator.hasNext()); }