/**
  * Tests the background processing if there are no child initializers.
  *
  * @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it
  */
 @Test
 public void testInitializeNoChildren() throws ConcurrentException {
   assertTrue("Wrong result of start()", initializer.start());
   final MultiBackgroundInitializer.MultiBackgroundInitializerResults res = initializer.get();
   assertTrue("Got child initializers", res.initializerNames().isEmpty());
   assertTrue("Executor not shutdown", initializer.getActiveExecutor().isShutdown());
 }
 /**
  * Tests that the set with the names of the initializers cannot be modified.
  *
  * @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it
  */
 @Test(expected = UnsupportedOperationException.class)
 public void testResultInitializerNamesModify() throws ConcurrentException {
   checkInitialize();
   final MultiBackgroundInitializer.MultiBackgroundInitializerResults res = initializer.get();
   final Iterator<String> it = res.initializerNames().iterator();
   it.next();
   it.remove();
 }
 /**
  * Helper method for testing the initialize() method. This method can operate with both an
  * external and a temporary executor service.
  *
  * @return the result object produced by the initializer
  * @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it
  */
 private MultiBackgroundInitializer.MultiBackgroundInitializerResults checkInitialize()
     throws ConcurrentException {
   final int count = 5;
   for (int i = 0; i < count; i++) {
     initializer.addInitializer(CHILD_INIT + i, new ChildBackgroundInitializer());
   }
   initializer.start();
   final MultiBackgroundInitializer.MultiBackgroundInitializerResults res = initializer.get();
   assertEquals("Wrong number of child initializers", count, res.initializerNames().size());
   for (int i = 0; i < count; i++) {
     final String key = CHILD_INIT + i;
     assertTrue("Name not found: " + key, res.initializerNames().contains(key));
     assertEquals("Wrong result object", Integer.valueOf(1), res.getResultObject(key));
     assertFalse("Exception flag", res.isException(key));
     assertNull("Got an exception", res.getException(key));
     checkChild(res.getInitializer(key), initializer.getActiveExecutor());
   }
   return res;
 }
 /**
  * Tests whether MultiBackgroundInitializers can be combined in a nested way.
  *
  * @throws org.apache.commons.lang3.concurrent.ConcurrentException so we don't have to catch it
  */
 @Test
 public void testInitializeNested() throws ConcurrentException {
   final String nameMulti = "multiChildInitializer";
   initializer.addInitializer(CHILD_INIT, new ChildBackgroundInitializer());
   final MultiBackgroundInitializer mi2 = new MultiBackgroundInitializer();
   final int count = 3;
   for (int i = 0; i < count; i++) {
     mi2.addInitializer(CHILD_INIT + i, new ChildBackgroundInitializer());
   }
   initializer.addInitializer(nameMulti, mi2);
   initializer.start();
   final MultiBackgroundInitializer.MultiBackgroundInitializerResults res = initializer.get();
   final ExecutorService exec = initializer.getActiveExecutor();
   checkChild(res.getInitializer(CHILD_INIT), exec);
   final MultiBackgroundInitializer.MultiBackgroundInitializerResults res2 =
       (MultiBackgroundInitializer.MultiBackgroundInitializerResults)
           res.getResultObject(nameMulti);
   assertEquals("Wrong number of initializers", count, res2.initializerNames().size());
   for (int i = 0; i < count; i++) {
     checkChild(res2.getInitializer(CHILD_INIT + i), exec);
   }
   assertTrue("Executor not shutdown", exec.isShutdown());
 }