KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > xstream > core > DefaultClassMapperTest


1 package com.thoughtworks.xstream.core;
2
3 import junit.framework.TestCase;
4 import com.thoughtworks.acceptance.objects.SampleDynamicProxy;
5
6 public class DefaultClassMapperTest extends TestCase {
7     private DefaultClassMapper mapper;
8
9     protected void setUp() throws Exception JavaDoc {
10         super.setUp();
11         mapper = new DefaultClassMapper();
12     }
13
14     public void testAppendsArraySuffixOnArrays() {
15         Class JavaDoc arrayCls = new String JavaDoc[0].getClass();
16         assertEquals("java.lang.String-array", mapper.lookupName(arrayCls));
17
18         mapper.alias("str", String JavaDoc.class, String JavaDoc.class);
19         assertEquals("str-array", mapper.lookupName(arrayCls));
20
21         mapper.alias("int", int.class, int.class);
22         assertEquals("int-array", mapper.lookupName(new int[0].getClass()));
23     }
24
25     public void testPrefixesIllegalXmlElementNamesWithValue() {
26         Class JavaDoc proxyCls = SampleDynamicProxy.newInstance().getClass();
27         String JavaDoc aliasedName = mapper.lookupName(proxyCls);
28         assertTrue("Does not start with 'default-Proxy' : <" + aliasedName + ">",
29                 aliasedName.startsWith("default-Proxy"));
30         assertEquals(proxyCls, mapper.lookupType(aliasedName));
31     }
32
33     public void testArrayClassesCanBeCreated() {
34         Class JavaDoc arrayType = mapper.lookupType("java.lang.String-array");
35         assertTrue(arrayType.isArray());
36         assertEquals(String JavaDoc.class, arrayType.getComponentType());
37
38         mapper.alias("str", String JavaDoc.class, String JavaDoc.class);
39         arrayType = mapper.lookupType("str-array");
40         assertTrue(arrayType.isArray());
41         assertEquals(String JavaDoc.class, arrayType.getComponentType());
42
43         mapper.alias("int", int.class, int.class);
44         arrayType = mapper.lookupType("int-array");
45         assertTrue(arrayType.isArray());
46         assertEquals(int.class, arrayType.getComponentType());
47     }
48 }
49
Popular Tags