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.Modifier;
024:
025: import junit.framework.TestCase;
026:
027: /**
028: * tested class: java.lang.Class
029: * tested method: getModifiers
030: */
031: public class ClassTestGetModifiers extends TestCase {
032:
033: /**
034: * If the class represents a primitive type, then its public and final
035: * modifiers should be on as well as its protected, private and interface
036: * modifiers should be off.
037: */
038: public void test1() {
039: int mod = Byte.TYPE.getModifiers();
040: assertTrue("public:", Modifier.isPublic(mod));
041: assertTrue("final:", Modifier.isFinal(mod));
042: assertFalse("protected", Modifier.isProtected(mod));
043: assertFalse("private", Modifier.isPrivate(mod));
044: assertFalse("interface", Modifier.isInterface(mod));
045: }
046:
047: /**
048: * If the class represents an array, then its final modifier should be on
049: * and its interface modifier should be off. Whether an array class has
050: * public, protected, package private or private modifier determines by the
051: * modifier of its component type.
052: */
053: public void test2() {
054: int mod = new int[0].getClass().getModifiers();
055: assertTrue("public:", Modifier.isPublic(mod));
056: assertTrue("final:", Modifier.isFinal(mod));
057: assertFalse("interface", Modifier.isInterface(mod));
058: }
059:
060: /**
061: * If the class represents an array, then its final modifier should be on
062: * and its interface modifier should be off. Whether an array class has
063: * public, protected, package private or private modifier determines by the
064: * modifier of its component type.
065: */
066: public void test3() {
067: int mod = new I[0].getClass().getModifiers();
068: assertTrue("private", Modifier.isPrivate(mod));
069: assertTrue("final", Modifier.isFinal(mod));
070: assertFalse("interface", Modifier.isInterface(mod));
071: }
072:
073: /**
074: * An interface should always has abstract and interface modifiers on.
075: */
076: public void test4() {
077: int mod = I.class.getModifiers();
078: assertTrue("private", Modifier.isPrivate(mod));
079: assertTrue("interface", Modifier.isInterface(mod));
080: assertTrue("abstract", Modifier.isAbstract(mod));
081: }
082:
083: /**
084: * Checks whether a Boolean class is public and final.
085: */
086: public void test5() {
087: int mod = Boolean.class.getModifiers();
088: assertEquals("should be public final", Modifier.PUBLIC
089: | Modifier.FINAL, mod);
090: }
091:
092: /**
093: * Checks whether a ClassLoader class is public and abstract.
094: */
095: public void test6() {
096: int mod = ClassLoader.class.getModifiers();
097: assertEquals("should be public abstract", Modifier.PUBLIC
098: | Modifier.ABSTRACT, mod);
099: }
100:
101: private interface I {
102: }
103: }
|