KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > xstream > converters > extended > JavaClassConverterTest


1 package com.thoughtworks.xstream.converters.extended;
2
3 import java.lang.reflect.Method JavaDoc;
4
5 import com.thoughtworks.acceptance.AbstractAcceptanceTest;
6
7 public class JavaClassConverterTest extends AbstractAcceptanceTest {
8
9     public void testHandlesPrimitivesAndWrappers() {
10         assertBothWays(int.class, "<java-class>int</java-class>");
11         assertBothWays(Integer JavaDoc.class, "<java-class>java.lang.Integer</java-class>");
12
13         assertBothWays(boolean.class, "<java-class>boolean</java-class>");
14         assertBothWays(Boolean JavaDoc.class, "<java-class>java.lang.Boolean</java-class>");
15
16         assertBothWays(void.class, "<java-class>void</java-class>");
17         assertBothWays(Void JavaDoc.class, "<java-class>java.lang.Void</java-class>");
18     }
19
20     public static class A {}
21
22     public void testHandlesArrays() {
23         assertBothWays(A[].class,
24                 "<java-class>[Lcom.thoughtworks.xstream.converters.extended.JavaClassConverterTest$A;</java-class>");
25         assertBothWays(int[].class,
26                 "<java-class>[I</java-class>");
27     }
28
29     public void testHandlesMultidimensioanlArrays() {
30         assertBothWays(A[][].class,
31                 "<java-class>[[Lcom.thoughtworks.xstream.converters.extended.JavaClassConverterTest$A;</java-class>");
32         assertBothWays(A[][][][].class,
33                 "<java-class>[[[[Lcom.thoughtworks.xstream.converters.extended.JavaClassConverterTest$A;</java-class>");
34
35         assertBothWays(int[][].class,
36                 "<java-class>[[I</java-class>");
37         assertBothWays(int[][][][].class,
38                 "<java-class>[[[[I</java-class>");
39     }
40
41     public static class B {}
42
43     public void testResolvesUnloadedClassThatIsAnArray() {
44         // subtleties in classloaders make this an awkward one
45
String JavaDoc input = "<java-class>[Lcom.thoughtworks.xstream.converters.extended.JavaClassConverterTest$B;</java-class>";
46         Class JavaDoc result = (Class JavaDoc) xstream.fromXML(input);
47         assertEquals("[Lcom.thoughtworks.xstream.converters.extended.JavaClassConverterTest$B;", result.getName());
48         assertTrue("Should be an array", result.isArray());
49         assertEquals("com.thoughtworks.xstream.converters.extended.JavaClassConverterTest$B", result.getComponentType().getName());
50     }
51 }
52
Popular Tags