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 b3293e67dcec11a6a9015ff25a743f5d92240a75 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sat Jul 22 21:44:00 2023 -0400 Sort members --- .../org/apache/commons/net/ftp/FTPFileTest.java | 58 ++++++------ .../net/imap/AuthenticatingIMAPClientTest.java | 12 +-- .../apache/commons/net/imap/IMAPCommandTest.java | 12 +-- .../org/apache/commons/net/imap/IMAPReplyTest.java | 102 ++++++++++----------- .../java/org/apache/commons/net/imap/IMAPTest.java | 86 ++++++++--------- .../org/apache/commons/net/util/Base64Test.java | 24 ++--- 6 files changed, 147 insertions(+), 147 deletions(-) diff --git a/src/test/java/org/apache/commons/net/ftp/FTPFileTest.java b/src/test/java/org/apache/commons/net/ftp/FTPFileTest.java index d8df3dbc..d822bd27 100644 --- a/src/test/java/org/apache/commons/net/ftp/FTPFileTest.java +++ b/src/test/java/org/apache/commons/net/ftp/FTPFileTest.java @@ -62,13 +62,6 @@ public class FTPFileTest { assertNull(file.getTimestampInstant()); } - @Test - public void testHasPermissionTrue() { - final FTPFile file = new FTPFile(); - file.setPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION, true); - assertTrue(file.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION)); - } - @Test public void testHasPermissionFalse() { final FTPFile file = new FTPFile(); @@ -82,6 +75,13 @@ public class FTPFileTest { assertFalse(invalidFile.hasPermission(FTPFile.GROUP_ACCESS, FTPFile.EXECUTE_PERMISSION)); } + @Test + public void testHasPermissionTrue() { + final FTPFile file = new FTPFile(); + file.setPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION, true); + assertTrue(file.hasPermission(FTPFile.USER_ACCESS, FTPFile.READ_PERMISSION)); + } + @Test public void testIsDirectory() { final FTPFile file = new FTPFile(); @@ -110,15 +110,23 @@ public class FTPFileTest { } @Test - public void toFormattedStringInvalidFile() { - final FTPFile invalidFile = new FTPFile("LIST"); - assertEquals("[Invalid: could not parse file entry]", invalidFile.toFormattedString()); + public void testToString() { + final FTPFile file = new FTPFile(); + file.setRawListing("LIST"); + assertEquals(file.getRawListing(), file.toString()); } @Test - public void toFormattedStringUnknownType() { + public void testToStringDefault() { final FTPFile file = new FTPFile(); - assertTrue(file.toFormattedString().startsWith("?")); + assertNull(file.toString()); + } + + @Test + public void toFormattedStringDirectoryType() { + final FTPFile file = new FTPFile(); + file.setType(FTPFile.DIRECTORY_TYPE); + assertTrue(file.toFormattedString().startsWith("d")); } @Test @@ -129,10 +137,9 @@ public class FTPFileTest { } @Test - public void toFormattedStringDirectoryType() { - final FTPFile file = new FTPFile(); - file.setType(FTPFile.DIRECTORY_TYPE); - assertTrue(file.toFormattedString().startsWith("d")); + public void toFormattedStringInvalidFile() { + final FTPFile invalidFile = new FTPFile("LIST"); + assertEquals("[Invalid: could not parse file entry]", invalidFile.toFormattedString()); } @Test @@ -142,6 +149,12 @@ public class FTPFileTest { assertTrue(file.toFormattedString().startsWith("l")); } + @Test + public void toFormattedStringUnknownType() { + final FTPFile file = new FTPFile(); + assertTrue(file.toFormattedString().startsWith("?")); + } + @Test public void toFormattedStringWithTimezone() { final FTPFile file = new FTPFile(); @@ -171,17 +184,4 @@ public class FTPFileTest { ); } - @Test - public void testToStringDefault() { - final FTPFile file = new FTPFile(); - assertNull(file.toString()); - } - - @Test - public void testToString() { - final FTPFile file = new FTPFile(); - file.setRawListing("LIST"); - assertEquals(file.getRawListing(), file.toString()); - } - } diff --git a/src/test/java/org/apache/commons/net/imap/AuthenticatingIMAPClientTest.java b/src/test/java/org/apache/commons/net/imap/AuthenticatingIMAPClientTest.java index d45b2b77..517a1b58 100644 --- a/src/test/java/org/apache/commons/net/imap/AuthenticatingIMAPClientTest.java +++ b/src/test/java/org/apache/commons/net/imap/AuthenticatingIMAPClientTest.java @@ -27,12 +27,6 @@ import org.junit.jupiter.params.provider.MethodSource; public class AuthenticatingIMAPClientTest { - @ParameterizedTest(name = "auth method for method {1} is `{0}`") - @MethodSource("authMethods") - public void getAuthName(final String expectedAuthMethodName, final AuthenticatingIMAPClient.AUTH_METHOD authMethod) { - assertEquals(expectedAuthMethodName, authMethod.getAuthName()); - } - private static Stream<Arguments> authMethods() { return Stream.of( Arguments.of("PLAIN", AuthenticatingIMAPClient.AUTH_METHOD.PLAIN), @@ -43,4 +37,10 @@ public class AuthenticatingIMAPClientTest { ); } + @ParameterizedTest(name = "auth method for method {1} is `{0}`") + @MethodSource("authMethods") + public void getAuthName(final String expectedAuthMethodName, final AuthenticatingIMAPClient.AUTH_METHOD authMethod) { + assertEquals(expectedAuthMethodName, authMethod.getAuthName()); + } + } diff --git a/src/test/java/org/apache/commons/net/imap/IMAPCommandTest.java b/src/test/java/org/apache/commons/net/imap/IMAPCommandTest.java index f5a0f381..6d2f2c6f 100644 --- a/src/test/java/org/apache/commons/net/imap/IMAPCommandTest.java +++ b/src/test/java/org/apache/commons/net/imap/IMAPCommandTest.java @@ -27,12 +27,6 @@ import org.junit.jupiter.params.provider.MethodSource; public class IMAPCommandTest { - @ParameterizedTest(name = "Command for IMAPCommand::{1} should be `{0}`") - @MethodSource("imapCommands") - public void getCommand(final String expectedCommand, final IMAPCommand command) { - assertEquals(expectedCommand, IMAPCommand.getCommand(command)); - } - private static Stream<Arguments> imapCommands() { return Stream.of( Arguments.of("CAPABILITY", IMAPCommand.CAPABILITY), @@ -64,4 +58,10 @@ public class IMAPCommandTest { ); } + @ParameterizedTest(name = "Command for IMAPCommand::{1} should be `{0}`") + @MethodSource("imapCommands") + public void getCommand(final String expectedCommand, final IMAPCommand command) { + assertEquals(expectedCommand, IMAPCommand.getCommand(command)); + } + } diff --git a/src/test/java/org/apache/commons/net/imap/IMAPReplyTest.java b/src/test/java/org/apache/commons/net/imap/IMAPReplyTest.java index 5de45514..80b2e0cf 100644 --- a/src/test/java/org/apache/commons/net/imap/IMAPReplyTest.java +++ b/src/test/java/org/apache/commons/net/imap/IMAPReplyTest.java @@ -33,6 +33,45 @@ import org.junit.jupiter.params.provider.MethodSource; public class IMAPReplyTest { + private static Stream<String> invalidLiteralCommands() { + return Stream.of( + "", + "{", + "}", + "{}", + "{foobar}", + "STORE +FLAGS.SILENT \\DELETED {", + "STORE +FLAGS.SILENT \\DELETED }", + "STORE +FLAGS.SILENT \\DELETED {-1}", + "STORE +FLAGS.SILENT \\DELETED {-10}", + "STORE +FLAGS.SILENT \\DELETED {-2147483648}" + ); + } + + private static Stream<Arguments> literalCommands() { + return Stream.of( + Arguments.of(310, "A003 APPEND saved-messages (\\Seen) {310}"), + Arguments.of(6, "A284 SEARCH CHARSET UTF-8 TEXT {6}"), + Arguments.of(7, "FRED FOOBAR {7}"), + Arguments.of(102856, "A044 BLURDYBLOOP {102856}"), + Arguments.of(342, "* 12 FETCH (BODY[HEADER] {342}"), + Arguments.of(0, "X999 LOGIN {0}"), + Arguments.of(Integer.MAX_VALUE, "X999 LOGIN {2147483647}") + ); + } + + @Test + public void getReplyCodeBadLine() throws IOException { + final String badLine = "A044 BAD No such command as \"FOOBAR\""; + assertEquals(IMAPReply.BAD, IMAPReply.getReplyCode(badLine)); + } + + @Test + public void getReplyCodeContinuationLine() throws IOException { + final String continuationLine = "+ Ready for additional command text"; + assertEquals(IMAPReply.CONT, IMAPReply.getReplyCode(continuationLine)); + } + @Test public void getReplyCodeMalformedLine() { final String malformedTaggedLine = "A064 FOO-BAR 0"; @@ -41,9 +80,9 @@ public class IMAPReplyTest { } @Test - public void getReplyCodeContinuationLine() throws IOException { - final String continuationLine = "+ Ready for additional command text"; - assertEquals(IMAPReply.CONT, IMAPReply.getReplyCode(continuationLine)); + public void getReplyCodeNoLine() throws IOException { + final String noLine = "A223 NO COPY failed: disk is full"; + assertEquals(IMAPReply.NO, IMAPReply.getReplyCode(noLine)); } @Test @@ -53,15 +92,15 @@ public class IMAPReplyTest { } @Test - public void getReplyCodeBadLine() throws IOException { - final String badLine = "A044 BAD No such command as \"FOOBAR\""; - assertEquals(IMAPReply.BAD, IMAPReply.getReplyCode(badLine)); + public void getUntaggedReplyCodeBadLine() throws IOException { + final String badLine = "* BAD Empty command line"; + assertEquals(IMAPReply.BAD, IMAPReply.getUntaggedReplyCode(badLine)); } @Test - public void getReplyCodeNoLine() throws IOException { - final String noLine = "A223 NO COPY failed: disk is full"; - assertEquals(IMAPReply.NO, IMAPReply.getReplyCode(noLine)); + public void getUntaggedReplyCodeContinuationLine() throws IOException { + final String continuationLine = "+ Ready for additional command text"; + assertEquals(IMAPReply.CONT, IMAPReply.getUntaggedReplyCode(continuationLine)); } @Test @@ -73,9 +112,9 @@ public class IMAPReplyTest { } @Test - public void getUntaggedReplyCodeContinuationLine() throws IOException { - final String continuationLine = "+ Ready for additional command text"; - assertEquals(IMAPReply.CONT, IMAPReply.getUntaggedReplyCode(continuationLine)); + public void getUntaggedReplyCodeNoLine() throws IOException { + final String noLine = "* NO Disk is 98% full, please delete unnecessary data"; + assertEquals(IMAPReply.NO, IMAPReply.getUntaggedReplyCode(noLine)); } @Test @@ -84,18 +123,6 @@ public class IMAPReplyTest { assertEquals(IMAPReply.OK, IMAPReply.getUntaggedReplyCode(okLine)); } - @Test - public void getUntaggedReplyCodeBadLine() throws IOException { - final String badLine = "* BAD Empty command line"; - assertEquals(IMAPReply.BAD, IMAPReply.getUntaggedReplyCode(badLine)); - } - - @Test - public void getUntaggedReplyCodeNoLine() throws IOException { - final String noLine = "* NO Disk is 98% full, please delete unnecessary data"; - assertEquals(IMAPReply.NO, IMAPReply.getUntaggedReplyCode(noLine)); - } - @Test public void isContinuationReplyCode() { final int replyCode = 3; @@ -156,31 +183,4 @@ public class IMAPReplyTest { assertEquals(-1, IMAPReply.literalCount(replyLine)); } - private static Stream<String> invalidLiteralCommands() { - return Stream.of( - "", - "{", - "}", - "{}", - "{foobar}", - "STORE +FLAGS.SILENT \\DELETED {", - "STORE +FLAGS.SILENT \\DELETED }", - "STORE +FLAGS.SILENT \\DELETED {-1}", - "STORE +FLAGS.SILENT \\DELETED {-10}", - "STORE +FLAGS.SILENT \\DELETED {-2147483648}" - ); - } - - private static Stream<Arguments> literalCommands() { - return Stream.of( - Arguments.of(310, "A003 APPEND saved-messages (\\Seen) {310}"), - Arguments.of(6, "A284 SEARCH CHARSET UTF-8 TEXT {6}"), - Arguments.of(7, "FRED FOOBAR {7}"), - Arguments.of(102856, "A044 BLURDYBLOOP {102856}"), - Arguments.of(342, "* 12 FETCH (BODY[HEADER] {342}"), - Arguments.of(0, "X999 LOGIN {0}"), - Arguments.of(Integer.MAX_VALUE, "X999 LOGIN {2147483647}") - ); - } - } diff --git a/src/test/java/org/apache/commons/net/imap/IMAPTest.java b/src/test/java/org/apache/commons/net/imap/IMAPTest.java index 81167760..f335e97c 100644 --- a/src/test/java/org/apache/commons/net/imap/IMAPTest.java +++ b/src/test/java/org/apache/commons/net/imap/IMAPTest.java @@ -30,39 +30,16 @@ import org.junit.jupiter.params.provider.MethodSource; public class IMAPTest { - @Test - public void trueChunkListener() { - assertTrue(IMAP.TRUE_CHUNK_LISTENER.chunkReceived(new IMAP())); - } - - @Test - public void quoteMailboxNameNullInput() { - assertNull(IMAP.quoteMailboxName(null)); - } - - @Test - public void quoteMailboxNoQuotingIfNoSpacePresent() { - final String stringToQuote = "Foobar\""; - assertEquals(stringToQuote, IMAP.quoteMailboxName(stringToQuote)); - } - - @ParameterizedTest(name = "String `{0}` should be quoted") - @MethodSource("mailboxNamesToBeQuoted") - public void quoteMailboxName(final String input) { - final String quotedMailboxName = IMAP.quoteMailboxName(input); - assertAll( - () -> assertTrue(quotedMailboxName.startsWith("\""), "quoted string should start with quotation mark"), - () -> assertTrue(quotedMailboxName.endsWith("\""), "quoted string should end with quotation mark") - ); - } - - @Test - public void constructDefaultIMAP() { - final IMAP imap = new IMAP(); - assertAll( - () -> assertEquals(IMAP.DEFAULT_PORT, imap.getDefaultPort()), - () -> assertEquals(IMAP.IMAPState.DISCONNECTED_STATE, imap.getState()), - () -> assertEquals(0, imap.getReplyStrings().length) + private static Stream<String> mailboxNamesToBeQuoted() { + return Stream.of( + "", + " ", + "\"", + "\"\"", + "\\/ ", + "Hello\", ", + "\" World!", + "Hello\",\" World!" ); } @@ -91,17 +68,40 @@ public class IMAPTest { assertTrue(matched, "Expected to see the original value again"); } - private static Stream<String> mailboxNamesToBeQuoted() { - return Stream.of( - "", - " ", - "\"", - "\"\"", - "\\/ ", - "Hello\", ", - "\" World!", - "Hello\",\" World!" + @Test + public void constructDefaultIMAP() { + final IMAP imap = new IMAP(); + assertAll( + () -> assertEquals(IMAP.DEFAULT_PORT, imap.getDefaultPort()), + () -> assertEquals(IMAP.IMAPState.DISCONNECTED_STATE, imap.getState()), + () -> assertEquals(0, imap.getReplyStrings().length) ); } + @ParameterizedTest(name = "String `{0}` should be quoted") + @MethodSource("mailboxNamesToBeQuoted") + public void quoteMailboxName(final String input) { + final String quotedMailboxName = IMAP.quoteMailboxName(input); + assertAll( + () -> assertTrue(quotedMailboxName.startsWith("\""), "quoted string should start with quotation mark"), + () -> assertTrue(quotedMailboxName.endsWith("\""), "quoted string should end with quotation mark") + ); + } + + @Test + public void quoteMailboxNameNullInput() { + assertNull(IMAP.quoteMailboxName(null)); + } + + @Test + public void quoteMailboxNoQuotingIfNoSpacePresent() { + final String stringToQuote = "Foobar\""; + assertEquals(stringToQuote, IMAP.quoteMailboxName(stringToQuote)); + } + + @Test + public void trueChunkListener() { + assertTrue(IMAP.TRUE_CHUNK_LISTENER.chunkReceived(new IMAP())); + } + } diff --git a/src/test/java/org/apache/commons/net/util/Base64Test.java b/src/test/java/org/apache/commons/net/util/Base64Test.java index cd138ae6..a1bc455a 100644 --- a/src/test/java/org/apache/commons/net/util/Base64Test.java +++ b/src/test/java/org/apache/commons/net/util/Base64Test.java @@ -94,12 +94,6 @@ public class Base64Test { assertEquals("foobar", new String(decoded, StandardCharsets.UTF_8)); } - @Test - public void testDecodeByteArrayNull() { - final byte[] decoded = new Base64().decode((byte[]) null); - assertNull(decoded); - } - @Test public void testDecodeByteArrayEmpty() { final byte[] base64Data = new byte[] {}; @@ -107,12 +101,24 @@ public class Base64Test { assertArrayEquals(base64Data, decoded); } + @Test + public void testDecodeByteArrayNull() { + final byte[] decoded = new Base64().decode((byte[]) null); + assertNull(decoded); + } + @Test @Ignore public void testDecodeInteger() { fail("Not yet implemented"); } + @Test + public void testDecodeNullString() { + final Base64 base64 = new Base64(); + assertThrows(NullPointerException.class, () -> base64.decode((String) null)); + } + @Test @Ignore public void testDecodeObject() { @@ -126,12 +132,6 @@ public class Base64Test { assertEquals("Hello World!", new String(decoded)); } - @Test - public void testDecodeNullString() { - final Base64 base64 = new Base64(); - assertThrows(NullPointerException.class, () -> base64.decode((String) null)); - } - @Test public void testEncodeBase64ByteArray() { final byte[] binaryData = null;