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

commit eba2fb093bfae54921fe1751576e6f2916801218
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Tue Feb 25 17:28:21 2025 -0500

    Add tests for loading FTRP client properties
    
    - Internet refactoring
---
 .../java/org/apache/commons/net/ftp/FTPClient.java | 27 ++++++++++------------
 .../org/apache/commons/net/ftp/FTPClientTest.java  | 10 ++++++++
 .../org/apache/commons/net/test.properties         | 17 ++++++++++++++
 3 files changed, 39 insertions(+), 15 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/ftp/FTPClient.java 
b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
index f9027e06..55852642 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
@@ -375,25 +375,22 @@ public class FTPClient extends FTP implements 
Configurable {
     }
 
     private static final class PropertiesSingleton {
+        static final Properties PROPERTIES = 
loadResourceProperties(SYSTEM_TYPE_PROPERTIES);
+    }
 
-        static final Properties PROPERTIES;
-
-        static {
-            final InputStream resourceAsStream = 
FTPClient.class.getResourceAsStream(SYSTEM_TYPE_PROPERTIES);
-            Properties p = null;
-            if (resourceAsStream != null) {
-                p = new Properties();
-                try {
-                    p.load(resourceAsStream);
-                } catch (final IOException e) {
-                    // Ignored
-                } finally {
-                    IOUtils.closeQuietly(resourceAsStream);
+    static Properties loadResourceProperties(final String 
systemTypeProperties) {
+        Properties properties = null;
+        if (systemTypeProperties != null) {
+            try (InputStream inputStream = 
FTPClient.class.getResourceAsStream(systemTypeProperties)) {
+                if (inputStream != null) {
+                    properties = new Properties();
+                    properties.load(inputStream);
                 }
+            } catch (final IOException ignore) {
+                // ignore
             }
-            PROPERTIES = p;
         }
-
+        return properties;
     }
 
     /**
diff --git a/src/test/java/org/apache/commons/net/ftp/FTPClientTest.java 
b/src/test/java/org/apache/commons/net/ftp/FTPClientTest.java
index 5eed6e46..8c9bcbc2 100644
--- a/src/test/java/org/apache/commons/net/ftp/FTPClientTest.java
+++ b/src/test/java/org/apache/commons/net/ftp/FTPClientTest.java
@@ -128,6 +128,16 @@ public class FTPClientTest extends TestCase {
         assertEquals(-1, client.getPassivePort());
     }
 
+    public void testLoadResourceProperties() {
+        assertNull(FTPClient.loadResourceProperties(null));
+        
assertNull(FTPClient.loadResourceProperties("this/does/not/exist.properties"));
+        
assertNull(FTPClient.loadResourceProperties("/this/does/not/exist.properties"));
+        
assertNull(FTPClient.loadResourceProperties(FTPClient.SYSTEM_TYPE_PROPERTIES));
+        assertNotNull(FTPClient.loadResourceProperties(""));
+        
assertNotNull(FTPClient.loadResourceProperties("/org/apache/commons/net/examples/examples.properties"));
+        
assertNotNull(FTPClient.loadResourceProperties("/org/apache/commons/net/test.properties"));
+    }
+
     public void testParseClient() {
         for (int i = 0; i < TESTS.length; i += 2) {
             assertEquals("Failed to parse", TESTS[i + 1], 
FTPClient.parsePathname(TESTS[i]));
diff --git a/src/test/resources/org/apache/commons/net/test.properties 
b/src/test/resources/org/apache/commons/net/test.properties
new file mode 100644
index 00000000..09921d79
--- /dev/null
+++ b/src/test/resources/org/apache/commons/net/test.properties
@@ -0,0 +1,17 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+a=1
+b=2

Reply via email to