added javadoc comments
This commit is contained in:
parent
68e24d6361
commit
8c7ba89027
@ -4,29 +4,73 @@ import java.util.Collection;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class implements JUnit4 assertion methods focused on collections.
|
||||||
|
*
|
||||||
|
* @author brian@inteligr8.com
|
||||||
|
*/
|
||||||
public class AssertCollection {
|
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) {
|
public static void assertSize(int expectedCount, Collection<?> actualCollection) {
|
||||||
assertSize(expectedCount, actualCollection, null);
|
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) {
|
public static void assertSize(int expectedCount, Collection<?> actualCollection, String message) {
|
||||||
if (expectedCount == 0) Assertions.assertTrue(actualCollection == null || actualCollection.isEmpty(), message);
|
if (expectedCount == 0) Assertions.assertTrue(actualCollection == null || actualCollection.isEmpty(), message);
|
||||||
else Assertions.assertTrue(actualCollection != null && actualCollection.size() == expectedCount, 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 <T> void assertContains(T expectedElement, Collection<T> actualCollection) {
|
public static <T> void assertContains(T expectedElement, Collection<T> actualCollection) {
|
||||||
assertContains(expectedElement, actualCollection, null);
|
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 <T> void assertContains(Collection<T> expectedElements, Collection<T> actualCollection) {
|
public static <T> void assertContains(Collection<T> expectedElements, Collection<T> actualCollection) {
|
||||||
assertContains(expectedElements, actualCollection, null);
|
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 <T> void assertContains(T expectedElement, Collection<T> actualCollection, String message) {
|
public static <T> void assertContains(T expectedElement, Collection<T> actualCollection, String message) {
|
||||||
Assertions.assertTrue(actualCollection != null && actualCollection.contains(expectedElement), 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 <T> void assertContains(Collection<T> expectedElements, Collection<T> actualCollection, String message) {
|
public static <T> void assertContains(Collection<T> expectedElements, Collection<T> actualCollection, String message) {
|
||||||
Assertions.assertTrue(actualCollection != null && actualCollection.containsAll(expectedElements), message);
|
Assertions.assertTrue(actualCollection != null && actualCollection.containsAll(expectedElements), message);
|
||||||
}
|
}
|
||||||
|
@ -5,38 +5,112 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class implements JUnit4 assertion methods focused on regular expression matching.
|
||||||
|
*
|
||||||
|
* @author brian@inteligr8.com
|
||||||
|
*/
|
||||||
public class AssertRegex {
|
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) {
|
public static void assertMatches(String expectedRegex, String actual) {
|
||||||
assertMatches(expectedRegex, actual, null);
|
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) {
|
public static void assertMatches(String expectedRegex, String actual, String message) {
|
||||||
Pattern pattern = Pattern.compile(expectedRegex);
|
Pattern pattern = Pattern.compile(expectedRegex);
|
||||||
assertMatches(pattern, actual, message);
|
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) {
|
public static void assertMatches(Pattern expected, String actual) {
|
||||||
assertMatches(expected, actual, null);
|
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) {
|
public static void assertMatches(Pattern expected, String actual, String message) {
|
||||||
assertMatches(false, expected, actual, 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) {
|
public static void assertNotMatches(String expectedRegex, String actual) {
|
||||||
assertNotMatches(expectedRegex, actual, null);
|
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) {
|
public static void assertNotMatches(String expectedRegex, String actual, String message) {
|
||||||
Pattern pattern = Pattern.compile(expectedRegex);
|
Pattern pattern = Pattern.compile(expectedRegex);
|
||||||
assertNotMatches(pattern, actual, message);
|
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) {
|
public static void assertNotMatches(Pattern expected, String actual) {
|
||||||
assertNotMatches(expected, actual, null);
|
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) {
|
public static void assertNotMatches(Pattern expected, String actual, String message) {
|
||||||
assertMatches(true, expected, actual, 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) {
|
public static void assertFind(String expectedRegex, int expectedCount, String actual) {
|
||||||
assertFind(expectedRegex, expectedCount, actual, null);
|
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) {
|
public static void assertFind(String expectedRegex, int expectedCount, String actual, String message) {
|
||||||
Pattern pattern = Pattern.compile(expectedRegex);
|
Pattern pattern = Pattern.compile(expectedRegex);
|
||||||
assertFind(pattern, expectedCount, actual, message);
|
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) {
|
public static void assertFind(Pattern expected, int expectedCount, String actual) {
|
||||||
assertFind(expected, expectedCount, actual, null);
|
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) {
|
public static void assertFind(Pattern expected, int expectedCount, String actual, String message) {
|
||||||
Matcher matcher = expected.matcher(actual);
|
Matcher matcher = expected.matcher(actual);
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user