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.Constructor;
024:
025: import junit.framework.TestCase;
026:
027: /**
028: * tested class: java.lang.Class
029: * tested method: getConstructors
030: */
031: public class ClassTestGetConstructors extends TestCase {
032:
033: /**
034: * The java.lang.Class class has no public constructotrs.
035: */
036: public void test1() {
037: Constructor[] cs = Class.class.getConstructors();
038: assertNotNull("Unexpected null", cs);
039: assertEquals("array length:", 0, cs.length);
040: }
041:
042: /**
043: * The primitive types don't declare public constructors.
044: */
045: public void test2() {
046: Constructor[] cs = Integer.TYPE.getConstructors();
047: assertNotNull("Unexpected null", cs);
048: assertEquals("array length:", 0, cs.length);
049: }
050:
051: /**
052: * The arrays don't declare public constructors.
053: */
054: public void test3() {
055: Constructor[] cs = new int[0].getClass().getConstructors();
056: assertNotNull("Unexpected null", cs);
057: assertEquals("array length:", 0, cs.length);
058: }
059:
060: /**
061: * The java.lang.Integer class must have two public constructors. One takes
062: * integer parameter another takes parameter of the java.lang.String type.
063: */
064: public void test4() {
065: Constructor[] cs = Integer.class.getConstructors();
066: assertEquals("Assert 0: array length:", 2, cs.length);
067: Class[] args = cs[0].getParameterTypes();
068: assertEquals("Assert 1: array length:", 1, args.length);
069: if (Integer.TYPE == args[0]) {
070: args = cs[1].getParameterTypes();
071: assertEquals("Assert 2: array length:", 1, args.length);
072: assertSame("Assert 3: Objects differ:", String.class,
073: args[0]);
074: } else {
075: assertSame("Assert 4: Objects differ:", String.class,
076: args[0]);
077: args = cs[1].getParameterTypes();
078: assertEquals("Assert 5: array length:", 1, args.length);
079: assertSame("Assert 6: Objects differ:", Integer.TYPE,
080: args[0]);
081: }
082: }
083:
084: /**
085: * The getConstructors() method must not return public constructors of the
086: * super class. Default constructor which takes no parameters must be
087: * returned.
088: */
089: public void test5() {
090: Constructor[] cs = getClass().getConstructors();
091: assertNotNull("Unexpected null", cs);
092: assertEquals("Assert 0: array length:", 1, cs.length);
093: assertEquals("Assert 1: array length:", 0, cs[0]
094: .getParameterTypes().length);
095: }
096:
097: /**
098: * The getConstructors() method must not return public constructors of the
099: * super class. Default constructor which takes no parameters must be
100: * returned.
101: */
102: public void test6() {
103: Constructor[] cs = Inner.class.getConstructors();
104: assertNotNull("Unexpected null", cs);
105: assertEquals("Assert 0: array length:", 1, cs.length);
106: assertEquals("Assert 1: array length:", 0, cs[0]
107: .getParameterTypes().length);
108: }
109:
110: public static class Inner extends Throwable {
111: private static final long serialVersionUID = 0L;
112: }
113: }
|