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 23. January 2005 by Joe Walnes
11: */
12: package com.thoughtworks.xstream.mapper;
13:
14: import com.thoughtworks.xstream.core.util.CompositeClassLoader;
15:
16: import junit.framework.TestCase;
17:
18: public class DefaultClassMapperTest extends TestCase {
19: private Mapper mapper;
20:
21: protected void setUp() throws Exception {
22: super .setUp();
23: mapper = new ArrayMapper(new DefaultMapper(
24: new CompositeClassLoader()));
25: }
26:
27: public void testAppendsArraySuffixOnArrays() {
28: Class arrayCls = new String[0].getClass();
29: assertEquals("java.lang.String-array", mapper
30: .serializedClass(arrayCls));
31: }
32:
33: public void testAppendsMultipleArraySuffixesOnMultidimensionalArrays() {
34: Class arrayCls = new String[0][0][0].getClass();
35: assertEquals("java.lang.String-array-array-array", mapper
36: .serializedClass(arrayCls));
37: }
38:
39: public void testCreatesInstancesOfArrays() {
40: Class arrayType = mapper.realClass("java.lang.String-array");
41: assertTrue(arrayType.isArray());
42: assertEquals(String.class, arrayType.getComponentType());
43: }
44:
45: public void testSupportsAllPrimitiveArrayTypes() {
46: assertEquals(int.class, mapper.realClass("int-array")
47: .getComponentType());
48: assertEquals(short.class, mapper.realClass("short-array")
49: .getComponentType());
50: assertEquals(long.class, mapper.realClass("long-array")
51: .getComponentType());
52: assertEquals(char.class, mapper.realClass("char-array")
53: .getComponentType());
54: assertEquals(boolean.class, mapper.realClass("boolean-array")
55: .getComponentType());
56: assertEquals(float.class, mapper.realClass("float-array")
57: .getComponentType());
58: assertEquals(double.class, mapper.realClass("double-array")
59: .getComponentType());
60: assertEquals(byte.class, mapper.realClass("byte-array")
61: .getComponentType());
62: }
63:
64: public void testCreatesInstancesOfMultidimensionalArrays() {
65: Class arrayType = mapper
66: .realClass("java.lang.String-array-array-array");
67: assertTrue(arrayType.isArray());
68: assertTrue(arrayType.getComponentType().isArray());
69: assertTrue(arrayType.getComponentType().getComponentType()
70: .isArray());
71:
72: assertFalse(arrayType.getComponentType().getComponentType()
73: .getComponentType().isArray());
74: assertEquals(String.class, arrayType.getComponentType()
75: .getComponentType().getComponentType());
76:
77: Class primitiveArrayType = mapper
78: .realClass("int-array-array-array");
79: assertTrue(primitiveArrayType.isArray());
80: assertTrue(primitiveArrayType.getComponentType().isArray());
81: assertTrue(primitiveArrayType.getComponentType()
82: .getComponentType().isArray());
83:
84: assertFalse(primitiveArrayType.getComponentType()
85: .getComponentType().getComponentType().isArray());
86: assertEquals(int.class, primitiveArrayType.getComponentType()
87: .getComponentType().getComponentType());
88: }
89: }
|