01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /**
19: * @author Evgueni V. Brevnov, Roman S. Bushmanov
20: * @version $Revision$
21: */package java.lang;
22:
23: import java.lang.reflect.Method;
24:
25: import junit.framework.TestCase;
26:
27: /**
28: * tested class: java.lang.Class
29: * tested method: getDeclaredMethods
30: */
31: @SuppressWarnings(value={"all"})
32: public class ClassTestGetDeclaredMethods extends TestCase {
33:
34: /**
35: * Void.TYPE class does not declare methods.
36: */
37: public void test1() {
38: Method[] ms = Void.TYPE.getDeclaredMethods();
39: assertNotNull("null expected", ms);
40: assertEquals("array length:", 0, ms.length);
41: }
42:
43: /**
44: * Arrays do not declare methods.
45: */
46: public void test2() {
47: Method[] ms = new int[0].getClass().getDeclaredMethods();
48: assertNotNull("null expected", ms);
49: assertEquals("array length:", 0, ms.length);
50: }
51:
52: /**
53: * This test case checks several statements. The methods of the super class
54: * should not be included in resulting array as well as the <clinit>
55: * method. Only private method with "method1" name should be returned.
56: */
57: public void test3() {
58: Method[] ms = A.class.getDeclaredMethods();
59: assertNotNull("null expected", ms);
60: assertEquals("array length:", 1, ms.length);
61: assertEquals("incorrect name", "method1", ms[0].getName());
62: }
63:
64: /**
65: * Helper inner class.
66: */
67: private static class A {
68:
69: static int i;
70:
71: static {
72: i = 0;
73: }
74:
75: public A() {
76: i = 0;
77: }
78:
79: private void method1() {
80: }
81: }
82: }
|