KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > picocontainer > defaults > issues > Issue0265TestCase


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 JavaDoc;
11
12 public class Issue0265TestCase extends MockObjectTestCase {
13
14     public void testCanReallyChangeMonitor() throws SecurityException JavaDoc, NoSuchMethodException JavaDoc {
15         Method JavaDoc start = Startable.class.getMethod("start", null);
16         Method JavaDoc 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