01: /*
02: * Copyright (C) 2005 Joe Walnes.
03: * Copyright (C) 2006, 2007 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 16. February 2005 by Joe Walnes
11: */
12: package com.thoughtworks.xstream.converters.extended;
13:
14: import com.thoughtworks.acceptance.AbstractAcceptanceTest;
15:
16: public class JavaClassConverterTest extends AbstractAcceptanceTest {
17:
18: public void testHandlesPrimitivesAndWrappers() {
19: assertBothWays(int.class, "<java-class>int</java-class>");
20: assertBothWays(Integer.class,
21: "<java-class>java.lang.Integer</java-class>");
22:
23: assertBothWays(boolean.class,
24: "<java-class>boolean</java-class>");
25: assertBothWays(Boolean.class,
26: "<java-class>java.lang.Boolean</java-class>");
27:
28: assertBothWays(void.class, "<java-class>void</java-class>");
29: assertBothWays(Void.class,
30: "<java-class>java.lang.Void</java-class>");
31: }
32:
33: public static class A {
34: }
35:
36: public void testHandlesArrays() {
37: assertBothWays(
38: A[].class,
39: "<java-class>[Lcom.thoughtworks.xstream.converters.extended.JavaClassConverterTest$A;</java-class>");
40: assertBothWays(int[].class, "<java-class>[I</java-class>");
41: }
42:
43: public void testHandlesMultidimensioanlArrays() {
44: assertBothWays(
45: A[][].class,
46: "<java-class>[[Lcom.thoughtworks.xstream.converters.extended.JavaClassConverterTest$A;</java-class>");
47: assertBothWays(
48: A[][][][].class,
49: "<java-class>[[[[Lcom.thoughtworks.xstream.converters.extended.JavaClassConverterTest$A;</java-class>");
50:
51: assertBothWays(int[][].class, "<java-class>[[I</java-class>");
52: assertBothWays(int[][][][].class,
53: "<java-class>[[[[I</java-class>");
54: }
55:
56: public static class B {
57: }
58:
59: public void testResolvesUnloadedClassThatIsAnArray() {
60: // subtleties in classloaders make this an awkward one
61: String input = "<java-class>[Lcom.thoughtworks.xstream.converters.extended.JavaClassConverterTest$B;</java-class>";
62: Class result = (Class) xstream.fromXML(input);
63: assertEquals(
64: "[Lcom.thoughtworks.xstream.converters.extended.JavaClassConverterTest$B;",
65: result.getName());
66: assertTrue("Should be an array", result.isArray());
67: assertEquals(
68: "com.thoughtworks.xstream.converters.extended.JavaClassConverterTest$B",
69: result.getComponentType().getName());
70: }
71: }
|