001: /***
002: * Retrotranslator: a Java bytecode transformer that translates Java classes
003: * compiled with JDK 5.0 into classes that can be run on JVM 1.4.
004: *
005: * Copyright (c) 2005 - 2008 Taras Puchko
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: * 3. Neither the name of the copyright holders nor the names of its
017: * contributors may be used to endorse or promote products derived from
018: * this software without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
021: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
022: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
023: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
024: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
025: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
026: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
027: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
028: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
029: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
030: * THE POSSIBILITY OF SUCH DAMAGE.
031: */package net.sf.retrotranslator.transformer;
032:
033: import junit.framework.TestCase;
034:
035: public class ClassLiteralVisitorTestCase extends TestCase {
036:
037: public static Class CONST = Float.class;
038:
039: public static interface InterfaceInClass {
040: public Class CONST = Integer.class;
041: }
042:
043: public static interface DerivedInterface extends MyConstants {
044: }
045:
046: public static class StaticClassInClass {
047: public static Class CONST = Float.class;
048: }
049:
050: public class ClassInClass {
051: public Class getConst() {
052: return Float.class;
053: }
054: }
055:
056: public static class MyConstantsImpl implements MyConstants {
057: }
058:
059: public class DerivedTestClass extends ClassLiteralVisitorTestCase {
060: }
061:
062: public class DerivedClass extends StaticClassInClass {
063: }
064:
065: public static Class getConst() {
066: return Float.class;
067: }
068:
069: public void testClasses() {
070: assertEquals(ClassLiteralVisitorTestCase.class,
071: ClassLiteralVisitorTestCase[].class.getComponentType());
072: assertEquals(InterfaceInClass.class, InterfaceInClass[].class
073: .getComponentType());
074: assertEquals(StaticClassInClass.class,
075: StaticClassInClass[].class.getComponentType());
076: assertEquals(ClassInClass.class, ClassInClass[].class
077: .getComponentType());
078: assertEquals(MyConstantsImpl.class, MyConstantsImpl[].class
079: .getComponentType());
080: }
081:
082: public void testConstField() {
083: assertNotNull(CONST);
084: assertNotNull(InterfaceInClass.CONST);
085: assertNotNull(StaticClassInClass.CONST);
086: assertNotNull(DerivedClass.CONST);
087: assertSame(DerivedInterface.CONST[1], Integer.class);
088: assertSame(MyConstantsImpl.CONST[1], Integer.class);
089: assertSame(MyConstants.CONST[2], String.class);
090: assertNotNull(MyConstants.InterfaceInInterface.CONST);
091: assertNotNull(MyConstants.ClassInInterface.CONST);
092: }
093:
094: public void testConstMethod() {
095: assertNotNull(ClassLiteralVisitorTestCase.getConst());
096: assertNotNull(DerivedTestClass.getConst());
097: assertNotNull(new ClassInClass().getConst());
098: }
099:
100: public void testArrays() {
101: assertEquals(Integer.class, Integer[].class.getComponentType());
102: assertEquals(Integer[].class, Integer[][].class
103: .getComponentType());
104: assertEquals(Integer[][].class, Integer[][][].class
105: .getComponentType());
106: assertEquals(boolean.class, boolean[].class.getComponentType());
107: assertEquals(boolean[].class, boolean[][].class
108: .getComponentType());
109: assertEquals(boolean[][].class, boolean[][][].class
110: .getComponentType());
111:
112: assertEquals(char[].class, char[][].class.getComponentType());
113: assertEquals(float[].class, float[][].class.getComponentType());
114: assertEquals(double[].class, double[][].class
115: .getComponentType());
116: assertEquals(byte[].class, byte[][].class.getComponentType());
117: assertEquals(short[].class, short[][].class.getComponentType());
118: assertEquals(int[].class, int[][].class.getComponentType());
119: assertEquals(long[].class, long[][].class.getComponentType());
120: }
121: }
|