KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > lib > pipeline > TestFilterMethodAnalyzer


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.lib.pipeline;
16
17 import java.lang.reflect.Method JavaDoc;
18
19 import org.apache.hivemind.service.MethodSignature;
20 import org.apache.hivemind.test.HiveMindTestCase;
21
22 public class TestFilterMethodAnalyzer extends HiveMindTestCase
23 {
24     private MethodSignature find(Class JavaDoc target, String JavaDoc name)
25     {
26         Method JavaDoc[] methods = target.getMethods();
27
28         for (int i = 0; i < methods.length; i++)
29         {
30             if (methods[i].getName().equals(name))
31                 return new MethodSignature(methods[i]);
32         }
33
34         unreachable();
35         return null;
36     }
37
38     private void assertPosition(String JavaDoc methodName, int expected)
39     {
40         FilterMethodAnalyzer a = new FilterMethodAnalyzer(SampleService.class);
41
42         MethodSignature ms = find(SampleService.class, methodName);
43         MethodSignature fms = find(SampleFilter.class, methodName);
44
45         assertEquals(expected, a.findServiceInterfacePosition(ms, fms));
46     }
47
48     private void assertMismatch(String JavaDoc methodName)
49     {
50         assertPosition(methodName, -1);
51     }
52
53     public void testSimpleMatch()
54     {
55         assertPosition("simpleMatch", 0);
56     }
57
58     public void testMismatchParameterCount()
59     {
60         assertMismatch("mismatchParameterCount");
61     }
62
63     public void testMismatchReturnType()
64     {
65         assertMismatch("mismatchReturnType");
66     }
67
68     public void testMissingServiceInterface()
69     {
70         assertMismatch("missingServiceInterface");
71     }
72
73     public void testComplexMatch()
74     {
75         assertPosition("complexMatch", 2);
76     }
77 }
78
Popular Tags