From 8c7ba890275cda15162519c58aa4bb5436745cce Mon Sep 17 00:00:00 2001 From: Brian Long Date: Sat, 27 Feb 2021 08:49:41 -0500 Subject: [PATCH] added javadoc comments --- .../inteligr8/junit5/AssertCollection.java | 44 +++++++ .../com/inteligr8/junit5/AssertRegex.java | 112 ++++++++++++++++++ 2 files changed, 156 insertions(+) diff --git a/src/main/java/com/inteligr8/junit5/AssertCollection.java b/src/main/java/com/inteligr8/junit5/AssertCollection.java index 7834d83..ad17b00 100644 --- a/src/main/java/com/inteligr8/junit5/AssertCollection.java +++ b/src/main/java/com/inteligr8/junit5/AssertCollection.java @@ -4,29 +4,73 @@ import java.util.Collection; import org.junit.jupiter.api.Assertions; +/** + * 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(expectedCount, actualCollection, null); } + /** + * 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(int expectedCount, Collection actualCollection, String message) { if (expectedCount == 0) Assertions.assertTrue(actualCollection == null || actualCollection.isEmpty(), message); else Assertions.assertTrue(actualCollection != null && actualCollection.size() == expectedCount, message); } + /** + * 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(expectedElement, actualCollection, null); } + /** + * 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(expectedElements, actualCollection, null); } + /** + * 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(T expectedElement, Collection actualCollection, String message) { Assertions.assertTrue(actualCollection != null && actualCollection.contains(expectedElement), message); } + /** + * 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(Collection expectedElements, Collection actualCollection, String message) { Assertions.assertTrue(actualCollection != null && actualCollection.containsAll(expectedElements), message); } diff --git a/src/main/java/com/inteligr8/junit5/AssertRegex.java b/src/main/java/com/inteligr8/junit5/AssertRegex.java index 53e019d..285f3b5 100644 --- a/src/main/java/com/inteligr8/junit5/AssertRegex.java +++ b/src/main/java/com/inteligr8/junit5/AssertRegex.java @@ -5,38 +5,112 @@ import java.util.regex.Pattern; import org.junit.jupiter.api.Assertions; +/** + * 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(expectedRegex, actual, null); } + /** + * 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 expectedRegex, String actual, String message) { Pattern pattern = Pattern.compile(expectedRegex); assertMatches(pattern, actual, message); } + /** + * This method evaluates 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#assertNotMatches(Pattern, String) + */ public static void assertMatches(Pattern expected, String actual) { assertMatches(expected, actual, null); } + /** + * This method evaluates 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#assertNotMatches(String, Pattern, String) + */ + public st public static void assertMatches(Pattern expected, String actual, String message) { assertMatches(false, expected, actual, message); } + /** + * 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(expectedRegex, actual, null); } + /** + * 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 expectedRegex, String actual, String message) { Pattern pattern = Pattern.compile(expectedRegex); assertNotMatches(pattern, actual, message); } + /** + * 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(expected, actual, null); } + /** + * 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(Pattern expected, String actual, String message) { assertMatches(true, expected, actual, message); } @@ -52,19 +126,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(expectedRegex, expectedCount, actual, null); } + /** + * 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 expectedRegex, int expectedCount, String actual, String message) { Pattern pattern = Pattern.compile(expectedRegex); assertFind(pattern, expectedCount, actual, message); } + /** + * 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(expected, expectedCount, actual, null); } + /** + * 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(Pattern expected, int expectedCount, String actual, String message) { Matcher matcher = expected.matcher(actual); int count = 0;