001: //$Id: ClassAnalyserTest.java 255 2006-10-23 21:51:34Z jg_hamburg $
002: /********************************************************************************
003: * DDTUnit, a Datadriven Approach to Unit- and Moduletesting
004: * Copyright (c) 2004, Joerg and Kai Gellien
005: * All rights reserved.
006: *
007: * The Software is provided under the terms of the Common Public License 1.0
008: * as provided with the distribution of DDTUnit in the file cpl-v10.html.
009: * Redistribution and use in source and binary forms, with or without
010: * modification, are permitted provided that the following conditions
011: * are met:
012: *
013: * + Redistributions of source code must retain the above copyright
014: * notice, this list of conditions and the following disclaimer.
015: *
016: * + Redistributions in binary form must reproduce the above
017: * copyright notice, this list of conditions and the following
018: * disclaimer in the documentation and/or other materials provided
019: * with the distribution.
020: *
021: * + Neither the name of the authors or DDTUnit, nor the
022: * names of its contributors may be used to endorse or promote
023: * products derived from this software without specific prior
024: * written permission.
025: *
026: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
027: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
028: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
029: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
030: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
031: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
032: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
033: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
034: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
035: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
036: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
037: ********************************************************************************/package junitx.ddtunit.util;
038:
039: import java.util.Arrays;
040: import java.util.Set;
041: import java.util.Vector;
042:
043: import junit.framework.TestCase;
044:
045: /**
046: * @author jg
047: */
048: public class ClassAnalyserTest extends TestCase {
049:
050: /**
051: * Constructor for ClassAnalyserTest.
052: *
053: * @param arg0
054: */
055: public ClassAnalyserTest(String arg0) {
056: super (arg0);
057: }
058:
059: public final void testGetSuperElements() {
060: Set super List = ClassAnalyser.getSuperElements(Object.class);
061: assertEquals("SuperElements of Object should be empty", 0,
062: super List.size());
063: super List = ClassAnalyser.getSuperElements(String.class);
064: assertEquals("SuperElements of String should be empty", 4,
065: super List.size());
066: super List = ClassAnalyser.getSuperElements(Vector.class);
067: int super Count = 8;
068: if (System.getProperty("os.name").startsWith("Windows")
069: && System.getProperty("java.version").startsWith("1.5")) {
070: super Count += 1;
071: }
072: assertEquals("SuperElements of Object should be empty",
073: super Count, super List.size());
074: }
075:
076: public void testFindInheritedMethod() {
077: Class[] args = new Class[0];
078: Object method = ClassAnalyser.findMethodByParams(
079: "junitx.ddtunit.resources.SimpleVOExtend",
080: "getIntegerValue", args);
081: assertNotNull("Method should not be null", method);
082: }
083:
084: public void testGetPrimitiveClazz() throws Exception {
085: Boolean[] booleanArray = { Boolean.TRUE, Boolean.FALSE };
086: boolean[] bArray = { true, false };
087: Byte[] byteArray = { Byte.valueOf((byte) '1'),
088: Byte.valueOf((byte) '2'), Byte.valueOf((byte) '3') };
089: byte[] byArray = { '1', '2', '3' };
090: Character[] charArray = { Character.valueOf('a'),
091: Character.valueOf('b'), Character.valueOf('c') };
092: char[] chArray = { 'a', 'b', 'c' };
093: Integer[] intArray = { Integer.valueOf(100),
094: Integer.valueOf(200), Integer.valueOf(300) };
095: int[] iArray = { 100, 200, 300 };
096: Long[] longArray = { Long.valueOf(1000L), Long.valueOf(2000),
097: Long.valueOf(3000) };
098: long[] lArray = { 1000L, 2000L, 3000L };
099: Short[] shortArray = { Short.valueOf((short) 1),
100: Short.valueOf((short) 2), Short.valueOf((short) 3) };
101: short[] sArray = { 1, 2, 3 };
102: Double[] doubleArray = { Double.valueOf(1.2),
103: Double.valueOf(2.3), Double.valueOf(3.4) };
104: double[] dArray = { 1.2, 2.3, 3.4 };
105: Float[] floatArray = { Float.valueOf(1.2F),
106: Float.valueOf(2.3F), Float.valueOf(3.4F) };
107: float[] fArray = { 1.2F, 2.3F, 3.4F };
108: assertTrue(Arrays.equals(bArray, (boolean[]) ClassAnalyser
109: .createPrimitiveArray(booleanArray)));
110: assertTrue(Arrays.equals(byArray, (byte[]) ClassAnalyser
111: .createPrimitiveArray(byteArray)));
112: assertTrue(Arrays.equals(chArray, (char[]) ClassAnalyser
113: .createPrimitiveArray(charArray)));
114: assertTrue(Arrays.equals(iArray, (int[]) ClassAnalyser
115: .createPrimitiveArray(intArray)));
116: assertTrue(Arrays.equals(sArray, (short[]) ClassAnalyser
117: .createPrimitiveArray(shortArray)));
118: assertTrue(Arrays.equals(lArray, (long[]) ClassAnalyser
119: .createPrimitiveArray(longArray)));
120: assertTrue(Arrays.equals(dArray, (double[]) ClassAnalyser
121: .createPrimitiveArray(doubleArray)));
122: assertTrue(Arrays.equals(fArray, (float[]) ClassAnalyser
123: .createPrimitiveArray(floatArray)));
124: }
125: }
|