1 4 package com.tc.objectserver.impl; 5 6 import com.tc.objectserver.api.ObjectInstanceMonitor; 7 8 import java.util.Collections ; 9 import java.util.Map ; 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 counts; 25 counts = monitor.getInstanceCounts(); 26 assertEquals(1, counts.size()); 27 assertEquals(new Integer (3), counts.get("timmy")); 28 29 monitor.instanceCreated("timmy2"); 30 counts = monitor.getInstanceCounts(); 31 assertEquals(2, counts.size()); 32 assertEquals(new Integer (3), counts.get("timmy")); 33 assertEquals(new Integer (1), counts.get("timmy2")); 34 35 monitor.instanceDestroyed("timmy2"); 36 counts = monitor.getInstanceCounts(); 37 assertEquals(1, counts.size()); 38 assertEquals(new Integer (3), counts.get("timmy")); 39 40 monitor.instanceDestroyed("timmy"); 41 counts = monitor.getInstanceCounts(); 42 assertEquals(1, counts.size()); 43 assertEquals(new Integer (2), counts.get("timmy")); 44 45 try { 46 monitor.instanceDestroyed("timmy2"); 47 fail(); 48 } catch (IllegalStateException ise) { 49 } 51 52 try { 53 monitor.instanceDestroyed("monitor has never seen this string before"); 54 fail(); 55 } catch (IllegalStateException ise) { 56 } 58 59 try { 60 monitor.instanceCreated(null); 61 fail(); 62 } catch (IllegalArgumentException ise) { 63 } 65 66 try { 67 monitor.instanceDestroyed(null); 68 fail(); 69 } catch (IllegalArgumentException ise) { 70 } 72 73 } 74 75 } 76 | Popular Tags |