ThreadsProcessingItem extends AbstractProcessingItem { public void setupInstances() { this.piInstances = new ArrayList<ThreadsProcessingItemInstance>(this.getParallelism()); for (int i=0; i<this.getParallelism(); i++) { Processor newProcessor = this.getProcessor().newProcessor(this.getProcessor()); newProcessor.onCreate(i + 1); this.piInstances.add(new ThreadsProcessingItemInstance(newProcessor, this.offset + i)); } } ThreadsProcessingItem(Processor processor, int parallelismHint); List<ThreadsProcessingItemInstance> getProcessingItemInstances(); void processEvent(ContentEvent event, int counter); void setupInstances();  }
@Test public void testSetupInstances() { new Expectations() { { for (int i=0; i<parallelism; i++) { processor.newProcessor(processor); result=processor; processor.onCreate(anyInt); } } }; pi.setupInstances(); List<ThreadsProcessingItemInstance> instances = pi.getProcessingItemInstances(); assertNotNull("List of PI instances is null.",instances); assertEquals("Number of instances does not match parallelism.",parallelism,instances.size(),0); for(int i=0; i<instances.size();i++) { assertNotNull("Instance "+i+" is null.",instances.get(i)); assertEquals("Instance "+i+" is not a ThreadsWorkerProcessingItem.",ThreadsProcessingItemInstance.class,instances.get(i).getClass()); } }