1 9 10 package org.picocontainer.defaults; 11 12 import org.jmock.Mock; 13 import org.jmock.MockObjectTestCase; 14 import org.picocontainer.Disposable; 15 import org.picocontainer.PicoContainer; 16 import org.picocontainer.Startable; 17 18 import java.util.Arrays ; 19 20 26 public class DefaultLifecycleManagerTestCase extends MockObjectTestCase { 27 28 StringBuffer events = new StringBuffer (); 29 Object one; 30 Object two; 31 Object three; 32 33 Mock pico; 34 PicoContainer node; 35 36 class TestComponent implements Startable, Disposable{ 37 String code; 38 39 public TestComponent(String code) { 40 this.code = code; 41 } 42 43 public void start() { 44 events.append("<" + code); 45 } 46 public void stop() { 47 events.append(code + ">"); 48 } 49 50 public void dispose() { 51 events.append("!" + code); 52 } 53 54 } 55 protected void setUp() throws Exception { 56 one = new TestComponent("One"); 57 two = new TestComponent("Two"); 58 three = new TestComponent("Three"); 59 60 pico = mock(PicoContainer.class); 61 node = (PicoContainer) pico.proxy(); 62 63 } 64 65 public void testStartingInInOrder() { 66 67 pico.expects(once()).method("getComponentInstancesOfType").with(same(Startable.class)).will(returnValue(Arrays.asList(new Object [] {one,two,three}))); 68 69 DefaultLifecycleManager dlm = new DefaultLifecycleManager(); 70 dlm.start(node); 71 assertEquals("<One<Two<Three", events.toString()); 72 } 73 74 public void testStoppingInInOrder() { 75 76 pico.expects(once()).method("getComponentInstancesOfType").with(same(Startable.class)).will(returnValue(Arrays.asList(new Object [] {one,two,three}))); 77 78 DefaultLifecycleManager dlm = new DefaultLifecycleManager(); 79 dlm.stop(node); 80 assertEquals("Three>Two>One>", events.toString()); 81 } 82 83 public void testDisposingInInOrder() { 84 85 pico.expects(once()).method("getComponentInstancesOfType").with(same(Disposable.class)).will(returnValue(Arrays.asList(new Object [] {one,two,three}))); 86 87 DefaultLifecycleManager dlm = new DefaultLifecycleManager(); 88 dlm.dispose(node); 89 assertEquals("!Three!Two!One", events.toString()); 90 } 91 92 } 93 | Popular Tags |