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-collections.git


The following commit(s) were added to refs/heads/master by this push:
     new a53127e  Use try-with-resources to fix a random failure seen on Java 
12.
a53127e is described below

commit a53127e3a58bdc2d730afa1dd918e47a4c19a0c8
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Sun Apr 26 09:57:57 2020 -0400

    Use try-with-resources to fix a random failure seen on Java 12.
---
 .../properties/EmptyPropertiesTest.java            | 28 ++++++++++++++--------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git 
a/src/test/java/org/apache/commons/collections4/properties/EmptyPropertiesTest.java
 
b/src/test/java/org/apache/commons/collections4/properties/EmptyPropertiesTest.java
index 1c63249..bb9c4c4 100644
--- 
a/src/test/java/org/apache/commons/collections4/properties/EmptyPropertiesTest.java
+++ 
b/src/test/java/org/apache/commons/collections4/properties/EmptyPropertiesTest.java
@@ -247,18 +247,26 @@ public class EmptyPropertiesTest {
     }
 
     @Test
-    public void testSave() {
+    public void testSave() throws IOException {
         final String comments = "Hello world!";
         // actual
-        final ByteArrayOutputStream actual = new ByteArrayOutputStream();
-        PropertiesFactory.EMPTY_PROPERTIES.save(new PrintStream(actual), 
comments);
-        // expected
-        final ByteArrayOutputStream expected = new ByteArrayOutputStream();
-        PropertiesFactory.INSTANCE.createProperties().save(new 
PrintStream(expected), comments);
-        Assert.assertArrayEquals(expected.toByteArray(), actual.toByteArray());
-        expected.reset();
-        new Properties().save(new PrintStream(expected), comments);
-        Assert.assertArrayEquals(expected.toByteArray(), actual.toByteArray());
+        try (final ByteArrayOutputStream actual = new ByteArrayOutputStream()) 
{
+            try (final PrintStream out = new PrintStream(actual)) {
+                PropertiesFactory.EMPTY_PROPERTIES.save(out, comments);
+            }
+            // expected
+            try (final ByteArrayOutputStream expected = new 
ByteArrayOutputStream()) {
+                try (final PrintStream out = new PrintStream(expected)) {
+                    PropertiesFactory.INSTANCE.createProperties().save(out, 
comments);
+                }
+                Assert.assertArrayEquals(expected.toByteArray(), 
actual.toByteArray());
+                expected.reset();
+                try (final PrintStream out = new PrintStream(expected)) {
+                    new Properties().save(out, comments);
+                }
+                Assert.assertArrayEquals(expected.toByteArray(), 
actual.toByteArray());
+            }
+        }
     }
 
     @Test(expected = UnsupportedOperationException.class)

Reply via email to