KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > methodmatch > AbstractMethodTestCase


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.methodmatch;
16
17 import java.lang.reflect.Method JavaDoc;
18
19 import junit.framework.AssertionFailedError;
20
21 import org.apache.hivemind.service.MethodSignature;
22 import org.apache.hivemind.test.HiveMindTestCase;
23
24 /**
25  * Base class for a number of tests related to {@link org.apache.hivemind.methodmatch.MethodMatcher}.
26  *
27  * @author Howard Lewis Ship
28  */

29 public abstract class AbstractMethodTestCase extends HiveMindTestCase
30 {
31     protected MethodSignature getMethodSignature(Class JavaDoc target, String JavaDoc name)
32     {
33         Method JavaDoc[] methods = target.getMethods();
34
35         for (int i = 0; i < methods.length; i++)
36         {
37             if (methods[i].getName().equals(name))
38                 return new MethodSignature(methods[i]);
39         }
40
41         throw new AssertionFailedError(
42             "Class " + target.getName() + " does not contain a method named: '" + name + "'.");
43     }
44
45     protected MethodSignature getMethodSignature(Object JavaDoc object, String JavaDoc name)
46     {
47         return getMethodSignature(object.getClass(), name);
48     }
49
50 }
51
Popular Tags