1 package com.thoughtworks.xstream.converters.extended; 2 3 import java.lang.reflect.Method ; 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 .class, "<java-class>java.lang.Integer</java-class>"); 12 13 assertBothWays(boolean.class, "<java-class>boolean</java-class>"); 14 assertBothWays(Boolean .class, "<java-class>java.lang.Boolean</java-class>"); 15 16 assertBothWays(void.class, "<java-class>void</java-class>"); 17 assertBothWays(Void .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 String input = "<java-class>[Lcom.thoughtworks.xstream.converters.extended.JavaClassConverterTest$B;</java-class>"; 46 Class result = (Class ) 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 |