ProjectCommandExecutor { public void add(final IExecutorCommand eCommand){ synchronized (ProjectCommandExecutor.this) { checkState(); if (eCommand.canStart()){ runCommand(eCommand); } else { queue.add(eCommand); } } } ProjectCommandExecutor();  ProjectCommandExecutor(int numThreads); void add(final IExecutorCommand eCommand); void stop();  }
@Test public void testAll() throws InterruptedException{ final Boolean[] canGo = new Boolean[]{false, true, true, false, false}; IExecutorCommand[] commands = new IExecutorCommand[]{ new SimpleIExecutor(canGo, 0, 3), new SimpleIExecutor(canGo, 1, -1), new SimpleIExecutor(canGo, 2, 0), new SimpleIExecutor(canGo, 3, -1), new SimpleIExecutor(canGo, 4, -1), }; ProjectCommandExecutor executor = new ProjectCommandExecutor(); Boolean[][] expectations = new Boolean[][]{ new Boolean[]{false, true, true, false, false}, new Boolean[]{false, false, true, false, false}, new Boolean[]{false, false, false, true, false}, new Boolean[]{false, false, false, false, false}, new Boolean[]{false, false, false, false, false,}, }; for (int i=0;i<canGo.length;i++){ executor.add(commands[i]); Thread.sleep(timeout); assertArrayEquals("Error in " + i + " iteration", expectations[i], canGo); } }
@Test public void testFailingCommand() throws InterruptedException{ final Boolean[] ok = new Boolean[]{false}; ProjectCommandExecutor executor = new ProjectCommandExecutor(); IExecutorCommand iec = new FailingCommand(ok); executor.add(iec); Thread.sleep(timeout); assertEquals("Failing command wasn't cleaned", true, ok[0]); }