KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hivemind > test > rules > TestSetModule


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package hivemind.test.rules;
16
17 import hivemind.test.FrameworkTestCase;
18
19 import org.apache.hivemind.impl.ModuleImpl;
20 import org.apache.hivemind.internal.Module;
21 import org.apache.hivemind.schema.SchemaProcessor;
22 import org.apache.hivemind.schema.rules.SetModuleRule;
23 import org.easymock.MockControl;
24
25 /**
26  * Tests the {@link org.apache.hivemind.schema.rules.SetModuleRule} rule class.
27  *
28  * @author Howard Lewis Ship
29  */

30 public class TestSetModule extends FrameworkTestCase
31 {
32     public static class Target
33     {
34         private Module _module;
35
36         public Module getModule()
37         {
38             return _module;
39         }
40
41         public void setModule(Module module)
42         {
43             _module = module;
44         }
45
46     }
47
48     public void testSetModuleRule()
49     {
50         MockControl control = newControl(SchemaProcessor.class);
51         SchemaProcessor p = (SchemaProcessor) control.getMock();
52
53         Module m = new ModuleImpl();
54         Target t = new Target();
55
56         p.peek();
57         control.setReturnValue(t);
58
59         p.getContributingModule();
60         control.setReturnValue(m);
61
62         replayControls();
63
64         SetModuleRule rule = new SetModuleRule();
65
66         rule.setPropertyName("module");
67
68         rule.begin(p, null);
69
70         assertSame(m, t.getModule());
71
72         verifyControls();
73     }
74 }
75
Popular Tags