ThreadsEngine { public static void setNumberOfThreads(int numThreads) { if (numThreads < 1) throw new IllegalStateException("Number of threads must be a positive integer."); if (threadPool.size() > numThreads) throw new IllegalStateException("You cannot set a numThreads smaller than the current size of the threads pool."); if (threadPool.size() < numThreads) { for (int i=threadPool.size(); i<numThreads; i++) { threadPool.add(Executors.newSingleThreadExecutor()); } } }  static void setNumberOfThreads(int numThreads); static int getNumberOfThreads(); static ExecutorService getThreadWithIndex(int index); static void submitTopology(Topology topology, int numThreads); static void clearThreadPool();  }
@Test(expected=IllegalStateException.class) public void testSetNumberOfThreadsDecrease() { ThreadsEngine.setNumberOfThreads(numThreads); ThreadsEngine.setNumberOfThreads(numThreadsSmaller); }
@Test(expected=IllegalStateException.class) public void testSetNumberOfThreadsNegative() { ThreadsEngine.setNumberOfThreads(-1); }
@Test(expected=IllegalStateException.class) public void testSetNumberOfThreadsZero() { ThreadsEngine.setNumberOfThreads(0); }