@SuppressWarnings("serial") public List<CandidateSteps> groovySteps() { final DefaultClassLoadingPicoContainer container = new DefaultClassLoadingPicoContainer( new ThreadCaching() .wrap( new CompositeInjection( new ConstructorInjection(), new SetterInjection().withInjectionOptional()))); container.change(Characteristics.USE_NAMES); container.addComponent(WebDriverProvider.class, driverProvider); // This loads all the Groovy classes in pages.* container.visit( new ClassName("pages.Home"), ".*\\.class", true, new DefaultClassLoadingPicoContainer.ClassVisitor() { public void classFound(Class clazz) { container.addComponent(clazz); } }); ClassLoadingPicoContainer steps = container.makeChildContainer("steps"); steps.addComponent(new ClassName("housekeeping.EmptyCartIfNotAlready")); steps.addComponent(new ClassName("EtsyDotComSteps")); return new PicoStepsFactory(configuration, steps).createCandidateSteps(); }
@Test public void testBuildContainerWithParentAndChildAssemblyScopes() throws IOException { String scriptValue = "A = org.picocontainer.script.testmodel.A\n" + "B = org.picocontainer.script.testmodel.B\n" + "ParentAssemblyScope = org.picocontainer.script.testmodel.ParentAssemblyScope\n" + "SomeAssemblyScope = org.picocontainer.script.testmodel.SomeAssemblyScope\n" + "container(:parent => $parent) {\n" + " puts 'assembly_scope:'+$assembly_scope.inspect\n " + " case $assembly_scope\n" + " when ParentAssemblyScope\n " + " puts 'parent scope'\n " + " component(A)\n" + " when SomeAssemblyScope\n " + " puts 'child scope'\n " + " component(B)\n" + " else \n" + " raise 'Invalid Scope: ' + $assembly_scope.inspect\n" + " end\n " + "}\n"; Reader script = new StringReader(scriptValue); ClassLoadingPicoContainer parent = new DefaultClassLoadingPicoContainer( buildContainer(script, null, new ParentAssemblyScope())); assertNotNull(parent.getComponentAdapter(A.class, (NameBinding) null)); script = new StringReader(scriptValue); PicoContainer pico = buildContainer(script, parent, new SomeAssemblyScope()); assertNotNull(pico.getComponent(B.class)); }