ParallelProtocolProducer implements ProtocolProducer { protected <ResourcePoolT extends ResourcePool> void iterate( Iterator<ProtocolProducer> iterator, ProtocolCollection<ResourcePoolT> protocolCollection) { while (iterator.hasNext() && protocolCollection.hasFreeCapacity()) { ProtocolProducer producer = iterator.next(); if (producer.hasNextProtocols()) { producer.getNextProtocols(protocolCollection); } else { iterator.remove(); } } } ParallelProtocolProducer(List<ProtocolProducer> protocols); @Override boolean hasNextProtocols(); @Override void getNextProtocols(
      ProtocolCollection<ResourcePoolT> protocolCollection);  }
@Test public void iterate() { Iterator<ProtocolProducer> iterator = mock(Iterator.class); ProtocolCollection protocolCollection = mock(ProtocolCollection.class); ProtocolProducer protocolProducer = mock(ProtocolProducer.class); when(iterator.hasNext()).thenReturn(true, false); when(protocolCollection.hasFreeCapacity()).thenReturn(true); when(protocolProducer.hasNextProtocols()).thenReturn(false); when(iterator.next()).thenReturn(protocolProducer); List<ProtocolProducer> list = Arrays.asList(protocolProducer); ParallelProtocolProducer parallelProtocolProducer = new ParallelProtocolProducer(list); parallelProtocolProducer.iterate(iterator, protocolCollection); verify(iterator, times(1)).remove(); }