View Javadoc

1   /*
2    * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3    * the spring framework, http://el4j.sf.net
4    * Copyright (C) 2005 by ELCA Informatique SA, Av. de la Harpe 22-24,
5    * 1000 Lausanne, Switzerland, http://www.elca.ch
6    *
7    * EL4J is published under the GNU Lesser General Public License (LGPL)
8    * Version 2.1. See http://www.gnu.org/licenses/
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * For alternative licensing, please contact info@elca.ch
16   */
17  
18  package ch.elca.el4j.tests.util.codingsupport;
19  
20  import static org.junit.Assert.assertEquals;
21  
22  import java.util.ArrayList;
23  
24  import org.junit.Test;
25  
26  import ch.elca.el4j.util.codingsupport.ClassUtils;
27  
28  /**
29   * This class tests the class utilities.
30   *
31   * @svnLink $Revision: 3873 $;$Date: 2009-08-04 13:59:45 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/core/src/test/java/ch/elca/el4j/tests/util/codingsupport/ClassUtilsTest.java $
32   *
33   * @author Andreas Bur (ABU)
34   */
35  public class ClassUtilsTest {
36  	
37  	/**
38  	 * Tests that a boolean array is properly converted into a string.
39  	 */
40  	@Test
41  	public void testBooleanArray() {
42  		assertEquals("boolean[]",
43  				ClassUtils.getCanonicalClassName((new boolean[2]).getClass()));
44  	}
45  	
46  	/**
47  	 * Tests that a byte array is properly converted into a string.
48  	 */
49  	@Test
50  	public void testByteArray() {
51  		assertEquals("byte[]",
52  				ClassUtils.getCanonicalClassName((new byte[2]).getClass()));
53  	}
54  	
55  	/**
56  	 * Tests that a char array is properly converted into a string.
57  	 */
58  	@Test
59  	public void testCharArray() {
60  		assertEquals("char[]",
61  				ClassUtils.getCanonicalClassName((new char[2]).getClass()));
62  	}
63  	
64  	/**
65  	 * Tests that a double array is properly converted into a string.
66  	 */
67  	@Test
68  	public void testDoubleArray() {
69  		assertEquals("double[]",
70  				ClassUtils.getCanonicalClassName((new double[2]).getClass()));
71  	}
72  	
73  	/**
74  	 * Tests that a float array is properly converted into a string.
75  	 */
76  	@Test
77  	public void testFloatArray() {
78  		assertEquals("float[]",
79  				ClassUtils.getCanonicalClassName((new float[2]).getClass()));
80  	}
81  	
82  	/**
83  	 * Tests that a int array is properly converted into a string.
84  	 */
85  	@Test
86  	public void testIntArray() {
87  		assertEquals("int[]",
88  				ClassUtils.getCanonicalClassName((new int[2]).getClass()));
89  	}
90  	
91  	/**
92  	 * Tests that a long array is properly converted into a string.
93  	 */
94  	@Test
95  	public void testLongArray() {
96  		assertEquals("long[]",
97  				ClassUtils.getCanonicalClassName((new long[2]).getClass()));
98  	}
99  	
100 	/**
101 	 * Tests that a short array is properly converted into a string.
102 	 */
103 	@Test
104 	public void testShortArray() {
105 		assertEquals("short[]",
106 				ClassUtils.getCanonicalClassName((new short[2]).getClass()));
107 	}
108 	
109 	/**
110 	 * Tests that a multi dimensional int array is properly converted into a
111 	 * string.
112 	 */
113 	@Test
114 	public void testIntMultiDimArray() {
115 		assertEquals("int[][][][]",
116 				ClassUtils.getCanonicalClassName(
117 						(new int[2][2][2][2]).getClass()));
118 	}
119 	
120 	/**
121 	 * Tests that an object array is properly converted into a string.
122 	 */
123 	@Test
124 	public void testObjArray() {
125 		assertEquals("java.lang.Object[]",
126 				ClassUtils.getCanonicalClassName((new Object[2]).getClass()));
127 	}
128 	
129 	/**
130 	 * Tests that an array of ArrayLists is properly converted into a string.
131 	 */
132 	@Test
133 	public void testArrayListArray() {
134 		assertEquals("java.util.ArrayList[]",
135 				ClassUtils.getCanonicalClassName(
136 						(new ArrayList[2]).getClass()));
137 	}
138 	
139 	/**
140 	 * Tests that a multi dimensional object array is properly converted into a
141 	 * string.
142 	 */
143 	@Test
144 	public void testMultyDimObjArray() {
145 		assertEquals("java.lang.Object[][][][][]",
146 				ClassUtils.getCanonicalClassName(
147 						(new Object[2][2][2][2][2]).getClass()));
148 	}
149 	
150 	/**
151 	 * Tests that an int is properly converted into a string.
152 	 */
153 	@Test
154 	public void testInt() {
155 		assertEquals("int", ClassUtils.getCanonicalClassName(int.class));
156 	}
157 	
158 	/**
159 	 * Tests that an object is properly converted into a string.
160 	 */
161 	@Test
162 	public void testObject() {
163 		assertEquals("java.lang.Object",
164 				ClassUtils.getCanonicalClassName(Object.class));
165 	}
166 }