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


The following commit(s) were added to refs/heads/master by this push:
     new ada49dd9 Sigh, I did not see this was a JUnit 3 test in the PR.
ada49dd9 is described below

commit ada49dd973734c7afe344e0e5acdb46f32b9d574
Author: Gary Gregory <[email protected]>
AuthorDate: Sat Feb 24 13:08:19 2024 -0500

    Sigh, I did not see this was a JUnit 3 test in the PR.
    
    - Only use static imports for JUnit
    - Rename test class
---
 src/main/java/org/apache/commons/net/ftp/FTP.java  |  6 +++
 .../java/org/apache/commons/net/ftp/FTPClient.java | 10 +++-
 ...ateTest.java => FTPClientTransferModeTest.java} | 57 ++++++++++++----------
 3 files changed, 46 insertions(+), 27 deletions(-)

diff --git a/src/main/java/org/apache/commons/net/ftp/FTP.java 
b/src/main/java/org/apache/commons/net/ftp/FTP.java
index 72945cc4..f4a7ff13 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTP.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTP.java
@@ -157,6 +157,12 @@ public class FTP extends SocketClient {
      */
     public static final int DEFLATE_TRANSFER_MODE = 13;
 
+    /**
+     * A constant used to indicate a file is to be transferred as FTP 
(un)compressing data in the GZIP compression format. All constants ending in
+     * <code>TRANSFER_MODE</code> are used to indicate file transfer modes.
+     */
+    public static final int GZIP_TRANSFER_MODE = 14;
+
     // We have to ensure that the protocol communication is in ASCII,
     // but we use ISO-8859-1 just in case 8-bit characters cross
     // the wire.
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 9d192c83..69e19c1e 100644
--- a/src/main/java/org/apache/commons/net/ftp/FTPClient.java
+++ b/src/main/java/org/apache/commons/net/ftp/FTPClient.java
@@ -3419,8 +3419,14 @@ public class FTPClient extends FTP implements 
Configurable {
         return FTPReply.isPositiveCompletion(smnt(pathname));
     }
 
-    @SuppressWarnings("resource")
     private Socket wrapOnDeflate(final Socket plainSocket) {
-        return fileTransferMode == DEFLATE_TRANSFER_MODE ? new 
DeflateSocket(plainSocket) : plainSocket;
+        switch (fileTransferMode) {
+        case DEFLATE_TRANSFER_MODE:
+            return new DeflateSocket(plainSocket);
+        case GZIP_TRANSFER_MODE:
+            //return new GZIPSocket(plainSocket);
+        default:
+            return plainSocket;
+        }
     }
 }
diff --git a/src/test/java/org/apache/commons/net/ftp/FTPClientDeflateTest.java 
b/src/test/java/org/apache/commons/net/ftp/FTPClientTransferModeTest.java
similarity index 77%
rename from src/test/java/org/apache/commons/net/ftp/FTPClientDeflateTest.java
rename to 
src/test/java/org/apache/commons/net/ftp/FTPClientTransferModeTest.java
index d1c7bb2b..ea39e4d5 100644
--- a/src/test/java/org/apache/commons/net/ftp/FTPClientDeflateTest.java
+++ b/src/test/java/org/apache/commons/net/ftp/FTPClientTransferModeTest.java
@@ -17,6 +17,9 @@
 
 package org.apache.commons.net.ftp;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
@@ -29,8 +32,6 @@ import java.time.Instant;
 import java.util.ArrayList;
 import java.util.List;
 
-import junit.framework.TestCase;
-
 import org.apache.commons.io.FileUtils;
 import org.apache.ftpserver.FtpServer;
 import org.apache.ftpserver.FtpServerFactory;
@@ -42,10 +43,16 @@ import org.apache.ftpserver.listener.ListenerFactory;
 import org.apache.ftpserver.usermanager.PropertiesUserManagerFactory;
 import org.apache.ftpserver.usermanager.impl.BaseUser;
 import org.apache.ftpserver.usermanager.impl.WritePermission;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
 
