initial checkin
This commit is contained in:
commit
e087bc6d81
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Maven
|
||||||
|
pom.xml.versionsBackup
|
||||||
|
|
||||||
|
# Eclipse
|
||||||
|
.project
|
||||||
|
.classpath
|
||||||
|
.settings
|
||||||
|
target
|
||||||
|
|
57
pom.xml
Normal file
57
pom.xml
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<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>junit5-ext</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>Reusable JUnit5 Extensions</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
<junit.version>5.7.0</junit.version>
|
||||||
|
<junit-platform-provider.version>[1.3, 1.4)</junit-platform-provider.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
|
<version>${junit.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>2.22.2</version>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.platform</groupId>
|
||||||
|
<artifactId>junit-platform-surefire-provider</artifactId>
|
||||||
|
<version>${junit-platform-provider.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<version>${junit.version}</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<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/junit5/AssertCollection.java
Normal file
34
src/main/java/com/inteligr8/junit5/AssertCollection.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package com.inteligr8.junit5;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
|
||||||
|
public class AssertCollection {
|
||||||
|
|
||||||
|
public static void assertSize(int expectedCount, Collection<?> actualCollection) {
|
||||||
|
assertSize(expectedCount, actualCollection, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void assertContains(T expectedElement, Collection<T> actualCollection) {
|
||||||
|
assertContains(expectedElement, actualCollection, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void assertContains(Collection<T> expectedElements, Collection<T> actualCollection) {
|
||||||
|
assertContains(expectedElements, actualCollection, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void assertContains(T expectedElement, Collection<T> actualCollection, String message) {
|
||||||
|
Assertions.assertTrue(actualCollection != null && actualCollection.contains(expectedElement), message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void assertContains(Collection<T> expectedElements, Collection<T> actualCollection, String message) {
|
||||||
|
Assertions.assertTrue(actualCollection != null && actualCollection.containsAll(expectedElements), message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
77
src/main/java/com/inteligr8/junit5/AssertRegex.java
Normal file
77
src/main/java/com/inteligr8/junit5/AssertRegex.java
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
package com.inteligr8.junit5;
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
|
||||||
|
public class AssertRegex {
|
||||||
|
|
||||||
|
public static void assertMatches(String expectedRegex, String actual) {
|
||||||
|
assertMatches(expectedRegex, actual, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertMatches(String expectedRegex, String actual, String message) {
|
||||||
|
Pattern pattern = Pattern.compile(expectedRegex);
|
||||||
|
assertMatches(pattern, actual, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertMatches(Pattern expected, String actual) {
|
||||||
|
assertMatches(expected, actual, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertMatches(Pattern expected, String actual, String message) {
|
||||||
|
assertMatches(false, expected, actual, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertNotMatches(String expectedRegex, String actual) {
|
||||||
|
assertNotMatches(expectedRegex, actual, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertNotMatches(String expectedRegex, String actual, String message) {
|
||||||
|
Pattern pattern = Pattern.compile(expectedRegex);
|
||||||
|
assertNotMatches(pattern, actual, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertNotMatches(Pattern expected, String actual) {
|
||||||
|
assertNotMatches(expected, actual, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertNotMatches(Pattern expected, String actual, String message) {
|
||||||
|
assertMatches(true, expected, actual, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void assertMatches(boolean negate, Pattern expected, String actual, String message) {
|
||||||
|
Matcher matcher = expected.matcher(actual);
|
||||||
|
if (matcher.matches() == negate) {
|
||||||
|
message = message == null ? "" : (message + "; ");
|
||||||
|
message += "expression of expected string: <" + expected.toString() + "> but actual string: <" + actual + ">";
|
||||||
|
Assertions.fail(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void assertFind(String expectedRegex, int expectedCount, String actual) {
|
||||||
|
assertFind(expectedRegex, expectedCount, actual, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertFind(String expectedRegex, int expectedCount, String actual, String message) {
|
||||||
|
Pattern pattern = Pattern.compile(expectedRegex);
|
||||||
|
assertFind(pattern, expectedCount, actual, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertFind(Pattern expected, int expectedCount, String actual) {
|
||||||
|
assertFind(expected, expectedCount, actual, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertFind(Pattern expected, int expectedCount, String actual, String message) {
|
||||||
|
Matcher matcher = expected.matcher(actual);
|
||||||
|
int count = 0;
|
||||||
|
for (count = 0; matcher.find(); count++)
|
||||||
|
;
|
||||||
|
if (expectedCount < 0) Assertions.assertTrue(-expectedCount <= count, message);
|
||||||
|
else Assertions.assertEquals(expectedCount, count, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user