KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > impl > TestJavaTypeUtils


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.hivemind.impl;
16
17 import junit.framework.TestCase;
18
19 /**
20  * Tests for {@link org.apache.hivemind.impl.JavaTypeUtils}.
21  *
22  * @author Howard M. Lewis Ship
23  * @since 1.1
24  */

25 public class TestJavaTypeUtils extends TestCase
26 {
27     private void test(String JavaDoc expected, String JavaDoc input)
28     {
29         String JavaDoc actual = JavaTypeUtils.getJVMClassName(input);
30
31         assertEquals(expected, actual);
32     }
33
34     public void testNonArrayUnchanged()
35     {
36         test("java.lang.Object", "java.lang.Object");
37         test("int", "int");
38     }
39
40     public void testPrimitiveArray()
41     {
42         test("[I", "int[]");
43     }
44
45     public void testObjectArray()
46     {
47         test("[Ljava.lang.Throwable;", "java.lang.Throwable[]");
48     }
49
50     public void testPrimitiveMultiArray()
51     {
52         test("[[B", "byte[][]");
53     }
54
55     // TODO: Test that all the primitives are correct
56

57     public void testObjectMultiArray()
58     {
59         test("[[Ljava.lang.Runnable;", "java.lang.Runnable[][]");
60     }
61
62     public void testGetPrimitive()
63     {
64         assertSame(boolean.class, JavaTypeUtils.getPrimtiveClass("boolean"));
65         assertSame(char.class, JavaTypeUtils.getPrimtiveClass("char"));
66
67         assertNull(JavaTypeUtils.getPrimtiveClass("java.lang.Object"));
68     }
69 }
Popular Tags