KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > service > impl > TestInterfaceSynthesizer


1 // Copyright 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 org.apache.hivemind.service.impl;
16
17 import org.apache.hivemind.service.ClassFactory;
18 import org.apache.hivemind.service.InterfaceFab;
19 import org.apache.hivemind.service.MethodSignature;
20 import org.apache.hivemind.test.HiveMindTestCase;
21 import org.apache.hivemind.test.TypeMatcher;
22 import org.easymock.MockControl;
23
24 /**
25  * @author Howard M. Lewis Ship
26  */

27 public class TestInterfaceSynthesizer extends HiveMindTestCase
28 {
29     private ClassFactory newClassFactory(InterfaceFab fab)
30     {
31         MockControl control = newControl(ClassFactory.class);
32         ClassFactory cf = (ClassFactory) control.getMock();
33
34         cf.newInterface("UNKNOWN");
35         control.setMatcher(new TypeMatcher());
36         control.setReturnValue(fab);
37
38         return cf;
39     }
40
41     public void testSimple()
42     {
43         MockControl control = newControl(InterfaceFab.class);
44         InterfaceFab fab = (InterfaceFab) control.getMock();
45
46         ClassFactory cf = newClassFactory(fab);
47
48         fab.addMethod(new MethodSignature(void.class, "doStuff", null, null));
49
50         fab.createInterface();
51         control.setReturnValue(null);
52
53         replayControls();
54
55         InterfaceSynthesizerImpl is = new InterfaceSynthesizerImpl();
56         is.setClassFactory(cf);
57
58         is.synthesizeInterface(SimpleBean.class);
59
60         verifyControls();
61     }
62
63     public void testExtendingInterface()
64     {
65         MockControl control = newControl(InterfaceFab.class);
66         InterfaceFab fab = (InterfaceFab) control.getMock();
67
68         ClassFactory cf = newClassFactory(fab);
69
70         fab.addInterface(BeanInterface.class);
71         fab.addMethod(new MethodSignature(String JavaDoc.class, "beanMethod", null, null));
72
73         fab.createInterface();
74         control.setReturnValue(null);
75
76         replayControls();
77
78         InterfaceSynthesizerImpl is = new InterfaceSynthesizerImpl();
79         is.setClassFactory(cf);
80
81         is.synthesizeInterface(ExtendingInterfaceBean.class);
82
83         verifyControls();
84     }
85
86     public void testExtendingSubInterface()
87     {
88         // We can't predict the order in which the methods will be invoked (it's based
89
// on things like hash values and order of objects inside a Set), so
90
// we use a nice control.
91

92         MockControl control = MockControl.createNiceControl(InterfaceFab.class);
93         addControl(control);
94
95         InterfaceFab fab = (InterfaceFab) control.getMock();
96
97         ClassFactory cf = newClassFactory(fab);
98
99         fab.addInterface(BeanInterface.class);
100         fab.addInterface(BeanSubInterface.class);
101         fab.addMethod(new MethodSignature(String JavaDoc.class, "beanMethod", null, null));
102
103         fab.createInterface();
104         control.setReturnValue(null);
105
106         replayControls();
107
108         InterfaceSynthesizerImpl is = new InterfaceSynthesizerImpl();
109         is.setClassFactory(cf);
110
111         is.synthesizeInterface(ExtendingSubInterfaceBean.class);
112
113         verifyControls();
114     }
115
116     public void testIgnoreStaticAndPrivateMethods()
117     {
118         MockControl control = newControl(InterfaceFab.class);
119         InterfaceFab fab = (InterfaceFab) control.getMock();
120
121         ClassFactory cf = newClassFactory(fab);
122
123         fab.addInterface(BeanInterface.class);
124         fab.addMethod(new MethodSignature(String JavaDoc.class, "beanMethod", null, null));
125
126         fab.createInterface();
127         control.setReturnValue(null);
128
129         replayControls();
130
131         InterfaceSynthesizerImpl is = new InterfaceSynthesizerImpl();
132         is.setClassFactory(cf);
133
134         is.synthesizeInterface(IgnoreStaticAndPrivateMethodsBean.class);
135
136         verifyControls();
137     }
138
139 }
Popular Tags