1 15 package org.apache.tapestry.services.impl; 16 17 import java.util.ArrayList ; 18 import java.util.List ; 19 20 import org.apache.hivemind.test.HiveMindTestCase; 21 import org.apache.tapestry.services.ObjectPool; 22 23 29 public class TestObjectPool extends HiveMindTestCase 30 { 31 public void testStoreAndGet() 32 { 33 String key = "POOLED-KEY"; 34 String pooled = "POOLED"; 35 ObjectPool p = new ObjectPoolImpl(); 36 37 assertNull(p.get(key)); 38 39 p.store(key, pooled); 40 41 assertSame(pooled, p.get(key)); 42 43 assertNull(p.get(key)); 44 } 45 46 public void testStoreMany() 47 { 48 ObjectPool p = new ObjectPoolImpl(); 49 50 Object pooled1 = new Object (); 51 Object pooled2 = new Object (); 52 53 String key = "POOLED-KEY"; 54 55 p.store(key, pooled1); 56 p.store(key, pooled2); 57 58 60 List l = new ArrayList (); 61 l.add(pooled1); 62 l.add(pooled2); 63 64 for (int i = 0; i < 2; i++) 65 { 66 Object pooled = p.get(key); 67 68 assertTrue(l.remove(pooled)); 69 } 70 71 assertNull(p.get(key)); 72 } 73 } | Popular Tags |