1 10 package org.nanocontainer.script.bsh; 11 12 import java.util.ArrayList ; 13 14 import junit.framework.TestCase; 15 16 import org.picocontainer.ComponentAdapter; 17 import org.picocontainer.MutablePicoContainer; 18 import org.picocontainer.defaults.DefaultPicoContainer; 19 20 29 public class BeanShellComponentAdapterTestCase extends TestCase { 30 31 private MutablePicoContainer pico; 32 33 ComponentAdapter setupComponentAdapter(Class implementation) { 34 pico = new DefaultPicoContainer(); 35 pico.registerComponentImplementation("whatever", ArrayList .class); 36 37 ComponentAdapter adapter = new BeanShellComponentAdapter("thekey", implementation, null); 38 pico.registerComponent(adapter); 39 return adapter; 40 } 41 42 public void testGetComponentInstance() { 43 ComponentAdapter adapter = setupComponentAdapter(ScriptableDemoBean.class); 44 45 ScriptableDemoBean bean = (ScriptableDemoBean) adapter.getComponentInstance(pico); 46 47 assertEquals("Bsh demo script should have set the key", "thekey", bean.key); 48 49 assertTrue(bean.whatever instanceof ArrayList ); 50 } 51 52 public void testGetComponentInstanceBadScript() { 53 ComponentAdapter adapter = setupComponentAdapter(BadScriptableDemoBean.class); 54 55 try { 56 adapter.getComponentInstance(pico); 57 fail("did not throw exception on missing 'instance' variable"); 58 } catch (BeanShellScriptInitializationException bssie) { 59 } 61 } 62 63 } 64 | Popular Tags |