KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > xstream > core > util > ObjectIdDictionaryTest


1 package com.thoughtworks.xstream.core.util;
2
3 import junit.framework.TestCase;
4
5 public class ObjectIdDictionaryTest extends TestCase {
6
7     public void testMapsIdsToObjectReferences() {
8         ObjectIdDictionary dict = new ObjectIdDictionary();
9         Object JavaDoc a = new Object JavaDoc();
10         Object JavaDoc b = new Object JavaDoc();
11         Object JavaDoc c = new Object JavaDoc();
12         dict.associateId(a, "id a");
13         dict.associateId(b, "id b");
14         dict.associateId(c, "id c");
15         assertEquals("id a", dict.lookupId(a));
16         assertEquals("id b", dict.lookupId(b));
17         assertEquals("id c", dict.lookupId(c));
18     }
19
20     public void testTreatsObjectsThatAreEqualButNotSameInstanceAsDifferentReference() {
21         ObjectIdDictionary dict = new ObjectIdDictionary();
22         Integer JavaDoc a = new Integer JavaDoc(3);
23         Integer JavaDoc b = new Integer JavaDoc(3);
24         dict.associateId(a, "id a");
25         dict.associateId(b, "id b");
26         assertEquals("id a", dict.lookupId(a));
27         assertEquals("id b", dict.lookupId(b));
28     }
29 }
30
Popular Tags