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 5c871fea Use assertThrows 5c871fea is described below commit 5c871feadc81b1a3acfedb6c142b3d2fb8457b3f Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Wed Aug 23 07:22:03 2023 -0400 Use assertThrows --- .../commons/net/ftp/FTPClientConfigTest.java | 21 ++------- .../net/ftp/parser/FTPTimestampParserImplTest.java | 53 ++++------------------ .../org/apache/commons/net/util/Base64Test.java | 14 +----- 3 files changed, 13 insertions(+), 75 deletions(-) diff --git a/src/test/java/org/apache/commons/net/ftp/FTPClientConfigTest.java b/src/test/java/org/apache/commons/net/ftp/FTPClientConfigTest.java index fbba6b03..b5318190 100644 --- a/src/test/java/org/apache/commons/net/ftp/FTPClientConfigTest.java +++ b/src/test/java/org/apache/commons/net/ftp/FTPClientConfigTest.java @@ -71,24 +71,9 @@ public class FTPClientConfigTest extends TestCase { public void testGetDateFormatSymbols() { - try { - FTPClientConfig.getDateFormatSymbols(badDelim); - fail("bad delimiter"); - } catch (final IllegalArgumentException e) { - // should have failed - } - try { - FTPClientConfig.getDateFormatSymbols(tooLong); - fail("more than 12 months"); - } catch (final IllegalArgumentException e) { - // should have failed - } - try { - FTPClientConfig.getDateFormatSymbols(tooShort); - fail("fewer than 12 months"); - } catch (final IllegalArgumentException e) { - // should have failed - } + assertThrows(IllegalArgumentException.class, () -> FTPClientConfig.getDateFormatSymbols(badDelim), "bad delimiter"); + assertThrows(IllegalArgumentException.class, () -> FTPClientConfig.getDateFormatSymbols(tooLong), "more than 12 months"); + assertThrows(IllegalArgumentException.class, () -> FTPClientConfig.getDateFormatSymbols(tooShort), "fewer than 12 months"); DateFormatSymbols dfs2 = null; try { dfs2 = FTPClientConfig.getDateFormatSymbols(fakeLang); diff --git a/src/test/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java b/src/test/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java index 37524ab4..541474e4 100644 --- a/src/test/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java +++ b/src/test/java/org/apache/commons/net/ftp/parser/FTPTimestampParserImplTest.java @@ -202,67 +202,30 @@ public class FTPTimestampParserImplTest extends TestCase { checkShortParse("2008-1-1", now, target, true); } - public void testParser() { + public void testParser() throws ParseException { // This test requires an English Locale final Locale locale = Locale.getDefault(); try { Locale.setDefault(Locale.ENGLISH); final FTPTimestampParserImpl parser = new FTPTimestampParserImpl(); - try { - parser.parseTimestamp("feb 22 2002"); - } catch (final ParseException e) { - fail("failed.to.parse.default"); - } - try { - final Calendar c = parser.parseTimestamp("f\u00e9v 22 2002"); - fail("should.have.failed.to.parse.default, but was: " + c.getTime().toString()); - } catch (final ParseException e) { - // this is the success case - } + parser.parseTimestamp("feb 22 2002"); + assertThrows(ParseException.class, () -> parser.parseTimestamp("f\u00e9v 22 2002")); final FTPClientConfig config = new FTPClientConfig(); config.setDefaultDateFormatStr("d MMM yyyy"); config.setRecentDateFormatStr("d MMM HH:mm"); config.setServerLanguageCode("fr"); parser.configure(config); - try { - parser.parseTimestamp("d\u00e9c 22 2002"); - fail("incorrect.field.order"); - } catch (final ParseException e) { - // this is the success case - } + assertThrows(ParseException.class, () -> parser.parseTimestamp("d\u00e9c 22 2002"), "incorrect.field.order"); try { parser.parseTimestamp("22 d\u00e9c 2002"); } catch (final ParseException e) { fail("failed.to.parse.french"); } - - try { - parser.parseTimestamp("22 dec 2002"); - fail("incorrect.language"); - } catch (final ParseException e) { - // this is the success case - } - try { - parser.parseTimestamp("29 f\u00e9v 2002"); - fail("nonexistent.date"); - } catch (final ParseException e) { - // this is the success case - } - - try { - parser.parseTimestamp("22 ao\u00fb 30:02"); - fail("bad.hour"); - } catch (final ParseException e) { - // this is the success case - } - - try { - parser.parseTimestamp("22 ao\u00fb 20:74"); - fail("bad.minute"); - } catch (final ParseException e) { - // this is the success case - } + assertThrows(ParseException.class, () -> parser.parseTimestamp("22 dec 2002"), "incorrect.language"); + assertThrows(ParseException.class, () -> parser.parseTimestamp("29 f\u00e9v 2002"), "nonexistent.date"); + assertThrows(ParseException.class, () -> parser.parseTimestamp("22 ao\u00fb 30:02"), "bad.hour"); + assertThrows(ParseException.class, () -> parser.parseTimestamp("22 ao\u00fb 20:74"), "bad.minute"); try { parser.parseTimestamp("28 ao\u00fb 20:02"); } catch (final ParseException e) { 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 984af904..576fe00f 100644 --- a/src/test/java/org/apache/commons/net/util/Base64Test.java +++ b/src/test/java/org/apache/commons/net/util/Base64Test.java @@ -157,24 +157,14 @@ public class Base64Test { encoded = Base64.encodeBase64(binaryData, false, false); assertNotNull(encoded); assertEquals(4, encoded.length); - try { - Base64.encodeBase64(binaryData, false, false, 3); - fail("Expected IllegalArgumentException"); - } catch (final IllegalArgumentException expected) { - // expected - } + assertThrows(IllegalArgumentException.class, () -> Base64.encodeBase64(binaryData, false, false, 3)); encoded = Base64.encodeBase64(binaryData, false, false, 4); // NET-483 assertNotNull(encoded); assertEquals(4, encoded.length); encoded = Base64.encodeBase64(binaryData, true, false); assertNotNull(encoded); assertEquals(6, encoded.length); // always adds trailer - try { - Base64.encodeBase64(binaryData, true, false, 5); - fail("Expected IllegalArgumentException"); - } catch (final IllegalArgumentException expected) { - // expected - } + assertThrows(IllegalArgumentException.class, () -> Base64.encodeBase64(binaryData, true, false, 5)); encoded = Base64.encodeBase64(binaryData, true, false, 6); assertNotNull(encoded); assertEquals(6, encoded.length);