Package org.nanocontainer.script.groovy

Source Code of org.nanocontainer.script.groovy.GroovyScriptGeneratorTestCase

package org.nanocontainer.script.groovy;

import junit.framework.TestCase;
import org.picocontainer.MutablePicoContainer;
import org.picocontainer.PicoContainer;
import org.picocontainer.defaults.DefaultPicoContainer;

import java.io.StringReader;
import java.util.ArrayList;

/**
* @author Aslak Hellesøy
* @version $Revision: 2447 $
*/
public class GroovyScriptGeneratorTestCase extends TestCase {
    public void testShouldWriteAGroovyScriptThatAllowsToRecreateASimilarContainer() {
        MutablePicoContainer pico = new DefaultPicoContainer();
        pico.registerComponentImplementation(ArrayList.class);
        pico.registerComponentInstance("Hello", "World");

        GroovyScriptGenerator groovyScriptGenerator = new GroovyScriptGenerator();
        String script = groovyScriptGenerator.generateScript(pico);

        GroovyContainerBuilder groovyContainerBuilder = new GroovyContainerBuilder(new StringReader(script), getClass().getClassLoader());
        PicoContainer newPico = groovyContainerBuilder.createContainerFromScript(null, null);

        assertNotNull(newPico.getComponentInstanceOfType(ArrayList.class));
        assertEquals("World", newPico.getComponentInstance("Hello"));
    }
}
TOP

Related Classes of org.nanocontainer.script.groovy.GroovyScriptGeneratorTestCase

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.