KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.io.Serializable JavaDoc;
18
19 import org.apache.hivemind.ApplicationRuntimeException;
20 import org.apache.hivemind.service.ClassFactory;
21 import org.apache.hivemind.service.InterfaceFab;
22 import org.apache.hivemind.service.MethodIterator;
23 import org.apache.hivemind.service.MethodSignature;
24 import org.apache.hivemind.test.HiveMindTestCase;
25
26 /**
27  * Tests for {@link org.apache.hivemind.service.impl.InterfaceFabImpl}.
28  *
29  * @author Howard M. Lewis Ship
30  * @since 1.1
31  */

32 public class TestInterfaceFab extends HiveMindTestCase
33 {
34     private InterfaceFab newInterface(String JavaDoc name)
35     {
36         ClassFactory cf = new ClassFactoryImpl();
37
38         return cf.newInterface(name);
39     }
40
41     public void testCreateEmptyInterface()
42     {
43         InterfaceFab fab = newInterface("MyNewInterface");
44
45         Class JavaDoc ic = fab.createInterface();
46
47         assertEquals("MyNewInterface", ic.getName());
48
49         assertEquals(0, ic.getMethods().length);
50
51         assertEquals("InterfaceFabImpl[\npublic interface MyNewInterface\n]", fab.toString());
52     }
53
54     public void testAddMethod()
55     {
56         InterfaceFab fab = newInterface("InterfaceWithMethods");
57
58         MethodSignature sig = new MethodSignature(void.class, "doStuff", null, null);
59
60         fab.addMethod(sig);
61
62         Class JavaDoc ic = fab.createInterface();
63
64         MethodIterator mi = new MethodIterator(ic);
65
66         MethodSignature sig2 = mi.next();
67
68         assertEquals(sig, sig2);
69
70         assertFalse(mi.hasNext());
71
72         assertEquals(
73                 "InterfaceFabImpl[\npublic interface InterfaceWithMethods\n\npublic void doStuff();\n]",
74                 fab.toString());
75     }
76
77     public void testAddInterface()
78     {
79         InterfaceFab fab = newInterface("ExtendInterface");
80
81         fab.addInterface(Runnable JavaDoc.class);
82         fab.addInterface(Serializable JavaDoc.class);
83
84         Class JavaDoc ic = fab.createInterface();
85
86         MethodIterator mi = new MethodIterator(ic);
87
88         MethodSignature sig = mi.next();
89
90         assertEquals(new MethodSignature(void.class, "run", null, null), sig);
91
92         assertFalse(mi.hasNext());
93
94         assertEquals(
95                 "InterfaceFabImpl[\npublic interface ExtendInterface extends java.lang.Runnable, java.io.Serializable\n]",
96                 fab.toString());
97     }
98
99     public void testDuplicateInterface()
100     {
101         ClassFactory cf = new ClassFactoryImpl();
102
103         cf.newInterface("DuplicateInterface").createInterface();
104
105         try
106         {
107             cf.newInterface("DuplicateInterface");
108             unreachable();
109         }
110         catch (ApplicationRuntimeException ex)
111         {
112             assertExceptionSubstring(ex, "Unable to create interface DuplicateInterface");
113         }
114     }
115
116 }
117
118
Popular Tags