001: package org.drools.util;
002:
003: import java.util.ArrayList;
004: import java.util.Arrays;
005: import java.util.Collections;
006: import java.util.HashSet;
007: import java.util.List;
008: import java.util.Map;
009: import java.util.Set;
010: import java.util.TreeMap;
011:
012: import junit.framework.TestCase;
013:
014: public class ShadowProxyUtilsTest extends TestCase {
015:
016: protected void setUp() throws Exception {
017: super .setUp();
018: }
019:
020: protected void tearDown() throws Exception {
021: super .tearDown();
022: }
023:
024: public void testCloneList() {
025: List list = new ArrayList();
026: list.add("a");
027: list.add("b");
028:
029: List clone = (List) ShadowProxyUtils.cloneObject(list);
030: assertEquals(list, clone);
031: assertNotSame(list, clone);
032: }
033:
034: public void testCloneMap() {
035: Map map = new TreeMap();
036: map.put("a", "a");
037: map.put("b", "b");
038:
039: Map clone = (Map) ShadowProxyUtils.cloneObject(map);
040: assertEquals(map, clone);
041: assertNotSame(map, clone);
042: }
043:
044: public void testCloneArray() {
045: int[][] array = new int[][] { { 0, 0 }, { 0, 1 }, { 1, 0 },
046: { 1, 1 } };
047:
048: int[][] clone = (int[][]) ShadowProxyUtils.cloneObject(array);
049: assertTrue(ArrayUtils.deepEquals(array, clone));
050: assertNotSame(array, clone);
051: }
052:
053: public void testCloneUnmodifiableSet() {
054: Set set = new HashSet();
055: set.add("a");
056: set.add("b");
057:
058: Set unmod = Collections.unmodifiableSet(set);
059:
060: Set clone = (Set) ShadowProxyUtils.cloneObject(unmod);
061: assertEquals(unmod, clone);
062: assertSame(unmod, clone);
063: }
064:
065: public void testCloneUnmodifiableMap() {
066: Map map = new TreeMap();
067: map.put("a", "a");
068: map.put("b", "b");
069: Map unmod = Collections.unmodifiableMap(map);
070:
071: Map clone = (Map) ShadowProxyUtils.cloneObject(unmod);
072: assertEquals(unmod, clone);
073: assertSame(unmod, clone);
074: }
075:
076: public void testCloneEmptyList() {
077: List list = Collections.EMPTY_LIST;
078:
079: List clone = (List) ShadowProxyUtils.cloneObject(list);
080: assertEquals(list, clone);
081: assertSame(list, clone);
082: }
083:
084: public void testCloneEmptySet() {
085: Set set = Collections.EMPTY_SET;
086:
087: Set clone = (Set) ShadowProxyUtils.cloneObject(set);
088: assertEquals(set, clone);
089: assertSame(set, clone);
090: }
091:
092: public void testCloneEmptyMap() {
093: Map map = Collections.EMPTY_MAP;
094:
095: Map clone = (Map) ShadowProxyUtils.cloneObject(map);
096: assertEquals(map, clone);
097: assertSame(map, clone);
098: }
099:
100: public void testCloneRegularObject() {
101: // this is never supposed to happen,
102: // but we don't want the method to blow up if it happens
103: Object obj = new Object();
104:
105: Object clone = (Object) ShadowProxyUtils.cloneObject(obj);
106: assertEquals(obj, clone);
107: assertSame(obj, clone);
108:
109: }
110:
111: }
|