Author: simonetripodi
Date: Sun Apr 24 20:13:44 2011
New Revision: 1096375

URL: http://svn.apache.org/viewvc?rev=1096375&view=rev
Log:
added generics to TestSoftRef* test classes

Modified:
    
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestSoftRefOutOfMemory.java
    
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestSoftReferenceObjectPool.java

Modified: 
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestSoftRefOutOfMemory.java
URL: 
http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestSoftRefOutOfMemory.java?rev=1096375&r1=1096374&r2=1096375&view=diff
==============================================================================
--- 
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestSoftRefOutOfMemory.java
 (original)
+++ 
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestSoftRefOutOfMemory.java
 Sun Apr 24 20:13:44 2011
@@ -33,12 +33,13 @@ import org.apache.commons.pool2.impl.Sof
  * @version $Revision$ $Date$
  */
 public class TestSoftRefOutOfMemory extends TestCase {
-    private SoftReferenceObjectPool pool;
+    private SoftReferenceObjectPool<String> pool;
 
     public TestSoftRefOutOfMemory(String testName) {
         super(testName);
     }
 
+    @Override
     public void tearDown() throws Exception {
         if (pool != null) {
             pool.close();
@@ -48,16 +49,16 @@ public class TestSoftRefOutOfMemory exte
     }
 
     public void testOutOfMemory() throws Exception {
-        pool = new SoftReferenceObjectPool(new SmallPoolableObjectFactory());
+        pool = new SoftReferenceObjectPool<String>(new 
SmallPoolableObjectFactory());
 
-        Object obj = pool.borrowObject();
+        String obj = pool.borrowObject();
         assertEquals("1", obj);
         pool.returnObject(obj);
         obj = null;
 
         assertEquals(1, pool.getNumIdle());
 
-        final List garbage = new LinkedList();
+        final List<byte[]> garbage = new LinkedList<byte[]>();
         final Runtime runtime = Runtime.getRuntime();
         while (pool.getNumIdle() > 0) {
             try {
@@ -83,20 +84,20 @@ public class TestSoftRefOutOfMemory exte
     }
 
     public void testOutOfMemory1000() throws Exception {
-        pool = new SoftReferenceObjectPool(new SmallPoolableObjectFactory());
+        pool = new SoftReferenceObjectPool<String>(new 
SmallPoolableObjectFactory());
 
         for (int i = 0 ; i < 1000 ; i++) {
             pool.addObject();
         }
 
-        Object obj = pool.borrowObject();
+        String obj = pool.borrowObject();
         assertEquals("1000", obj);
         pool.returnObject(obj);
         obj = null;
 
         assertEquals(1000, pool.getNumIdle());
 
-        final List garbage = new LinkedList();
+        final List<byte[]> garbage = new LinkedList<byte[]>();
         final Runtime runtime = Runtime.getRuntime();
         while (pool.getNumIdle() > 0) {
             try {
@@ -122,16 +123,16 @@ public class TestSoftRefOutOfMemory exte
     }
 
     public void testOutOfMemoryLarge() throws Exception {
-        pool = new SoftReferenceObjectPool(new 
LargePoolableObjectFactory(1000000));
+        pool = new SoftReferenceObjectPool<String>(new 
LargePoolableObjectFactory(1000000));
 
-        Object obj = pool.borrowObject();
-        assertTrue(((String)obj).startsWith("1."));
+        String obj = pool.borrowObject();
+        assertTrue(obj.startsWith("1."));
         pool.returnObject(obj);
         obj = null;
 
         assertEquals(1, pool.getNumIdle());
 
-        final List garbage = new LinkedList();
+        final List<byte[]> garbage = new LinkedList<byte[]>();
         final Runtime runtime = Runtime.getRuntime();
         while (pool.getNumIdle() > 0) {
             try {
@@ -149,7 +150,7 @@ public class TestSoftRefOutOfMemory exte
         System.gc();
 
         obj = pool.borrowObject();
-        assertTrue(((String)obj).startsWith("2."));
+        assertTrue(obj.startsWith("2."));
         pool.returnObject(obj);
         obj = null;
 
@@ -160,8 +161,9 @@ public class TestSoftRefOutOfMemory exte
      * Makes sure an {@link OutOfMemoryError} isn't swallowed.
      */
     public void testOutOfMemoryError() throws Exception {
-        pool = new SoftReferenceObjectPool(new BasePoolableObjectFactory() {
-            public Object makeObject() throws Exception {
+        pool = new SoftReferenceObjectPool<String>(new 
BasePoolableObjectFactory<String>() {
+            @Override
+            public String makeObject() throws Exception {
                 throw new OutOfMemoryError();
             }
         });
@@ -175,12 +177,14 @@ public class TestSoftRefOutOfMemory exte
         }
         pool.close();
 
-        pool = new SoftReferenceObjectPool(new BasePoolableObjectFactory() {
-            public Object makeObject() throws Exception {
-                return new Object();
+        pool = new SoftReferenceObjectPool<String>(new 
BasePoolableObjectFactory<String>() {
+            @Override
+            public String makeObject() throws Exception {
+                return new String();
             }
 
-            public boolean validateObject(Object obj) {
+            @Override
+            public boolean validateObject(String obj) {
                 throw new OutOfMemoryError();
             }
         });
@@ -194,16 +198,19 @@ public class TestSoftRefOutOfMemory exte
         }
         pool.close();
         
-        pool = new SoftReferenceObjectPool(new BasePoolableObjectFactory() {
-            public Object makeObject() throws Exception {
-                return new Object();
+        pool = new SoftReferenceObjectPool<String>(new 
BasePoolableObjectFactory<String>() {
+            @Override
+            public String makeObject() throws Exception {
+                return new String();
             }
 
-            public boolean validateObject(Object obj) {
+            @Override
+            public boolean validateObject(String obj) {
                 throw new IllegalAccessError();
             }
 
-            public void destroyObject(Object obj) throws Exception {
+            @Override
+            public void destroyObject(String obj) throws Exception {
                 throw new OutOfMemoryError();
             }
         });
@@ -220,10 +227,10 @@ public class TestSoftRefOutOfMemory exte
     }
 
 
-    public static class SmallPoolableObjectFactory implements 
PoolableObjectFactory {
+    public static class SmallPoolableObjectFactory implements 
PoolableObjectFactory<String> {
         private int counter = 0;
 
-        public Object makeObject() {
+        public String makeObject() {
             counter++;
             // It seems that as of Java 1.4 String.valueOf may return an
             // intern()'ed String this may cause problems when the tests
@@ -232,15 +239,15 @@ public class TestSoftRefOutOfMemory exte
             // is returned eliminated false failures.
             return new String(String.valueOf(counter));
         }
-        public boolean validateObject(Object obj) {
+        public boolean validateObject(String obj) {
             return true;
         }
-        public void activateObject(Object obj) { }
-        public void passivateObject(Object obj) { }
-        public void destroyObject(Object obj) { }
+        public void activateObject(String obj) { }
+        public void passivateObject(String obj) { }
+        public void destroyObject(String obj) { }
     }
 
-    public static class LargePoolableObjectFactory implements 
PoolableObjectFactory {
+    public static class LargePoolableObjectFactory implements 
PoolableObjectFactory<String> {
         private String buffer;
         private int counter = 0;
 
@@ -250,15 +257,15 @@ public class TestSoftRefOutOfMemory exte
             buffer = new String(data);
         }
 
-        public Object makeObject() {
+        public String makeObject() {
             counter++;
             return String.valueOf(counter) + buffer;
         }
-        public boolean validateObject(Object obj) {
+        public boolean validateObject(String obj) {
             return true;
         }
-        public void activateObject(Object obj) { }
-        public void passivateObject(Object obj) { }
-        public void destroyObject(Object obj) { }
+        public void activateObject(String obj) { }
+        public void passivateObject(String obj) { }
+        public void destroyObject(String obj) { }
     }
 }
\ No newline at end of file

Modified: 
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestSoftReferenceObjectPool.java
URL: 
http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestSoftReferenceObjectPool.java?rev=1096375&r1=1096374&r2=1096375&view=diff
==============================================================================
--- 
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestSoftReferenceObjectPool.java
 (original)
+++ 
commons/proper/pool/trunk/src/test/org/apache/commons/pool2/impl/TestSoftReferenceObjectPool.java
 Sun Apr 24 20:13:44 2011
@@ -32,9 +32,10 @@ public class TestSoftReferenceObjectPool
         super(testName);
     }
 
-    protected ObjectPool makeEmptyPool(int cap) {
-        return new SoftReferenceObjectPool(
-            new PoolableObjectFactory()  {
+    @Override
+    protected ObjectPool<Object> makeEmptyPool(int cap) {
+        return new SoftReferenceObjectPool<Object>(
+            new PoolableObjectFactory<Object>()  {
                 int counter = 0;
                 public Object makeObject() { return String.valueOf(counter++); 
}
                 public void destroyObject(Object obj) { }
@@ -45,18 +46,22 @@ public class TestSoftReferenceObjectPool
             );
     }
 
-    protected ObjectPool makeEmptyPool(final PoolableObjectFactory factory) {
-        return new SoftReferenceObjectPool(factory);
+    @Override
+    protected ObjectPool<Object> makeEmptyPool(final 
PoolableObjectFactory<Object> factory) {
+        return new SoftReferenceObjectPool<Object>(factory);
     }
 
+    @Override
     protected Object getNthObject(int n) {
         return String.valueOf(n);
     }
 
+    @Override
     protected boolean isLifo() {
         return false;
     }
 
+    @Override
     protected boolean isFifo() {
         return false;
     }


Reply via email to