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


The following commit(s) were added to refs/heads/master by this push:
     new 1c584fea Use NIO in some tests
1c584fea is described below

commit 1c584fea2b5d8d5d9c71e4167fc96f0e1ba0da86
Author: Gary D. Gregory <[email protected]>
AuthorDate: Sat Mar 15 17:30:45 2025 -0400

    Use NIO in some tests
---
 .../configuration2/ConfigurationAssert.java        | 11 ++++++++
 .../DatabaseConfigurationTestHelper.java           |  4 +--
 .../configuration2/FileURLStreamHandler.java       |  6 ++---
 .../commons/configuration2/io/TestFileHandler.java | 30 ++++++++++++++--------
 4 files changed, 36 insertions(+), 15 deletions(-)

diff --git 
a/src/test/java/org/apache/commons/configuration2/ConfigurationAssert.java 
b/src/test/java/org/apache/commons/configuration2/ConfigurationAssert.java
index c1f4d4bc..8fffe508 100644
--- a/src/test/java/org/apache/commons/configuration2/ConfigurationAssert.java
+++ b/src/test/java/org/apache/commons/configuration2/ConfigurationAssert.java
@@ -23,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 import java.io.File;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.nio.file.Path;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -130,6 +131,16 @@ public final class ConfigurationAssert {
         return new File(TEST_DIR, name);
     }
 
+    /**
+     * Returns a {@code File} object for the specified test file.
+     *
+     * @param name the name of the test file
+     * @return a {@code File} object pointing to that test file
+     */
+    public static Path getTestPath(final String name) {
+        return TEST_DIR.toPath().resolve(name);
+    }
+
     /**
      * Returns a URL pointing to the specified test file. If the URL cannot be 
constructed, a runtime exception is thrown.
      *
diff --git 
a/src/test/java/org/apache/commons/configuration2/DatabaseConfigurationTestHelper.java
 
b/src/test/java/org/apache/commons/configuration2/DatabaseConfigurationTestHelper.java
index 11d863cc..20887180 100644
--- 
a/src/test/java/org/apache/commons/configuration2/DatabaseConfigurationTestHelper.java
+++ 
b/src/test/java/org/apache/commons/configuration2/DatabaseConfigurationTestHelper.java
@@ -17,7 +17,7 @@
 package org.apache.commons.configuration2;
 
 import java.io.File;
-import java.io.FileInputStream;
+import java.nio.file.Files;
 import java.sql.Connection;
 
 import javax.sql.DataSource;
@@ -181,7 +181,7 @@ public class DatabaseConfigurationTestHelper {
         // prepare the database
         final Connection conn = ds.getConnection();
         final IDatabaseConnection connection = new DatabaseConnection(conn);
-        final IDataSet dataSet = new XmlDataSet(new 
FileInputStream(ConfigurationAssert.getTestFile("dataset.xml")));
+        final IDataSet dataSet = new 
XmlDataSet(Files.newInputStream(ConfigurationAssert.getTestPath("dataset.xml")));
 
         try {
             DatabaseOperation.CLEAN_INSERT.execute(connection, dataSet);
diff --git 
a/src/test/java/org/apache/commons/configuration2/FileURLStreamHandler.java 
b/src/test/java/org/apache/commons/configuration2/FileURLStreamHandler.java
index 2c3fee54..8aae090b 100644
--- a/src/test/java/org/apache/commons/configuration2/FileURLStreamHandler.java
+++ b/src/test/java/org/apache/commons/configuration2/FileURLStreamHandler.java
@@ -33,10 +33,10 @@ import java.net.URLStreamHandler;
  */
 public class FileURLStreamHandler extends URLStreamHandler {
     @Override
-    protected URLConnection openConnection(final URL u) throws IOException {
-        final File file = new File(u.getFile());
+    protected URLConnection openConnection(final URL url) throws IOException {
+        final File file = new File(url.getFile());
 
-        return new URLConnection(u) {
+        return new URLConnection(url) {
 
             @Override
             public void connect() throws IOException {
diff --git 
a/src/test/java/org/apache/commons/configuration2/io/TestFileHandler.java 
b/src/test/java/org/apache/commons/configuration2/io/TestFileHandler.java
index 1a0b5ca5..10ec8bb1 100644
--- a/src/test/java/org/apache/commons/configuration2/io/TestFileHandler.java
+++ b/src/test/java/org/apache/commons/configuration2/io/TestFileHandler.java
@@ -35,7 +35,6 @@ import static org.mockito.Mockito.when;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.FileWriter;
@@ -46,8 +45,11 @@ import java.io.StringReader;
 import java.io.StringWriter;
 import java.io.Writer;
 import java.net.MalformedURLException;
+import java.net.URI;
 import java.net.URL;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
@@ -300,6 +302,14 @@ public class TestFileHandler {
         });
     }
 
+    private URI createTestURI() {
+        return createTestFile().toURI();
+    }
+
+    private URL createTestURL() throws MalformedURLException {
+        return createTestURI().toURL();
+    }
+
     /**
      * Tries to add a null listener.
      */
@@ -482,7 +492,7 @@ public class TestFileHandler {
     @Test
     public void testIsLocationDefinedURL() throws IOException {
         final FileHandler handler = new FileHandler();
-        handler.setURL(createTestFile().toURI().toURL());
+        handler.setURL(createTestURL());
         assertTrue(handler.isLocationDefined());
     }
 
@@ -632,10 +642,9 @@ public class TestFileHandler {
      */
     @Test
     public void testLoadFromReader() throws Exception {
-        final File file = createTestFile();
         final FileBasedTestImpl content = new FileBasedTestImpl();
         final FileHandler handler = new FileHandler(content);
-        try (Reader in = new FileReader(file)) {
+        try (Reader in = new FileReader(createTestFile())) {
             handler.load(in);
         }
         assertEquals(CONTENT, content.getContent());
@@ -665,24 +674,26 @@ public class TestFileHandler {
      */
     @Test
     public void testLoadFromStream() throws Exception {
-        final File file = createTestFile();
         final FileBasedTestImpl content = new FileBasedTestImpl();
         final FileHandler handler = new FileHandler(content);
-        try (FileInputStream in = new FileInputStream(file)) {
+        try (InputStream in = Files.newInputStream(createTestPath())) {
             handler.load(in);
         }
         assertEquals(CONTENT, content.getContent());
     }
 
+    private Path createTestPath() {
+        return createTestFile().toPath();
+    }
+
     /**
      * Tests whether data from a URL can be loaded.
      */
     @Test
     public void testLoadFromURL() throws Exception {
-        final File file = createTestFile();
         final FileBasedTestImpl content = new FileBasedTestImpl();
         final FileHandler handler = new FileHandler(content);
-        handler.load(file.toURI().toURL());
+        handler.load(createTestURL());
         assertEquals(CONTENT, content.getContent());
     }
 
@@ -691,10 +702,9 @@ public class TestFileHandler {
      */
     @Test
     public void testLoadFromURLLocation() throws Exception {
-        final File file = createTestFile();
         final FileBasedTestImpl content = new FileBasedTestImpl();
         final FileHandler handler = new FileHandler(content);
-        handler.setURL(file.toURI().toURL());
+        handler.setURL(createTestURL());
         handler.load();
         assertEquals(CONTENT, content.getContent());
     }

Reply via email to