private Module[] getModules(Guice guice, Class<?> testClass) { List<Module> result = Lists.newArrayList(); for (Class<? extends Module> moduleClass : guice.modules()) { try { result.add(moduleClass.newInstance()); } catch (InstantiationException e) { throw new TestNGException(e); } catch (IllegalAccessException e) { throw new TestNGException(e); } } Class<? extends IModuleFactory> factory = guice.moduleFactory(); if (factory != IModuleFactory.class) { try { IModuleFactory factoryInstance = factory.newInstance(); Module moduleClass = factoryInstance.createModule(m_testContext, testClass); if (moduleClass != null) { result.add(moduleClass); } } catch (InstantiationException e) { throw new TestNGException(e); } catch (IllegalAccessException e) { throw new TestNGException(e); } } return result.toArray(new Module[result.size()]); }