KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > picocontainer > defaults > DefaultLifecycleStrategyTestCase


1 /*****************************************************************************
2  * Copyright (C) PicoContainer Organization. All rights reserved. *
3  * ------------------------------------------------------------------------- *
4  * The software in this package is published under the terms of the BSD *
5  * style license a copy of which has been included with this distribution in *
6  * the LICENSE.txt file. *
7  *****************************************************************************/

8 package org.picocontainer.defaults;
9
10 import java.io.Serializable JavaDoc;
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 /**
19  *
20  * @author Mauro Talevi
21  */

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 JavaDoc startable = mockComponent(true, false);
32         strategy.start(startable);
33         strategy.stop(startable);
34     }
35
36     public void testDisposable(){
37         Object JavaDoc startable = mockComponent(false, true);
38         strategy.dispose(startable);
39     }
40
41     public void testSerializable(){
42         Object JavaDoc serializable = mockComponent(false, false);
43         strategy.start(serializable);
44         strategy.stop(serializable);
45         strategy.dispose(serializable);
46     }
47     
48     private Object JavaDoc mockComponent(boolean startable, boolean disposeable) {
49         Mock mock = mock(Serializable JavaDoc.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