KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > impl > TestMethodIterator


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 org.apache.hivemind.impl;
16
17 import java.io.IOException JavaDoc;
18 import java.util.NoSuchElementException JavaDoc;
19
20 import org.apache.hivemind.service.MethodIterator;
21 import org.apache.hivemind.service.MethodSignature;
22 import org.apache.hivemind.test.HiveMindTestCase;
23
24 /**
25  * Tests for {@link org.apache.hivemind.service.MethodIterator}.
26  *
27  * @author Howard Lewis Ship
28  * @since 1.0
29  */

30 public class TestMethodIterator extends HiveMindTestCase
31 {
32     static interface Play extends Runnable JavaDoc
33     {
34         public void jump();
35     }
36
37     static interface Runnable2
38     {
39         public void run();
40     }
41
42     static interface Runnable3 extends Runnable JavaDoc, Runnable2
43     {
44     }
45
46     static interface ToString
47     {
48         public String JavaDoc toString();
49     }
50
51     /** @since 1.1 */
52     static interface Openable
53     {
54         public void open();
55     }
56
57     /** @since 1.1 */
58     static interface OpenableWithError
59     {
60         public void open() throws IOException JavaDoc;
61     }
62
63     /** @since 1.1 */
64     static interface CombinedOpeneable extends Openable, OpenableWithError
65     {
66     }
67
68     public void testNormal()
69     {
70         MethodIterator mi = new MethodIterator(Runnable JavaDoc.class);
71
72         assertTrue(mi.hasNext());
73
74         MethodSignature actual = mi.next();
75
76         assertEquals(new MethodSignature(void.class, "run", null, null), actual);
77
78         assertFalse(mi.hasNext());
79
80         try
81         {
82             mi.next();
83         }
84         catch (NoSuchElementException JavaDoc ex)
85         {
86             //
87
}
88
89         assertEquals(false, mi.getToString());
90     }
91
92     public void testInherited()
93     {
94         MethodIterator mi = new MethodIterator(Play.class);
95
96         assertTrue(mi.hasNext());
97
98         // Problematic because the order in which they are returned is
99
// JDK specific and not defined!
100

101         MethodSignature actual = mi.next();
102
103         assertEquals(new MethodSignature(void.class, "jump", null, null), actual);
104
105         assertTrue(mi.hasNext());
106
107         actual = mi.next();
108
109         assertEquals(new MethodSignature(void.class, "run", null, null), actual);
110
111         assertFalse(mi.hasNext());
112
113         assertEquals(false, mi.getToString());
114     }
115
116     public void testFiltersFuplication()
117     {
118         MethodIterator mi = new MethodIterator(Runnable3.class);
119
120         MethodSignature actual = mi.next();
121
122         assertEquals(new MethodSignature(void.class, "run", null, null), actual);
123
124         assertEquals(false, mi.getToString());
125     }
126
127     public void testToString()
128     {
129         MethodIterator mi = new MethodIterator(ToString.class);
130
131         MethodSignature actual = mi.next();
132
133         assertEquals(new MethodSignature(String JavaDoc.class, "toString", null, null), actual);
134
135         assertEquals(true, mi.getToString());
136     }
137
138     /** @since 1.1 */
139     public void testFilterInheritedMethods()
140     {
141         MethodIterator mi = new MethodIterator(CombinedOpeneable.class);
142
143         MethodSignature actual = mi.next();
144
145         assertEquals(new MethodSignature(void.class, "open", null, new Class JavaDoc[]
146         { IOException JavaDoc.class }), actual);
147
148         assertEquals(false, mi.hasNext());
149     }
150 }
Popular Tags