KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > impl > ObjectInstanceMonitorTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.objectserver.impl;
5
6 import com.tc.objectserver.api.ObjectInstanceMonitor;
7
8 import java.util.Collections JavaDoc;
9 import java.util.Map JavaDoc;
10
11 import junit.framework.TestCase;
12
13 public class ObjectInstanceMonitorTest extends TestCase {
14
15   public void test() {
16
17     ObjectInstanceMonitor monitor = new ObjectInstanceMonitorImpl();
18     assertEquals(Collections.EMPTY_MAP, monitor.getInstanceCounts());
19
20     monitor.instanceCreated("timmy");
21     monitor.instanceCreated("timmy");
22     monitor.instanceCreated("timmy");
23
24     Map JavaDoc counts;
25     counts = monitor.getInstanceCounts();
26     assertEquals(1, counts.size());
27     assertEquals(new Integer JavaDoc(3), counts.get("timmy"));
28
29     monitor.instanceCreated("timmy2");
30     counts = monitor.getInstanceCounts();
31     assertEquals(2, counts.size());
32     assertEquals(new Integer JavaDoc(3), counts.get("timmy"));
33     assertEquals(new Integer JavaDoc(1), counts.get("timmy2"));
34
35     monitor.instanceDestroyed("timmy2");
36     counts = monitor.getInstanceCounts();
37     assertEquals(1, counts.size());
38     assertEquals(new Integer JavaDoc(3), counts.get("timmy"));
39
40     monitor.instanceDestroyed("timmy");
41     counts = monitor.getInstanceCounts();
42     assertEquals(1, counts.size());
43     assertEquals(new Integer JavaDoc(2), counts.get("timmy"));
44
45     try {
46       monitor.instanceDestroyed("timmy2");
47       fail();
48     } catch (IllegalStateException JavaDoc ise) {
49       // expected
50
}
51
52     try {
53       monitor.instanceDestroyed("monitor has never seen this string before");
54       fail();
55     } catch (IllegalStateException JavaDoc ise) {
56       // expected
57
}
58
59     try {
60       monitor.instanceCreated(null);
61       fail();
62     } catch (IllegalArgumentException JavaDoc ise) {
63       // expected
64
}
65
66     try {
67       monitor.instanceDestroyed(null);
68       fail();
69     } catch (IllegalArgumentException JavaDoc ise) {
70       // expected
71
}
72
73   }
74
75 }
76
Popular Tags