Merge branch 'develop' into stable

This commit is contained in:
Brian Long 2021-02-27 09:00:10 -05:00
commit 4941f47f5a
4 changed files with 189 additions and 3 deletions

2
.gitignore vendored
View File

@ -1,9 +1,9 @@
# Maven # Maven
pom.xml.versionsBackup pom.xml.versionsBackup
target
# Eclipse # Eclipse
.project .project
.classpath .classpath
.settings .settings
target

35
pom.xml
View File

@ -9,14 +9,29 @@
<name>Reusable JUnit5 Extensions</name> <name>Reusable JUnit5 Extensions</name>
<scm>
<url>https://bitbucket.org/inteligr8/junit5-ext</url>
</scm>
<organization>
<name>Inteligr8</name>
<url>https://www.inteligr8.com</url>
</organization>
<developers>
<developer>
<name>Brian Long</name>
<email>brian@inteligr8.com</email>
<url>https://twitter.com/brianmlong</url>
</developer>
</developers>
<properties> <properties>
<project.build.sourceEncoding>utf-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>
<junit.version>5.7.0</junit.version> <junit.version>5.7.0</junit.version>
<junit-platform-provider.version>[1.3, 1.4)</junit-platform-provider.version> <junit-platform-provider.version>[1.3, 1.4)</junit-platform-provider.version>
</properties> </properties>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.junit.jupiter</groupId> <groupId>org.junit.jupiter</groupId>
@ -27,6 +42,7 @@
<build> <build>
<plugins> <plugins>
<!-- This plugin enables the JUnit5 framework -->
<plugin> <plugin>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version> <version>2.22.2</version>
@ -43,6 +59,21 @@
</dependency> </dependency>
</dependencies> </dependencies>
</plugin> </plugin>
<!-- This plugin enables the generation of a javadoc JAR -->
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>javadoc</id>
<phase>package</phase>
<goals><goal>jar</goal></goals>
<configuration>
<show>public</show>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>
@ -50,7 +81,7 @@
<repository> <repository>
<id>inteligr8-releases</id> <id>inteligr8-releases</id>
<name>Inteligr8 Releases</name> <name>Inteligr8 Releases</name>
<url>http://repos.yateslong.us/nexus/repository/inteligr8-public</url> <url>http://repos.inteligr8.com/nexus/repository/inteligr8-public</url>
<layout>default</layout> <layout>default</layout>
</repository> </repository>
</distributionManagement> </distributionManagement>

View File

@ -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);
} }

View File

@ -5,38 +5,111 @@ 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(Pattern, String, String)
*/
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(Pattern, String, 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 +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) { 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;