1 package org.picocontainer.defaults.issues; 2 3 import org.jmock.MockObjectTestCase; 4 import org.jmock.Mock; 5 import org.picocontainer.ComponentMonitor; 6 import org.picocontainer.Startable; 7 import org.picocontainer.defaults.DefaultPicoContainerTestCase; 8 import org.picocontainer.defaults.DefaultPicoContainer; 9 10 import java.lang.reflect.Method ; 11 12 public class Issue0265TestCase extends MockObjectTestCase { 13 14 public void testCanReallyChangeMonitor() throws SecurityException , NoSuchMethodException { 15 Method start = Startable.class.getMethod("start", null); 16 Method stop = Startable.class.getMethod("stop", null); 17 Mock mockMonitor1 = mock(ComponentMonitor.class, "Monitor1"); 18 Mock mockMonitor2 = mock(ComponentMonitor.class, "Monitor2"); 19 DefaultPicoContainer pico = new DefaultPicoContainer((ComponentMonitor) mockMonitor1.proxy()); 20 pico.registerComponentImplementation(DefaultPicoContainerTestCase.MyStartable.class); 21 mockMonitor1.expects(once()).method("instantiating"); 22 mockMonitor1.expects(once()).method("instantiated"); 23 mockMonitor1.expects(once()).method("invoking").with(eq(start), ANYTHING); 24 mockMonitor1.expects(once()).method("invoked").with(eq(start), ANYTHING, ANYTHING); 25 mockMonitor1.expects(once()).method("invoking").with(eq(stop), ANYTHING); 26 mockMonitor1.expects(once()).method("invoked").with(eq(stop), ANYTHING, ANYTHING); 27 pico.start(); 28 pico.stop(); 29 Startable startable = (Startable) pico.getComponentInstance(DefaultPicoContainerTestCase.MyStartable.class); 30 assertNotNull(startable); 31 pico.changeMonitor((ComponentMonitor) mockMonitor2.proxy()); 32 mockMonitor2.expects(once()).method("invoking").with(eq(start), ANYTHING); 33 mockMonitor2.expects(once()).method("invoked").with(eq(start), ANYTHING, ANYTHING); 34 mockMonitor2.expects(once()).method("invoking").with(eq(stop), ANYTHING); 35 mockMonitor2.expects(once()).method("invoked").with(eq(stop), ANYTHING, ANYTHING); 36 pico.start(); 37 pico.stop(); 38 } 39 40 } 41 | Popular Tags |