commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1532088 - /commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
Date Mon, 14 Oct 2013 20:51:40 GMT
Author: markt
Date: Mon Oct 14 20:51:40 2013
New Revision: 1532088

URL: http://svn.apache.org/r1532088
Log:
Fix some FindBugs warnings

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

Modified: commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java?rev=1532088&r1=1532087&r2=1532088&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
(original)
+++ commons/proper/pool/trunk/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
Mon Oct 14 20:51:40 2013
@@ -58,24 +58,8 @@ public class TestGenericKeyedObjectPool 
 
     @Override
     protected KeyedObjectPool<Object,Object> makeEmptyPool(int mincapacity) {
-
         KeyedPooledObjectFactory<Object,Object> factory =
-                new BaseKeyedPooledObjectFactory<Object,Object>()  {
-            ConcurrentHashMap<Object,AtomicInteger> map = new ConcurrentHashMap<Object,AtomicInteger>();
-            @Override
-            public Object create(Object key) throws Exception {
-                int counter = 0;
-                AtomicInteger Counter = map.get(key);
-                if(null != Counter) {
-                    counter = Counter.incrementAndGet();
-                } else {
-                    map.put(key, new AtomicInteger(0));
-                    counter = 0;
-                }
-                return String.valueOf(key) + String.valueOf(counter);
-            }
-        };
-
+                new SimplePerKeyFactory();
         GenericKeyedObjectPool<Object,Object> pool =
             new GenericKeyedObjectPool<Object,Object>(factory);
         pool.setMaxTotalPerKey(mincapacity);
@@ -1043,12 +1027,7 @@ public class TestGenericKeyedObjectPool 
         long timeBetweenEvictionRunsMillis = 8;
         boolean blockWhenExhausted = false;
         boolean lifo = false;
-        KeyedPooledObjectFactory<Object,Object> factory = new BaseKeyedPooledObjectFactory<Object,Object>()
{
-            @Override
-            public Object create(Object key) throws Exception {
-                return null;
-            }
-        };
+        KeyedPooledObjectFactory<Object,Object> factory = new DummyFactory();
 
         GenericKeyedObjectPool<Object,Object> pool =
                 new GenericKeyedObjectPool<Object,Object>(factory);
@@ -1790,6 +1769,34 @@ public class TestGenericKeyedObjectPool 
         Set<ObjectName> result = mbs.queryNames(oname, null);
         Assert.assertEquals(1, result.size());
     }
+
+
+    private static class DummyFactory
+            extends BaseKeyedPooledObjectFactory<Object,Object> {
+        @Override
+        public Object create(Object key) throws Exception {
+            return null;
+        }
+    }
+
+
+    private static class SimplePerKeyFactory
+            extends BaseKeyedPooledObjectFactory<Object,Object> {
+        ConcurrentHashMap<Object,AtomicInteger> map =
+                new ConcurrentHashMap<Object,AtomicInteger>();
+        @Override
+        public Object create(Object key) throws Exception {
+            int counter = 0;
+            AtomicInteger Counter = map.get(key);
+            if(null != Counter) {
+                counter = Counter.incrementAndGet();
+            } else {
+                map.put(key, new AtomicInteger(0));
+                counter = 0;
+            }
+            return String.valueOf(key) + String.valueOf(counter);
+        }
+    }
 }
 
 



Mime
View raw message