001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Evgueni V. Brevnov, Roman S. Bushmanov
020: * @version $Revision$
021: */package java.lang;
022:
023: import java.lang.reflect.Method;
024:
025: import junit.framework.TestCase;
026:
027: /**
028: * tested class: java.lang.Class
029: * tested method: getMethods
030: */
031: @SuppressWarnings(value={"all"})
032: public class ClassTestGetMethods extends TestCase {
033:
034: /**
035: * Void.TYPE class does not declare methods.
036: */
037: public void test1() {
038: Method[] ms = Void.TYPE.getMethods();
039: assertNotNull("unexpected null", ms);
040: assertEquals("array length:", 0, ms.length);
041: }
042:
043: /**
044: * An array should inherit all public member methods of the Object class.
045: */
046: public void test2() {
047: Method[] ms = new int[0].getClass().getMethods();
048: assertNotNull("unexpected null", ms);
049: assertEquals("array length:", 9, ms.length);
050: }
051:
052: /**
053: * Only the public member methods should be returned.
054: */
055: public void test3() {
056: Method[] ms = A.class.getMethods();
057: assertNotNull("unexpected null", ms);
058: assertEquals("array length:", 10, ms.length);
059: }
060:
061: /**
062: * All member methods of the interface should be returned. Note that it does
063: * not include methods of the Object class.
064: */
065: public void test4() {
066: Method[] ms = I.class.getMethods();
067: assertNotNull("unexpected null", ms);
068: assertEquals("array length:", 1, ms.length);
069: }
070:
071: /**
072: * All member methods of the interface and its super interface should be
073: * returned. Note that it does not include methods of the Object class.
074: */
075: public void test5() {
076: Method[] ms = J.class.getMethods();
077: assertNotNull("unexpected null", ms);
078: assertEquals("array length:", 2, ms.length);
079: }
080:
081: /**
082: * Complex case. All public member methods of this class, its super classes
083: * and its super interfaces should be returned. Note that each member method
084: * appear only once in a resulting array.
085: */
086: public void test6() {
087: Method[] ms = B.class.getMethods();
088: assertNotNull("unexpected null", ms);
089: assertEquals("array length:", 11, ms.length);
090: }
091:
092: private static class A {
093:
094: public void m1() {
095: }
096:
097: private void m2() {
098: }
099: }
100:
101: interface I {
102:
103: public void m1();
104: }
105:
106: interface J extends I {
107:
108: void m2();
109: }
110:
111: private class B extends A implements I, J {
112:
113: public void m2() {
114: }
115:
116: private int m3() {
117: return 0;
118: }
119: }
120: }
|