1 8 package org.picocontainer.defaults; 9 10 import java.io.Serializable ; 11 12 import org.jmock.Mock; 13 import org.jmock.MockObjectTestCase; 14 import org.picocontainer.Disposable; 15 import org.picocontainer.Startable; 16 import org.picocontainer.monitors.DefaultComponentMonitor; 17 18 22 public class DefaultLifecycleStrategyTestCase extends MockObjectTestCase { 23 24 private DefaultLifecycleStrategy strategy; 25 26 public void setUp(){ 27 strategy = new DefaultLifecycleStrategy(new DefaultComponentMonitor()); 28 } 29 30 public void testStartable(){ 31 Object startable = mockComponent(true, false); 32 strategy.start(startable); 33 strategy.stop(startable); 34 } 35 36 public void testDisposable(){ 37 Object startable = mockComponent(false, true); 38 strategy.dispose(startable); 39 } 40 41 public void testSerializable(){ 42 Object serializable = mockComponent(false, false); 43 strategy.start(serializable); 44 strategy.stop(serializable); 45 strategy.dispose(serializable); 46 } 47 48 private Object mockComponent(boolean startable, boolean disposeable) { 49 Mock mock = mock(Serializable .class); 50 if ( startable ) { 51 mock = mock(Startable.class); 52 mock.expects(atLeastOnce()).method("start"); 53 mock.expects(atLeastOnce()).method("stop"); 54 } 55 if ( disposeable ) { 56 mock = mock(Disposable.class); 57 mock.expects(atLeastOnce()).method("dispose"); 58 } 59 return mock.proxy(); 60 } 61 } 62 | Popular Tags |