KickJava   Java API By Example, From Geeks To Geeks.

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


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  *****************************************************************************/

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 JavaDoc;
19
20 /**
21  * @author Aslak Hellesøy
22  * @author Paul Hammant
23  * @author Ward Cunningham
24  * @version $Revision: 1870 $
25  */

26 public class DefaultLifecycleManagerTestCase extends MockObjectTestCase {
27
28     StringBuffer JavaDoc events = new StringBuffer JavaDoc();
29     Object JavaDoc one;
30     Object JavaDoc two;
31     Object JavaDoc three;
32
33     Mock pico;
34     PicoContainer node;
35
36     class TestComponent implements Startable, Disposable{
37         String JavaDoc code;
38
39         public TestComponent(String JavaDoc 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 JavaDoc {
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 JavaDoc[] {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 JavaDoc[] {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 JavaDoc[] {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