You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/07/14 16:22:43 UTC

[commons-pool] 03/06: Use try-with-resources in test

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-pool.git

commit d88a1992240c5ee143a19f872789d6aa269c3dd5
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jul 14 11:44:28 2023 -0400

    Use try-with-resources in test
---
 .../pool2/impl/TestGenericKeyedObjectPool.java     | 52 +++++++++++-----------
 1 file changed, 27 insertions(+), 25 deletions(-)

diff --git a/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java b/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
index cb6712b5..94f7c32b 100644
--- a/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
+++ b/src/test/java/org/apache/commons/pool2/impl/TestGenericKeyedObjectPool.java
@@ -2445,37 +2445,39 @@ public class TestGenericKeyedObjectPool extends TestKeyedObjectPool {
     @Test
     @Timeout(value = 1000, unit = TimeUnit.MILLISECONDS)
     public void testNPEOnFactoryNull() throws InterruptedException {
+        // @formatter:off
         final DisconnectingWaiterFactory<String> factory = new DisconnectingWaiterFactory<>(
             () -> null,  // Override default to always return null from makeObject
             DisconnectingWaiterFactory.DEFAULT_DISCONNECTED_LIFECYCLE_ACTION,
             DisconnectingWaiterFactory.DEFAULT_DISCONNECTED_VALIDATION_ACTION
         );
-        final GenericKeyedObjectPool<String,Waiter,RuntimeException> pool = new GenericKeyedObjectPool<>(factory);
-        final String key = "one";
-        pool.setTestOnBorrow(true);
-        pool.setMaxTotal(-1);
-        pool.setMinIdlePerKey(1);
-        // Disconnect the factory - will always return null in this state
-        factory.disconnect();
-        try {
-            pool.borrowObject(key);
-            fail("Expecting NullPointerException");
-        } catch (final NullPointerException ex) {
-            // expected
-        }
-        try {
-            pool.addObject(key);
-            fail("Expecting NullPointerException");
-        } catch (final NullPointerException ex2) {
-            // expected
-        }
-        try {
-            pool.ensureMinIdle();
-            fail("Expecting NullPointerException");
-        } catch (final NullPointerException ex3) {
-            // expected
+        // @formatter:on
+        try (final GenericKeyedObjectPool<String, Waiter, RuntimeException> pool = new GenericKeyedObjectPool<>(factory)) {
+            final String key = "one";
+            pool.setTestOnBorrow(true);
+            pool.setMaxTotal(-1);
+            pool.setMinIdlePerKey(1);
+            // Disconnect the factory - will always return null in this state
+            factory.disconnect();
+            try {
+                pool.borrowObject(key);
+                fail("Expecting NullPointerException");
+            } catch (final NullPointerException ex) {
+                // expected
+            }
+            try {
+                pool.addObject(key);
+                fail("Expecting NullPointerException");
+            } catch (final NullPointerException ex2) {
+                // expected
+            }
+            try {
+                pool.ensureMinIdle();
+                fail("Expecting NullPointerException");
+            } catch (final NullPointerException ex3) {
+                // expected
+            }
         }
-        pool.close();
     }
 
     @Test