KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgap > impl > PoolTest


1 /*
2  * This file is part of JGAP.
3  *
4  * JGAP offers a dual license model containing the LGPL as well as the MPL.
5  *
6  * For licencing information please see the file license.txt included with JGAP
7  * or have a look at the top of class org.jgap.Chromosome which representatively
8  * includes the JGAP license policy applicable for any file delivered with JGAP.
9  */

10 package org.jgap.impl;
11
12 import java.util.*;
13
14 import org.jgap.*;
15
16 import junit.framework.*;
17
18 /**
19  * Tests for Pool class
20  *
21  * @since 1.1
22  * @author Klaus Meffert
23  */

24 public class PoolTest
25     extends JGAPTestCase {
26   /** String containing the CVS revision. Read out via reflection!*/
27   private final static String JavaDoc CVS_REVISION = "$Revision: 1.7 $";
28
29   public static Test suite() {
30     TestSuite suite = new TestSuite(PoolTest.class);
31     return suite;
32   }
33
34   /**
35    * @author Klaus Meffert
36    */

37   public void testConstruct_0() {
38     new Pool();
39   }
40
41   /**
42    * @author Klaus Meffert
43    */

44   public void testClear_0() {
45     Pool pool = new Pool();
46     assertEquals(0, pool.size());
47     pool.clear();
48     assertEquals(0, pool.size());
49     pool.releaseObject(new Object JavaDoc());
50     assertEquals(1, pool.size());
51     pool.releaseObject(new Object JavaDoc());
52     assertEquals(2, pool.size());
53     pool.clear();
54     assertEquals(0, pool.size());
55   }
56
57   /**
58    * @author Klaus Meffert
59    */

60   public void testAcquirePooledObject_0() {
61     Pool pool = new Pool();
62     assertEquals(null, pool.acquirePooledObject());
63     Vector obj = new Vector();
64     pool.releaseObject(obj);
65     assertEquals(1, pool.size());
66     Object JavaDoc obj2 = pool.acquirePooledObject();
67     assertEquals(obj, obj2);
68     assertEquals(0, pool.size());
69   }
70
71   /**
72    * @author Klaus Meffert
73    */

74   public void testReleaseAllObjects_0() {
75     Pool pool = new Pool();
76     pool.releaseAllObjects(null);
77     assertEquals(0, pool.size());
78   }
79
80   /**
81    * @author Klaus Meffert
82    */

83   public void testReleaseAllObjects_1() {
84     Pool pool = new Pool();
85     Collection coll = new Vector();
86     coll.add(new HashMap());
87     coll.add(new Vector());
88     pool.releaseAllObjects(coll);
89     assertEquals(2, pool.size());
90     coll.add(new Object JavaDoc());
91     pool.releaseAllObjects(coll);
92     assertEquals(5, pool.size());
93   }
94
95   /**
96    * @author Klaus Meffert
97    */

98   public void testSize_0() {
99     Pool pool = new Pool();
100     assertEquals(0, pool.size());
101   }
102 }
103
Popular Tags