-public class FTPClientDeflateTest extends TestCase {
+public class FTPClientTransferModeTest {
 
     private static final class FtpServerAndPort {
+
         private final int port;
         private final FtpServer ftpServer;
 
@@ -61,7 +68,7 @@ public class FTPClientDeflateTest extends TestCase {
     }
 
     private static final String DEFAULT_HOME = "ftp_root/";
-
+    
     private static UserManager initUserManager(final String username, final 
String password) throws FtpException {
 
         final PropertiesUserManagerFactory propertiesUserManagerFactory = new 
PropertiesUserManagerFactory();
@@ -81,19 +88,17 @@ public class FTPClientDeflateTest extends TestCase {
     }
 
     private static void runWithFTPserver(final Runner runner) throws Exception 
{
-
-        final String username = "test";
+        final String userName = "test";
         final String password = "test";
-        final FtpServerAndPort ftpServerAndPort = 
setupPlainFTPserver(username, password);
+        final FtpServerAndPort ftpServerAndPort = 
setupPlainFTPserver(userName, password);
         try {
-            runner.run(ftpServerAndPort.port, username, password);
+            runner.run(ftpServerAndPort.port, userName, password);
         } finally {
             ftpServerAndPort.ftpServer.stop();
         }
     }
 
     private static FtpServerAndPort setupPlainFTPserver(final String username, 
final String password) throws FtpException {
-
         final FtpServerFactory serverFactory = new FtpServerFactory();
 
         // Init user
@@ -114,18 +119,19 @@ public class FTPClientDeflateTest extends TestCase {
         return new FtpServerAndPort(server, listener.getPort());
     }
 
-    @Override
+    @BeforeEach
     protected void setUp() throws IOException {
         FileUtils.deleteDirectory(new File(DEFAULT_HOME));
     }
 
-    @Override
+    @AfterEach
     protected void tearDown() throws Exception {
         FileUtils.deleteDirectory(new File(DEFAULT_HOME));
     }
 
-    public void testRetrievingFiles() throws Exception {
-
+    @ParameterizedTest
+    @ValueSource(ints = {FTP.DEFLATE_TRANSFER_MODE})
+    public void testRetrievingFiles(final int transferMode) throws Exception {
         new File(DEFAULT_HOME).mkdirs();
         final String filename = "test_download.txt";
         final String fileContent = "Created at " + Instant.now();
@@ -133,44 +139,45 @@ public class FTPClientDeflateTest extends TestCase {
 
         runWithFTPserver((port, user, password) -> {
             final FTPClient client = new FTPClient();
-            try {
+            try {   
                 client.connect("localhost", port);
                 client.login(user, password);
-                assertTrue("Mode Z successfully activated", 
client.setFileTransferMode(FTP.DEFLATE_TRANSFER_MODE));
+                assertTrue(client.setFileTransferMode(transferMode));
 
                 final FTPFile[] files = client.listFiles();
-                assertEquals("Only single file in home directory", 1, 
files.length);
+                assertEquals(1, files.length);
 
                 final ByteArrayOutputStream bos = new ByteArrayOutputStream();
-                assertTrue("File successfully transferred", 
client.retrieveFile(files[0].getName(), bos));
-                assertEquals("File content is not corrupted", fileContent, new 
String(bos.toByteArray(), StandardCharsets.UTF_8));
+                assertTrue(client.retrieveFile(files[0].getName(), bos));
+                assertEquals(fileContent, new String(bos.toByteArray(), 
StandardCharsets.UTF_8));
             } finally {
                 client.logout();
             }
         });
     }
 
-    public void testStoringFiles() throws Exception {
-
+    @ParameterizedTest
+    @ValueSource(ints = {FTP.DEFLATE_TRANSFER_MODE})
+    public void testStoringFiles(final int transferMode) throws Exception {
         runWithFTPserver((port, user, password) -> {
             final FTPClient client = new FTPClient();
             try {
                 client.connect("localhost", port);
                 client.login(user, password);
-                assertTrue("Mode Z successfully activated", 
client.setFileTransferMode(FTP.DEFLATE_TRANSFER_MODE));
+                assertTrue(client.setFileTransferMode(transferMode));
 
                 final FTPFile[] filesBeforeUpload = client.listFiles();
-                assertEquals("No files in home directory before upload", 0, 
filesBeforeUpload.length);
+                assertEquals(0, filesBeforeUpload.length);
 
                 final String fileName = "test_upload.txt";
                 final String fileContent = "Created at " + Instant.now();
-                assertTrue("File successfully transferred", 
client.storeFile(fileName, new 
ByteArrayInputStream(fileContent.getBytes(StandardCharsets.UTF_8))));
+                assertTrue(client.storeFile(fileName, new 
ByteArrayInputStream(fileContent.getBytes(StandardCharsets.UTF_8))));
 
                 final FTPFile[] filesAfterUpload = client.listFiles();
-                assertEquals("Single file in home directory after upload", 1, 
filesAfterUpload.length);
+                assertEquals(1, filesAfterUpload.length);
 
                 final Path p = Paths.get(DEFAULT_HOME, fileName);
-                assertEquals("File content is not corrupted", fileContent, new 
String(Files.readAllBytes(p), StandardCharsets.UTF_8));
+                assertEquals(fileContent, new String(Files.readAllBytes(p), 
StandardCharsets.UTF_8));
             } finally {
                 client.logout();
             }

Reply via email to