From 51b2e12bfb331c7450a926bf465af486e69c72b2 Mon Sep 17 00:00:00 2001 From: Brian Long Date: Fri, 26 Feb 2021 22:13:48 -0500 Subject: [PATCH 1/5] changed repo hostname; added javadoc --- pom.xml | 17 ++- .../inteligr8/junit4/AssertCollection.java | 44 +++++++ .../com/inteligr8/junit4/AssertRegex.java | 111 ++++++++++++++++++ 3 files changed, 171 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a37172f..e6f88b9 100644 --- a/pom.xml +++ b/pom.xml @@ -9,6 +9,21 @@ Reusable JUnit4 Extensions + + https://bitbucket.org/inteligr8/junit4-ext + + + Inteligr8 + https://www.inteligr8.com + + + + Brian Long + brian@inteligr8.com + https://twitter.com/brianmlong + + + 1.7 1.7 @@ -26,7 +41,7 @@ inteligr8-releases Inteligr8 Releases - http://repos.yateslong.us/nexus/repository/inteligr8-public + http://repos.inteligr8.com/nexus/repository/inteligr8-public default diff --git a/src/main/java/com/inteligr8/junit4/AssertCollection.java b/src/main/java/com/inteligr8/junit4/AssertCollection.java index d35fb34..8ffbd40 100644 --- a/src/main/java/com/inteligr8/junit4/AssertCollection.java +++ b/src/main/java/com/inteligr8/junit4/AssertCollection.java @@ -4,29 +4,73 @@ import java.util.Collection; import org.junit.Assert; +/** + * This class implements JUnit4 assertion methods focused on collections. + * + * @author brian@inteligr8.com + */ public class AssertCollection { + /** + * This method evaluates the size of a collection. + * + * @param expectedCount The expected size of the collection + * @param actualCollection The collection to evaluate + */ public static void assertSize(int expectedCount, Collection actualCollection) { assertSize(null, expectedCount, actualCollection); } + /** + * This method evaluates the size of a collection. + * + * @param message A message to record on failure + * @param expectedCount The expected size of the collection + * @param actualCollection The collection to evaluate + */ public static void assertSize(String message, int expectedCount, Collection actualCollection) { if (expectedCount == 0) Assert.assertTrue(message, actualCollection == null || actualCollection.isEmpty()); else Assert.assertTrue(message, actualCollection != null && actualCollection.size() == expectedCount); } + /** + * This method evaluates the contents of a collection + * + * @param expectedElement A expected element in the collection + * @param actualCollection A collection to search/inspect + */ public static void assertContains(T expectedElement, Collection actualCollection) { assertContains(null, expectedElement, actualCollection); } + /** + * This method evaluates the contents of a collection + * + * @param expectedElements A subset of the expected elements in the collection + * @param actualCollection A collection to search/inspect + */ public static void assertContains(Collection expectedElements, Collection actualCollection) { assertContains(null, expectedElements, actualCollection); } + /** + * This method evaluates the contents of a collection + * + * @param message A message to record on failure + * @param expectedElement A expected element in the collection + * @param actualCollection A collection to search/inspect + */ public static void assertContains(String message, T expectedElement, Collection actualCollection) { Assert.assertTrue(message, actualCollection != null && actualCollection.contains(expectedElement)); } + /** + * This method evaluates the contents of a collection + * + * @param message A message to record on failure + * @param expectedElements A subset of the expected elements in the collection + * @param actualCollection A collection to search/inspect + */ public static void assertContains(String message, Collection expectedElements, Collection actualCollection) { Assert.assertTrue(message, actualCollection != null && actualCollection.containsAll(expectedElements)); } diff --git a/src/main/java/com/inteligr8/junit4/AssertRegex.java b/src/main/java/com/inteligr8/junit4/AssertRegex.java index 2e86f54..2b2c9e5 100644 --- a/src/main/java/com/inteligr8/junit4/AssertRegex.java +++ b/src/main/java/com/inteligr8/junit4/AssertRegex.java @@ -5,38 +5,111 @@ import java.util.regex.Pattern; import org.junit.Assert; +/** + * This class implements JUnit4 assertion methods focused on regular expression matching. + * + * @author brian@inteligr8.com + */ public class AssertRegex { + /** + * This method evaluates the format of the specified value using the + * specified regular expression. + * + * @param expectedRegex A regular expression + * @param actual A text value to evaluate + * @see AssertRegex#assertNotMatches(String, String) + */ public static void assertMatches(String expectedRegex, String actual) { assertMatches(null, expectedRegex, actual); } + /** + * This method evaluates the format of the specified value using the + * specified regular expression. + * + * @param message A message to record on failure + * @param expectedRegex A regular expression + * @param actual A text value to evaluate + * @see AssertRegex#assertNotMatches(String, String, String) + */ public static void assertMatches(String message, String expectedRegex, String actual) { Pattern pattern = Pattern.compile(expectedRegex); assertMatches(message, pattern, actual); } + /** + * This method evaluates the format of the specified value using the + * specified regular expression. + * + * @param expectedRegex A regular expression + * @param actual A text value to evaluate + * @see AssertRegex#assertNotMatches(Pattern, String) + */ public static void assertMatches(Pattern expected, String actual) { assertMatches(null, expected, actual); } + /** + * This method evaluates the format of the specified value using the + * specified regular expression. + * + * @param message A message to record on failure + * @param expectedRegex A regular expression + * @param actual A text value to evaluate + * @see AssertRegex#assertNotMatches(String, Pattern, String) + */ public static void assertMatches(String message, Pattern expected, String actual) { assertMatches(message, false, expected, actual); } + /** + * This method negates the evaluation of the format of the specified value + * using the specified regular expression. + * + * @param expectedRegex A regular expression + * @param actual A text value to evaluate + * @see AssertRegex#assertMatches(String, String) + */ public static void assertNotMatches(String expectedRegex, String actual) { assertNotMatches(null, expectedRegex, actual); } + /** + * This method negates the evaluation of the format of the specified value + * using the specified regular expression. + * + * @param message A message to record on failure + * @param expectedRegex A regular expression + * @param actual A text value to evaluate + * @see AssertRegex#assertMatches(String, String, String) + */ public static void assertNotMatches(String message, String expectedRegex, String actual) { Pattern pattern = Pattern.compile(expectedRegex); assertNotMatches(message, pattern, actual); } + /** + * This method negates the evaluation of the format of the specified value + * using the specified regular expression. + * + * @param expected A regular expression + * @param actual A text value to evaluate + * @see AssertRegex#assertMatches(Pattern, String) + */ public static void assertNotMatches(Pattern expected, String actual) { assertNotMatches(null, expected, actual); } + /** + * This method negates the evaluation of the format of the specified value + * using the specified regular expression. + * + * @param message A message to record on failure + * @param expected A regular expression + * @param actual A text value to evaluate + * @see AssertRegex#assertMatches(String, Pattern, String) + */ public static void assertNotMatches(String message, Pattern expected, String actual) { assertMatches(message, true, expected, actual); } @@ -52,19 +125,57 @@ public class AssertRegex { + /** + * This method counts the matches of the specified value against the + * specified regular expression. + * + * @param expectedRegex A regular expression + * @param expectedCount The count of an expected regex match + * @param actual A text value to evaluate + * @see AssertRegex#assertMatches(String, String) + */ public static void assertFind(String expectedRegex, int expectedCount, String actual) { assertFind(null, expectedRegex, expectedCount, actual); } + /** + * This method counts the matches of the specified value against the + * specified regular expression. + * + * @param message A message to record on failure + * @param expectedRegex A regular expression + * @param expectedCount The count of an expected regex match + * @param actual A text value to evaluate + * @see AssertRegex#assertMatches(String, String, String) + */ public static void assertFind(String message, String expectedRegex, int expectedCount, String actual) { Pattern pattern = Pattern.compile(expectedRegex); assertFind(message, pattern, expectedCount, actual); } + /** + * This method counts the matches of the specified value against the + * specified regular expression. + * + * @param expected A regular expression + * @param expectedCount The count of an expected regex match + * @param actual A text value to evaluate + * @see AssertRegex#assertMatches(Pattern, String) + */ public static void assertFind(Pattern expected, int expectedCount, String actual) { assertFind(null, expected, expectedCount, actual); } + /** + * This method counts the matches of the specified value against the + * specified regular expression. + * + * @param message A message to record on failure + * @param expected A regular expression + * @param expectedCount The count of an expected regex match + * @param actual A text value to evaluate + * @see AssertRegex#assertMatches(Pattern, String) + */ public static void assertFind(String message, Pattern expected, int expectedCount, String actual) { Matcher matcher = expected.matcher(actual); int count = 0; From b50dce34e2caf88a6e879b13332d8fb071f08d95 Mon Sep 17 00:00:00 2001 From: Brian Long Date: Fri, 26 Feb 2021 22:18:01 -0500 Subject: [PATCH 2/5] added javadoc packaging; minor doc fix --- pom.xml | 19 +++++++++++++++++++ .../com/inteligr8/junit4/AssertRegex.java | 4 ++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e6f88b9..8a29df7 100644 --- a/pom.xml +++ b/pom.xml @@ -36,6 +36,25 @@ 4.13 + + + + + maven-javadoc-plugin + + + javadoc + package + jar + + true + public + + + + + + diff --git a/src/main/java/com/inteligr8/junit4/AssertRegex.java b/src/main/java/com/inteligr8/junit4/AssertRegex.java index 2b2c9e5..8f0d5ff 100644 --- a/src/main/java/com/inteligr8/junit4/AssertRegex.java +++ b/src/main/java/com/inteligr8/junit4/AssertRegex.java @@ -42,7 +42,7 @@ public class AssertRegex { * This method evaluates the format of the specified value using the * specified regular expression. * - * @param expectedRegex A regular expression + * @param expected A regular expression * @param actual A text value to evaluate * @see AssertRegex#assertNotMatches(Pattern, String) */ @@ -55,7 +55,7 @@ public class AssertRegex { * specified regular expression. * * @param message A message to record on failure - * @param expectedRegex A regular expression + * @param expected A regular expression * @param actual A text value to evaluate * @see AssertRegex#assertNotMatches(String, Pattern, String) */ From fc713c6b59ba98bc147caa4b57e59d581e1a2852 Mon Sep 17 00:00:00 2001 From: Brian Long Date: Sat, 27 Feb 2021 08:46:45 -0500 Subject: [PATCH 3/5] readability update to .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a436cfa..67af4db 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,9 @@ # Maven pom.xml.versionsBackup +target # Eclipse .project .classpath .settings -target From 059cb9e4bd15590fca8f312200c66aa50c23ca97 Mon Sep 17 00:00:00 2001 From: Brian Long Date: Sat, 27 Feb 2021 08:48:15 -0500 Subject: [PATCH 4/5] parameterized junit version --- pom.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8a29df7..0bb18b4 100644 --- a/pom.xml +++ b/pom.xml @@ -27,18 +27,20 @@ 1.7 1.7 + 4.13 junit junit - 4.13 + ${junit.version} + maven-javadoc-plugin From 15f9d56f0f15c9a4ff8eca50250fd583b6371fa3 Mon Sep 17 00:00:00 2001 From: Brian Long Date: Sat, 27 Feb 2021 09:03:25 -0500 Subject: [PATCH 5/5] fixed build warnings --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0bb18b4..9926698 100644 --- a/pom.xml +++ b/pom.xml @@ -25,6 +25,7 @@ + utf-8 1.7 1.7 4.13 @@ -43,13 +44,13 @@ maven-javadoc-plugin + 3.2.0 javadoc package jar - true public