### Question:
WebConfiguration { public Collection<Module> createModules(Module... standardModules) throws ServletException { Set<String> existingModules = new HashSet<>(); Collection<Module> modules = new ArrayList<>(); if (standardModules != null) { for (Module module : standardModules) { modules.add(module); existingModules.add(module.getClass().getName()); } } String extraModules = configuration.getInitParameter(EXTRA_MODULES_PARAMETER); if (extraModules != null) { StringTokenizer toks = new StringTokenizer(extraModules, ", \n\r"); while (toks.hasMoreTokens()) { String moduleName = toks.nextToken(); if (!existingModules.add(moduleName)) { continue; } Module module; try { module = (Module) Util.getJavaClass(moduleName).newInstance(); } catch (Exception e) { String message = String.format("Error instantiating custom DI module '%s' by filter '%s': %s", moduleName, getClass().getName(), e.getMessage()); throw new ServletException(message, e); } modules.add(module); } } return modules; } WebConfiguration(final ServletConfig servletConfiguration);  WebConfiguration(FilterConfig filterConfiguration); String getConfigurationLocation(); String getDataDomainName(); Collection<Module> createModules(Module... standardModules); Map<String, String> getParameters(); Map<String, String> getOtherParameters();  }### Answer:
@Test public void testFilterCreateModules_Standard() throws Exception { MockFilterConfig config = new MockFilterConfig(); WebConfiguration configuration = new WebConfiguration(config); Module m1 = binder -> { }; Module m2 = binder -> { }; Collection<Module> modules = configuration.createModules(m1, m2); assertEquals(2, modules.size()); Iterator<Module> it = modules.iterator(); assertSame(m1, it.next()); assertSame(m2, it.next()); }
@Test public void testFilterCreateModules_Extra() throws Exception { MockFilterConfig config = new MockFilterConfig(); String exra = String.format( "%s, \n%s", MockModule1.class.getName(), MockModule2.class.getName()); config.setInitParameter(WebConfiguration.EXTRA_MODULES_PARAMETER, exra); WebConfiguration configuration = new WebConfiguration(config); Module m1 = binder -> { }; Module m2 = binder -> { }; Collection<Module> modules = configuration.createModules(m1, m2); assertEquals(4, modules.size()); Iterator<Module> it = modules.iterator(); assertSame(m1, it.next()); assertSame(m2, it.next()); assertTrue(it.next() instanceof MockModule1); assertTrue(it.next() instanceof MockModule2); }
@Test public void testServletCreateModules_Extra() throws Exception { MockServletConfig config = new MockServletConfig(); String exra = String.format( "%s, \n%s", MockModule1.class.getName(), MockModule2.class.getName()); config.setInitParameter(WebConfiguration.EXTRA_MODULES_PARAMETER, exra); WebConfiguration configuration = new WebConfiguration(config); Module m1 = binder -> { }; Module m2 = binder -> { }; Collection<Module> modules = configuration.createModules(m1, m2); assertEquals(4, modules.size()); Iterator<Module> it = modules.iterator(); assertSame(m1, it.next()); assertSame(m2, it.next()); assertTrue(it.next() instanceof MockModule1); assertTrue(it.next() instanceof MockModule2); }