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 e7eb845b1e33b29acfd90648642bedd878ed761b
Author: Gary Gregory <[email protected]>
AuthorDate: Wed Jan 28 15:58:31 2026 -0500

    Reuse ThreadUtils in tests
---
 .../java/org/apache/commons/net/ftp/AbstractFtpsTest.java     | 11 ++++-------
 src/test/java/org/apache/commons/net/ntp/TestNtpClient.java   |  7 ++-----
 .../java/org/apache/commons/net/telnet/TelnetClientTest.java  |  7 ++-----
 src/test/java/org/apache/commons/net/tftp/TFTPServer.java     |  2 +-
 .../java/org/apache/commons/net/tftp/TFTPServerPathTest.java  |  1 +
 5 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/src/test/java/org/apache/commons/net/ftp/AbstractFtpsTest.java 
b/src/test/java/org/apache/commons/net/ftp/AbstractFtpsTest.java
index e75aa882..d159f88f 100644
--- a/src/test/java/org/apache/commons/net/ftp/AbstractFtpsTest.java
+++ b/src/test/java/org/apache/commons/net/ftp/AbstractFtpsTest.java
@@ -29,6 +29,7 @@ import java.time.Duration;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.output.NullOutputStream;
+import org.apache.commons.lang3.ThreadUtils;
 import org.apache.commons.net.PrintCommandListener;
 import org.apache.ftpserver.FtpServer;
 import org.apache.ftpserver.FtpServerFactory;
@@ -177,13 +178,9 @@ public abstract class AbstractFtpsTest {
         assertClientCode(client);
         assertEquals(SocketPort, client.getRemotePort());
         //
-        try {
-            // HACK: Without this sleep, the user command sometimes does not 
reach the ftpserver
-            // This only seems to affect GitHub builds, and only Java 11+
-            Thread.sleep(200); // 100 seems to be not always enough
-        } catch (final InterruptedException ignore) {
-            // ignore
-        }
+        // HACK: Without this sleep, the user command sometimes does not reach 
the ftpserver
+        // This only seems to affect GitHub builds, and only Java 11+
+        ThreadUtils.sleepQuietly(Duration.ofMillis(200));
         assertTrue(client.login("test", "test"));
         assertClientCode(client);
         //
diff --git a/src/test/java/org/apache/commons/net/ntp/TestNtpClient.java 
b/src/test/java/org/apache/commons/net/ntp/TestNtpClient.java
index e9bd4b8e..339e68a5 100644
--- a/src/test/java/org/apache/commons/net/ntp/TestNtpClient.java
+++ b/src/test/java/org/apache/commons/net/ntp/TestNtpClient.java
@@ -25,6 +25,7 @@ import java.io.IOException;
 import java.net.InetAddress;
 import java.time.Duration;
 
+import org.apache.commons.lang3.ThreadUtils;
 import org.apache.commons.net.examples.ntp.SimpleNTPServer;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
@@ -57,11 +58,7 @@ public class TestNtpClient {
                 break;
             }
             // if not running then sleep 2 seconds and try again
-            try {
-                Thread.sleep(2000);
-            } catch (final InterruptedException e) {
-                // ignore
-            }
+            ThreadUtils.sleepQuietly(Duration.ofMillis(2000));
         }
         assertTrue(running);
     }
diff --git a/src/test/java/org/apache/commons/net/telnet/TelnetClientTest.java 
b/src/test/java/org/apache/commons/net/telnet/TelnetClientTest.java
index 7d7222f4..e847561f 100644
--- a/src/test/java/org/apache/commons/net/telnet/TelnetClientTest.java
+++ b/src/test/java/org/apache/commons/net/telnet/TelnetClientTest.java
@@ -28,6 +28,7 @@ import java.io.PipedInputStream;
 import java.io.PipedOutputStream;
 import java.time.Duration;
 
+import org.apache.commons.lang3.ThreadUtils;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -215,11 +216,7 @@ public class TelnetClientTest implements 
TelnetNotificationHandler {
         OPTIONS.close();
         STANDARD.close();
         SMALL_BUFFER.close();
-        try {
-            Thread.sleep(1000);
-        } catch (final InterruptedException ie) {
-            // do nothing
-        }
+        ThreadUtils.sleepQuietly(Duration.ofMillis(1000));
     }
 
     /*
diff --git a/src/test/java/org/apache/commons/net/tftp/TFTPServer.java 
b/src/test/java/org/apache/commons/net/tftp/TFTPServer.java
index 4f18a468..6e8efdad 100644
--- a/src/test/java/org/apache/commons/net/tftp/TFTPServer.java
+++ b/src/test/java/org/apache/commons/net/tftp/TFTPServer.java
@@ -593,7 +593,7 @@ public class TFTPServer implements Runnable, AutoCloseable {
         try {
             serverThread.join();
         } catch (final InterruptedException e) {
-            // we've done the best we could, return
+            Thread.currentThread().interrupt();
         }
     }
 
diff --git a/src/test/java/org/apache/commons/net/tftp/TFTPServerPathTest.java 
b/src/test/java/org/apache/commons/net/tftp/TFTPServerPathTest.java
index cf54a190..14cf884e 100644
--- a/src/test/java/org/apache/commons/net/tftp/TFTPServerPathTest.java
+++ b/src/test/java/org/apache/commons/net/tftp/TFTPServerPathTest.java
@@ -65,6 +65,7 @@ public class TFTPServerPathTest {
                 try {
                     Thread.sleep(500);
                 } catch (final InterruptedException e1) {
+                    Thread.currentThread().interrupt();
                     fail(e);
                 }
                 Files.deleteIfExists(path);

Reply via email to