Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
cec7f9e76c | |||
7859ff0508 | |||
15f9d56f0f | |||
059cb9e4bd | |||
fc713c6b59 | |||
b50dce34e2 | |||
51b2e12bfb | |||
0660594a18 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,9 +1,9 @@
|
|||||||
# Maven
|
# Maven
|
||||||
pom.xml.versionsBackup
|
pom.xml.versionsBackup
|
||||||
|
target
|
||||||
|
|
||||||
# Eclipse
|
# Eclipse
|
||||||
.project
|
.project
|
||||||
.classpath
|
.classpath
|
||||||
.settings
|
.settings
|
||||||
target
|
|
||||||
|
|
||||||
|
43
pom.xml
43
pom.xml
@ -4,29 +4,66 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.inteligr8</groupId>
|
<groupId>com.inteligr8</groupId>
|
||||||
<artifactId>junit4-ext</artifactId>
|
<artifactId>junit4-ext</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0.1</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>Reusable JUnit4 Extensions</name>
|
<name>Reusable JUnit4 Extensions</name>
|
||||||
|
|
||||||
|
<scm>
|
||||||
|
<url>https://bitbucket.org/inteligr8/junit4-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.7</maven.compiler.source>
|
<maven.compiler.source>1.7</maven.compiler.source>
|
||||||
<maven.compiler.target>1.7</maven.compiler.target>
|
<maven.compiler.target>1.7</maven.compiler.target>
|
||||||
|
<junit.version>4.13</junit.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.13</version>
|
<version>${junit.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<!-- 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>
|
||||||
|
</build>
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
<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>
|
||||||
|
@ -4,29 +4,73 @@ import java.util.Collection;
|
|||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(null, expectedCount, 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) {
|
public static void assertSize(String message, int expectedCount, Collection<?> actualCollection) {
|
||||||
if (expectedCount == 0) Assert.assertTrue(message, actualCollection == null || actualCollection.isEmpty());
|
if (expectedCount == 0) Assert.assertTrue(message, actualCollection == null || actualCollection.isEmpty());
|
||||||
else Assert.assertTrue(message, actualCollection != null && actualCollection.size() == expectedCount);
|
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 <T> void assertContains(T expectedElement, Collection<T> actualCollection) {
|
public static <T> void assertContains(T expectedElement, Collection<T> actualCollection) {
|
||||||
assertContains(null, expectedElement, 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 <T> void assertContains(Collection<T> expectedElements, Collection<T> actualCollection) {
|
public static <T> void assertContains(Collection<T> expectedElements, Collection<T> actualCollection) {
|
||||||
assertContains(null, expectedElements, 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 <T> void assertContains(String message, T expectedElement, Collection<T> actualCollection) {
|
public static <T> void assertContains(String message, T expectedElement, Collection<T> actualCollection) {
|
||||||
Assert.assertTrue(message, actualCollection != null && actualCollection.contains(expectedElement));
|
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 <T> void assertContains(String message, Collection<T> expectedElements, Collection<T> actualCollection) {
|
public static <T> void assertContains(String message, Collection<T> expectedElements, Collection<T> actualCollection) {
|
||||||
Assert.assertTrue(message, actualCollection != null && actualCollection.containsAll(expectedElements));
|
Assert.assertTrue(message, actualCollection != null && actualCollection.containsAll(expectedElements));
|
||||||
}
|
}
|
||||||
|
@ -5,38 +5,111 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(null, expectedRegex, 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) {
|
public static void assertMatches(String message, String expectedRegex, String actual) {
|
||||||
Pattern pattern = Pattern.compile(expectedRegex);
|
Pattern pattern = Pattern.compile(expectedRegex);
|
||||||
assertMatches(message, pattern, actual);
|
assertMatches(message, pattern, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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(null, expected, 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 expected 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) {
|
public static void assertMatches(String message, Pattern expected, String actual) {
|
||||||
assertMatches(message, false, expected, 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) {
|
public static void assertNotMatches(String expectedRegex, String actual) {
|
||||||
assertNotMatches(null, expectedRegex, 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) {
|
public static void assertNotMatches(String message, String expectedRegex, String actual) {
|
||||||
Pattern pattern = Pattern.compile(expectedRegex);
|
Pattern pattern = Pattern.compile(expectedRegex);
|
||||||
assertNotMatches(message, pattern, actual);
|
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) {
|
public static void assertNotMatches(Pattern expected, String actual) {
|
||||||
assertNotMatches(null, expected, 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) {
|
public static void assertNotMatches(String message, Pattern expected, String actual) {
|
||||||
assertMatches(message, true, expected, 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) {
|
public static void assertFind(String expectedRegex, int expectedCount, String actual) {
|
||||||
assertFind(null, expectedRegex, expectedCount, 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) {
|
public static void assertFind(String message, String expectedRegex, int expectedCount, String actual) {
|
||||||
Pattern pattern = Pattern.compile(expectedRegex);
|
Pattern pattern = Pattern.compile(expectedRegex);
|
||||||
assertFind(message, pattern, expectedCount, actual);
|
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) {
|
public static void assertFind(Pattern expected, int expectedCount, String actual) {
|
||||||
assertFind(null, expected, expectedCount, 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) {
|
public static void assertFind(String message, Pattern expected, int expectedCount, String actual) {
|
||||||
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