import Sequenic.T2.* ; import org.junit.* ; import static org.junit.Assert.* ; public class TestXPool { static class Item {} static class Dream{} Item x1 = new Item() ; Item x2 = new Item() ; Dream y1 = new Dream() ; private XPool empty() { return new XPool() ; } private XPool singleton() { XPool p = new XPool() ; p.put(x1) ; return p ; } private XPool p3() { XPool p = new XPool() ; p.put(x1) ; p.put(x2) ; p.put(y1) ; return p ; } @Test public void get() { assertNotNull(singleton().get(0)) ; assertNotNull(p3().get(0)) ; } //@Test public void getBO() { assertNull(empty().get(0)) ; assertNull(p3().get(-1)) ; assertNull(p3().get(9)) ; } @Test public void put() { XPool p = empty() ; p.put(x1) ; assertNotNull(p.get(0)) ; p = singleton() ; p.put(x1) ; assertTrue(p.get_objectCount() == 2) ; p = p3() ; p.put(y1) ; p.put(new Dream()) ; p.put(new Object()) ; assertTrue(p.get_objectCount() == 6) ; } //@Test(expected = IllegalArgumentException.class) public void put_null_BO() { XPool p = singleton() ; p.put(null) ; } @Test public void get_objectCount() { assertTrue(empty().get_objectCount() == 0) ; assertTrue(singleton().get_objectCount() == 1) ; assertTrue(p3().get_objectCount() == 3) ; } //@Test public void resetBO() { XPool p = empty() ; p.reset() ; assertTrue(p.get_objectCount() == 0) ; p = singleton() ; p.reset() ; assertTrue(p.get_objectCount() == 0) ; p = p3() ; p.reset() ; assertTrue(p.get_objectCount() == 0) ; } @Test public void getIndex() { assertTrue(singleton().getIndex(Item.class) == 0) ; assertTrue(p3().getIndex(Item.class) == 0) ; assertTrue(p3().getIndex(Dream.class) == 2) ; Integer k = p3().getIndex(Object.class) ; assertTrue(0<=k && k<3) ; } //@Test public void getIndexBO() { assertNull(empty().getIndex(Item.class)) ; assertNull(p3().getIndex(Class.class)) ; } //@Test(expected = IllegalArgumentException.class) public void getIndex_null_BO() { p3().getIndex(null) ; } }