initial checkin
This commit is contained in:
commit
b863d3749e
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Maven
|
||||||
|
pom.xml.versionsBackup
|
||||||
|
|
||||||
|
# Eclipse
|
||||||
|
.project
|
||||||
|
.classpath
|
||||||
|
.settings
|
||||||
|
target
|
||||||
|
|
33
pom.xml
Normal file
33
pom.xml
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.inteligr8</groupId>
|
||||||
|
<artifactId>junit4-ext</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>Reusable JUnit4 Extensions</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>1.7</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.7</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.13</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<distributionManagement>
|
||||||
|
<repository>
|
||||||
|
<id>inteligr8-releases</id>
|
||||||
|
<name>Inteligr8 Releases</name>
|
||||||
|
<url>http://repos.yateslong.us/nexus/repository/inteligr8-public</url>
|
||||||
|
<layout>default</layout>
|
||||||
|
</repository>
|
||||||
|
</distributionManagement>
|
||||||
|
</project>
|
34
src/main/java/com/inteligr8/junit4/AssertCollection.java
Normal file
34
src/main/java/com/inteligr8/junit4/AssertCollection.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package com.inteligr8.junit4;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
|
||||||
|
public class AssertCollection {
|
||||||
|
|
||||||
|
public static void assertSize(int expectedCount, Collection<?> actualCollection) {
|
||||||
|
assertSize(null, expectedCount, actualCollection);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void assertContains(T expectedElement, Collection<T> actualCollection) {
|
||||||
|
assertContains(null, expectedElement, actualCollection);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void assertContains(Collection<T> expectedElements, Collection<T> actualCollection) {
|
||||||
|
assertContains(null, expectedElements, actualCollection);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void assertContains(String message, T expectedElement, Collection<T> actualCollection) {
|
||||||
|
Assert.assertTrue(message, actualCollection != null && actualCollection.contains(expectedElement));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void assertContains(String message, Collection<T> expectedElements, Collection<T> actualCollection) {
|
||||||
|
Assert.assertTrue(message, actualCollection != null && actualCollection.containsAll(expectedElements));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
77
src/main/java/com/inteligr8/junit4/AssertRegex.java
Normal file
77
src/main/java/com/inteligr8/junit4/AssertRegex.java
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
package com.inteligr8.junit4;
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
|
||||||
|
public class AssertRegex {
|
||||||
|
|
||||||
|
public static void assertMatches(String expectedRegex, String actual) {
|
||||||
|
assertMatches(null, expectedRegex, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertMatches(String message, String expectedRegex, String actual) {
|
||||||
|
Pattern pattern = Pattern.compile(expectedRegex);
|
||||||
|
assertMatches(message, pattern, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertMatches(Pattern expected, String actual) {
|
||||||
|
assertMatches(null, expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertMatches(String message, Pattern expected, String actual) {
|
||||||
|
assertMatches(message, false, expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertNotMatches(String expectedRegex, String actual) {
|
||||||
|
assertNotMatches(null, expectedRegex, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertNotMatches(String message, String expectedRegex, String actual) {
|
||||||
|
Pattern pattern = Pattern.compile(expectedRegex);
|
||||||
|
assertNotMatches(message, pattern, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertNotMatches(Pattern expected, String actual) {
|
||||||
|
assertNotMatches(null, expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertNotMatches(String message, Pattern expected, String actual) {
|
||||||
|
assertMatches(message, true, expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void assertMatches(String message, boolean negate, Pattern expected, String actual) {
|
||||||
|
Matcher matcher = expected.matcher(actual);
|
||||||
|
if (matcher.matches() == negate) {
|
||||||
|
message = message == null ? "" : (message + "; ");
|
||||||
|
message += "expression of expected string: <" + expected.toString() + "> but actual string: <" + actual + ">";
|
||||||
|
Assert.fail(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void assertFind(String expectedRegex, int expectedCount, String actual) {
|
||||||
|
assertFind(null, expectedRegex, expectedCount, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertFind(String message, String expectedRegex, int expectedCount, String actual) {
|
||||||
|
Pattern pattern = Pattern.compile(expectedRegex);
|
||||||
|
assertFind(message, pattern, expectedCount, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertFind(Pattern expected, int expectedCount, String actual) {
|
||||||
|
assertFind(null, expected, expectedCount, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertFind(String message, Pattern expected, int expectedCount, String actual) {
|
||||||
|
Matcher matcher = expected.matcher(actual);
|
||||||
|
int count = 0;
|
||||||
|
for (count = 0; matcher.find(); count++)
|
||||||
|
;
|
||||||
|
if (expectedCount < 0) Assert.assertTrue(message, -expectedCount <= count);
|
||||||
|
else Assert.assertEquals(message, expectedCount, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user