You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/02/16 17:14:33 UTC
(commons-net) 07/15: Fix test
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 27742fb041647c49349cf642085194fe86f2fc0a
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sun Feb 16 10:41:00 2025 -0500
Fix test
Remove extra vertical whitespace
---
.../apache/commons/net/PrintCommandListener.java | 1 -
.../commons/net/ftp/ListingFunctionalTest.java | 38 +++-------------------
2 files changed, 5 insertions(+), 34 deletions(-)
diff --git a/src/main/java/org/apache/commons/net/PrintCommandListener.java b/src/main/java/org/apache/commons/net/PrintCommandListener.java
index f1390d8d..95d304e7 100644
--- a/src/main/java/org/apache/commons/net/PrintCommandListener.java
+++ b/src/main/java/org/apache/commons/net/PrintCommandListener.java
@@ -33,7 +33,6 @@ public class PrintCommandListener implements ProtocolCommandListener {
private final PrintWriter writer;
private final boolean nologin;
private final char eolMarker;
-
private final boolean directionMarker;
/**
diff --git a/src/test/java/org/apache/commons/net/ftp/ListingFunctionalTest.java b/src/test/java/org/apache/commons/net/ftp/ListingFunctionalTest.java
index 28b3b29f..0487c385 100644
--- a/src/test/java/org/apache/commons/net/ftp/ListingFunctionalTest.java
+++ b/src/test/java/org/apache/commons/net/ftp/ListingFunctionalTest.java
@@ -24,6 +24,9 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.net.PrintCommandListener;
+
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -59,19 +62,15 @@ public class ListingFunctionalTest extends TestCase {
final Class<?> clasz = ListingFunctionalTest.class;
final Method[] methods = clasz.getDeclaredMethods();
final TestSuite allSuites = new TestSuite("FTP Listing Functional Test Suite");
-
for (final String[] element : testData) {
final TestSuite suite = new TestSuite(element[VALID_PARSERKEY] + " @ " + element[HOSTNAME]);
-
for (final Method method : methods) {
if (method.getName().startsWith("test")) {
suite.addTest(new ListingFunctionalTest(method.getName(), element));
}
}
-
allSuites.addTest(suite);
}
-
return allSuites;
}
@@ -98,21 +97,16 @@ public class ListingFunctionalTest extends TestCase {
private boolean findByName(final List<?> fileList, final String string) {
boolean found = false;
final Iterator<?> iter = fileList.iterator();
-
while (iter.hasNext() && !found) {
final Object element = iter.next();
-
if (element instanceof FTPFile) {
final FTPFile file = (FTPFile) element;
-
found = file.getName().equals(string);
} else {
final String fileName = (String) element;
-
found = fileName.endsWith(string);
}
}
-
return found;
}
@@ -126,7 +120,7 @@ public class ListingFunctionalTest extends TestCase {
client.connect(hostName);
client.login("anonymous", "anonymous");
client.enterLocalPassiveMode();
-// client.addProtocolCommandListener(new PrintCommandListener(System.out));
+ client.addProtocolCommandListener(new PrintCommandListener(System.out));
}
/*
@@ -139,11 +133,9 @@ public class ListingFunctionalTest extends TestCase {
} catch (final IOException e) {
e.printStackTrace();
}
-
if (client.isConnected()) {
client.disconnect();
}
-
client = null;
super.tearDown();
}
@@ -153,10 +145,8 @@ public class ListingFunctionalTest extends TestCase {
*/
public void testInitiateListParsing() throws IOException {
client.changeWorkingDirectory(validPath);
-
final FTPListParseEngine engine = client.initiateListParsing();
final List<FTPFile> files = Arrays.asList(engine.getNext(25));
-
assertTrue(files.toString(), findByName(files, validFilename));
}
@@ -166,7 +156,6 @@ public class ListingFunctionalTest extends TestCase {
public void testInitiateListParsingWithPath() throws IOException {
final FTPListParseEngine engine = client.initiateListParsing(validParserKey, validPath);
final List<FTPFile> files = Arrays.asList(engine.getNext(25));
-
assertTrue(files.toString(), findByName(files, validFilename));
}
@@ -176,7 +165,6 @@ public class ListingFunctionalTest extends TestCase {
public void testInitiateListParsingWithPathAndAutodetection() throws IOException {
final FTPListParseEngine engine = client.initiateListParsing(validPath);
final List<FTPFile> files = Arrays.asList(engine.getNext(25));
-
assertTrue(files.toString(), findByName(files, validFilename));
}
@@ -185,7 +173,6 @@ public class ListingFunctionalTest extends TestCase {
*/
public void testInitiateListParsingWithPathAndAutodetectionButEmpty() throws IOException {
final FTPListParseEngine engine = client.initiateListParsing(invalidPath);
-
assertFalse(engine.hasNext());
}
@@ -194,7 +181,6 @@ public class ListingFunctionalTest extends TestCase {
*/
public void testInitiateListParsingWithPathAndIncorrectParser() throws IOException {
final FTPListParseEngine engine = client.initiateListParsing(invalidParserKey, invalidPath);
-
assertFalse(engine.hasNext());
}
@@ -205,15 +191,12 @@ public class ListingFunctionalTest extends TestCase {
final FTPClientConfig config = new FTPClientConfig(validParserKey);
client.configure(config);
final List<FTPFile> files = Arrays.asList(client.listFiles(validPath));
-
assertTrue(files.toString(), findByName(files, validFilename));
}
public void testListFilesWithAutodection() throws IOException {
client.changeWorkingDirectory(validPath);
-
final List<FTPFile> files = Arrays.asList(client.listFiles());
-
assertTrue(files.toString(), findByName(files, validFilename));
}
@@ -223,11 +206,8 @@ public class ListingFunctionalTest extends TestCase {
public void testListFilesWithIncorrectParser() throws IOException {
final FTPClientConfig config = new FTPClientConfig(invalidParserKey);
client.configure(config);
-
final FTPFile[] files = client.listFiles(validPath);
-
assertNotNull(files);
-
// This may well fail, e.g. window parser for VMS listing
assertArrayEquals("Expected empty array: " + Arrays.toString(files), new FTPFile[] {}, files);
}
@@ -237,7 +217,6 @@ public class ListingFunctionalTest extends TestCase {
*/
public void testListFilesWithPathAndAutodectionButEmpty() throws IOException {
final FTPFile[] files = client.listFiles(invalidPath);
-
assertEquals(0, files.length);
}
@@ -246,7 +225,6 @@ public class ListingFunctionalTest extends TestCase {
*/
public void testListFilesWithPathAndAutodetection() throws IOException {
final List<FTPFile> files = Arrays.asList(client.listFiles(validPath));
-
assertTrue(files.toString(), findByName(files, validFilename));
}
@@ -255,13 +233,9 @@ public class ListingFunctionalTest extends TestCase {
*/
public void testListNames() throws IOException {
client.changeWorkingDirectory(validPath);
-
final String[] names = client.listNames();
-
assertNotNull(names);
-
final List<String> lnames = Arrays.asList(names);
-
assertTrue(lnames.toString(), lnames.contains(validFilename));
}
@@ -272,14 +246,12 @@ public class ListingFunctionalTest extends TestCase {
final String[] listNames = client.listNames(validPath);
assertNotNull("listNames not null", listNames);
final List<String> names = Arrays.asList(listNames);
-
assertTrue(names.toString(), findByName(names, validFilename));
}
public void testListNamesWithPathButEmpty() throws IOException {
final String[] names = client.listNames(invalidPath);
-
- assertNull(names);
+ assertTrue(ArrayUtils.isEmpty(names));
}
public void testPrintWorkingDirectory() throws IOException {