From b14ee39cca486bda106758a48d31c91ad52d0d83 Mon Sep 17 00:00:00 2001 From: Elric V Date: Mon, 4 Mar 2024 22:27:12 +0100 Subject: [PATCH] Convert JUnit 4 Parameterized test to @Nested tests in JUnit 5 --- .../commons/net/ftp/AbstractFtpsTest.java | 156 +++++++++++++++- .../commons/net/ftp/FTPSClientTest.java | 168 ++---------------- 2 files changed, 164 insertions(+), 160 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 4ed83879b..c41f7b73a 100644 --- a/src/test/java/org/apache/commons/net/ftp/AbstractFtpsTest.java +++ b/src/test/java/org/apache/commons/net/ftp/AbstractFtpsTest.java @@ -26,6 +26,8 @@ import java.net.SocketException; import java.net.URL; import java.time.Duration; +import java.time.Instant; +import java.util.Calendar; import org.apache.commons.io.FileUtils; import org.apache.commons.io.output.NullOutputStream; @@ -39,6 +41,9 @@ import org.apache.ftpserver.ssl.SslConfigurationFactory; import org.apache.ftpserver.usermanager.PropertiesUserManagerFactory; import org.apache.ftpserver.usermanager.impl.BaseUser; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Timeout; /** * Tests {@link FTPSClient}. @@ -62,6 +67,10 @@ public abstract class AbstractFtpsTest { private static final boolean TRACE_CALLS = Boolean.parseBoolean(System.getenv("TRACE_CALLS")); private static final boolean ADD_LISTENER = Boolean.parseBoolean(System.getenv("ADD_LISTENER")); private static final long startTime = System.nanoTime(); + private static final String USER_PROPS_RES = "org/apache/commons/net/ftpsserver/users.properties"; + private static final String SERVER_JKS_RES = "org/apache/commons/net/ftpsserver/ftpserver.jks"; + + private final boolean endpointCheckingEnabled; /** * Returns the test directory as a String. @@ -136,9 +145,12 @@ protected static void trace(final String msg) { } } - private final boolean endpointCheckingEnabled; + @BeforeAll + public static void setupServer() throws Exception { + AbstractFtpsTest.setupServer(AbstractFtpsTest.IMPLICIT, USER_PROPS_RES, SERVER_JKS_RES, "target/test-classes/org/apache/commons/net/test-data"); + } - public AbstractFtpsTest(final boolean endpointCheckingEnabled, final String userPropertiesResource, final String serverJksResource) { + public AbstractFtpsTest(final boolean endpointCheckingEnabled) { this.endpointCheckingEnabled = endpointCheckingEnabled; } @@ -208,4 +220,144 @@ protected void retrieveFile(final String pathname) throws SocketException, IOExc client.disconnect(); } } + + + @Test + @Timeout(TEST_TIMEOUT) + public void testHasFeature() throws SocketException, IOException { + trace(">>testHasFeature"); + loginClient().disconnect(); + trace("<>testListFilesPathNameEmpty"); + testListFiles(""); + trace("<>testListFilesPathNameJunk"); + testListFiles(" Junk "); + trace("<>testListFilesPathNameNull"); + testListFiles(null); + trace("<>testListFilesPathNameRoot"); + testListFiles("/"); + trace("<>testMdtmCalendar"); + testMdtmCalendar("/file.txt"); + trace("<>testMdtmFile"); + testMdtmFile("/file.txt"); + trace("<>testMdtmInstant"); + testMdtmInstant("/file.txt"); + trace("<>testOpenClose"); + final FTPSClient ftpsClient = loginClient(); + try { + assertTrue(ftpsClient.hasFeature("MODE")); + assertTrue(ftpsClient.hasFeature(FTPCmd.MODE)); + } finally { + ftpsClient.disconnect(); + } + trace("<>testRetrieveFilePathNameRoot"); + retrieveFile("/file.txt"); + trace("< */ -@RunWith(Parameterized.class) -public class FTPSClientTest extends AbstractFtpsTest { - - private static final String USER_PROPS_RES = "org/apache/commons/net/ftpsserver/users.properties"; - - private static final String SERVER_JKS_RES = "org/apache/commons/net/ftpsserver/ftpserver.jks"; - - @BeforeClass - public static void setupServer() throws Exception { - setupServer(IMPLICIT, USER_PROPS_RES, SERVER_JKS_RES, "target/test-classes/org/apache/commons/net/test-data"); - } - - @Parameters(name = "endpointCheckingEnabled={0}") - public static Boolean[] testConstructurData() { - return new Boolean[] { Boolean.FALSE, Boolean.TRUE }; - } - - public FTPSClientTest(final boolean endpointCheckingEnabled) { - super(endpointCheckingEnabled, null, null); - } - - @Test(timeout = TEST_TIMEOUT) - public void testHasFeature() throws SocketException, IOException { - trace(">>testHasFeature"); - loginClient().disconnect(); - trace("<>testListFilesPathNameEmpty"); - testListFiles(""); - trace("<>testListFilesPathNameJunk"); - testListFiles(" Junk "); - trace("<>testListFilesPathNameNull"); - testListFiles(null); - trace("<>testListFilesPathNameRoot"); - testListFiles("/"); - trace("<>testMdtmCalendar"); - testMdtmCalendar("/file.txt"); - trace("<>testMdtmFile"); - testMdtmFile("/file.txt"); - trace("<>testMdtmInstant"); - testMdtmInstant("/file.txt"); - trace("<>testOpenClose"); - final FTPSClient ftpsClient = loginClient(); - try { - assertTrue(ftpsClient.hasFeature("MODE")); - assertTrue(ftpsClient.hasFeature(FTPCmd.MODE)); - } finally { - ftpsClient.disconnect(); - } - trace("<>testRetrieveFilePathNameRoot"); - retrieveFile("/file.txt"); - trace("<