diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..336e77e
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,13 @@
+root = true
+
+[*]
+end_of_line = lf
+insert_final_newline = true
+indent_style = space
+indent_size = 4
+charset = utf-8
+continuation_indent_size = 8
+
+[*.yml]
+indent_style = space
+indent_size = 2
diff --git a/.travis.yml b/.travis.yml
index 0bdd949..f8b2798 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,3 +1,12 @@
language: java
+
+cache:
+ directories:
+ - $HOME/.m2
+
jdk:
- - oraclejdk8
+ - openjdk8
+
+install: true
+
+script: mvn clean install
diff --git a/pom.xml b/pom.xml
index 89c3006..f40b001 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,16 +7,13 @@
1.7-SNAPSHOT
java-8-matchers
-
- Hamcrest matchers for JDK8's Optionals and Streams, and the java.time package
-
+ Hamcrest matchers for features introduced in Java 8: Optional, Stream, the Java Time API, and lambdas.
https://github.com/unruly/java-8-matchers
1.8
1.8
UTF-8
- -Xdoclint:none
@@ -40,37 +37,144 @@
HEAD
+
+
+
+ org.junit
+ junit-bom
+ 5.6.2
+ pom
+ import
+
+
+
+
org.hamcrest
- hamcrest-core
- 1.3
+ hamcrest
+ 2.2
- junit
- junit
- 4.12
- test
-
-
- org.hamcrest
- hamcrest-library
- 1.3
+ org.junit.jupiter
+ junit-jupiter-api
test
+
+
+
+ maven-clean-plugin
+ 3.1.0
+
+
+ maven-enforcer-plugin
+ 3.0.0-M3
+
+
+
+ 3.0.5
+
+
+
+
+
+ maven-dependency-plugin
+ 3.1.2
+
+ true
+
+
+
+ maven-resources-plugin
+ 3.1.0
+
+
+ maven-compiler-plugin
+ 3.8.1
+
+
+ maven-source-plugin
+ 3.2.1
+
+
+ maven-javadoc-plugin
+ 3.2.0
+
+ all,-missing
+ true
+
+
+
+ maven-surefire-plugin
+ 3.0.0-M4
+
+
+ maven-jar-plugin
+ 3.2.0
+
+
+ maven-install-plugin
+ 3.0.0-M1
+
+
+ maven-deploy-plugin
+ 3.0.0-M1
+
+
+ maven-release-plugin
+ 3.0.0-M1
+
+ true
+ false
+ release
+ deploy
+ forked-path
+
+
+
+ org.sonatype.plugins
+ nexus-staging-maven-plugin
+ 1.6.8
+ true
+
+ ossrh
+ https://oss.sonatype.org/
+ true
+
+
+
+ org.codehaus.mojo
+ versions-maven-plugin
+ 2.7
+
+
+
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.1
+ maven-enforcer-plugin
+
+
+
+ enforce
+
+
+
+
+
+ maven-dependency-plugin
+
+
+
+ analyze-only
+
+
+
- org.apache.maven.plugins
maven-source-plugin
- 2.2.1
attach-sources
@@ -81,9 +185,7 @@
- org.apache.maven.plugins
maven-javadoc-plugin
- 2.9.1
attach-javadocs
@@ -96,42 +198,6 @@
org.sonatype.plugins
nexus-staging-maven-plugin
- 1.6.5
- true
-
- ossrh
- https://oss.sonatype.org/
- true
-
-
-
- org.apache.maven.plugins
- maven-release-plugin
- 2.5
-
- true
- false
- release
- deploy
- forked-path
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
- 2.19.1
-
-
- org.apache.maven.plugins
- maven-jar-plugin
- 2.6
-
-
-
- test-jar
-
-
-
@@ -142,7 +208,6 @@
- org.apache.maven.plugins
maven-gpg-plugin
1.6
@@ -171,4 +236,4 @@
-
\ No newline at end of file
+
diff --git a/src/main/java/co/unruly/matchers/StreamMatchers.java b/src/main/java/co/unruly/matchers/StreamMatchers.java
index 106f45a..99d2ef7 100644
--- a/src/main/java/co/unruly/matchers/StreamMatchers.java
+++ b/src/main/java/co/unruly/matchers/StreamMatchers.java
@@ -7,9 +7,13 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
-import java.util.PrimitiveIterator;
import java.util.Objects;
-import java.util.stream.*;
+import java.util.PrimitiveIterator;
+import java.util.stream.BaseStream;
+import java.util.stream.DoubleStream;
+import java.util.stream.IntStream;
+import java.util.stream.LongStream;
+import java.util.stream.Stream;
public class StreamMatchers {
@@ -356,11 +360,11 @@ public void describeTo(Description description) {
/**
* The BaseStream must produce exactly the given expected items in order, and no more.
*
- * For infinite BaseStreams see {@link #startsWith(T...)} or a primitive stream variant
+ * For infinite BaseStreams see {@link #startsWith(Object...)} or a primitive stream variant
* @param expectedMatchers Matchers for the items that should be produced by the BaseStream
* @param The type of items
* @param The type of the BaseStream
- * @see #startsWith(T...)
+ * @see #startsWith(Object...)
* @see #startsWithInt(int...)
* @see #startsWithLong(long...)
* @see #startsWithDouble(double...)
@@ -379,11 +383,11 @@ protected boolean matchesSafely(S actual) {
/**
* The BaseStream must produce exactly the given expected items in order, and no more.
*
- * For infinite BaseStreams see {@link #startsWith(T...)} or a primitive stream variant
+ * For infinite BaseStreams see {@link #startsWith(Object...)} or a primitive stream variant
* @param expected The items that should be produced by the BaseStream
* @param The type of items
* @param The type of the BaseStream
- * @see #startsWith(T...)
+ * @see #startsWith(Object...)
* @see #startsWithInt(int...)
* @see #startsWithLong(long...)
* @see #startsWithDouble(double...)
@@ -671,7 +675,7 @@ boolean remainingItemsEqual(Iterator expectedIterator, Iterator actualIter
expectedAccumulator.add(nextExpected);
T nextActual = actualIterator.next();
actualAccumulator.add(nextActual);
- if(Objects.equals(nextExpected, nextActual)) {
+ if (Objects.equals(nextExpected, nextActual)) {
return remainingItemsEqual(expectedIterator, actualIterator);
}
}
@@ -704,7 +708,7 @@ boolean remainingItemsMatch(Iterator> expectedIterator, Iterator a
expectedAccumulator.add(nextExpected);
T nextActual = actualIterator.next();
actualAccumulator.add(nextActual);
- if(nextExpected.matches(nextActual)) {
+ if (nextExpected.matches(nextActual)) {
return remainingItemsMatch(expectedIterator, actualIterator);
}
}
@@ -912,7 +916,7 @@ public T next() {
private static class IntArrayIterator implements PrimitiveIterator.OfInt {
private final int[] expected;
private int currentPos = 0;
-
+
public IntArrayIterator(int... expected) {
this.expected = expected;
}
diff --git a/src/test/java/co/unruly/matchers/Helper.java b/src/test/java/co/unruly/matchers/Helper.java
index 27528b7..3cf8ac5 100644
--- a/src/test/java/co/unruly/matchers/Helper.java
+++ b/src/test/java/co/unruly/matchers/Helper.java
@@ -3,17 +3,16 @@
import org.hamcrest.Matcher;
import static java.util.Arrays.asList;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.stringContainsInOrder;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.fail;
-public class Helper {
+class Helper {
static void testFailingMatcher(S testData, Matcher matcher, String expectedDescription, String actualDescription) {
try {
- assertThat(testData,matcher);
+ assertThat(testData, matcher);
fail("Supposed to not match " + matcher + ", but " + testData + " matched");
} catch (AssertionError e) {
- System.out.println(e.getMessage());
assertThat(e.toString(), stringContainsInOrder(asList(expectedDescription, actualDescription)));
}
}
diff --git a/src/test/java/co/unruly/matchers/Java8MatchersTest.java b/src/test/java/co/unruly/matchers/Java8MatchersTest.java
index b3bb796..f3d0b79 100644
--- a/src/test/java/co/unruly/matchers/Java8MatchersTest.java
+++ b/src/test/java/co/unruly/matchers/Java8MatchersTest.java
@@ -1,38 +1,38 @@
package co.unruly.matchers;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import static co.unruly.matchers.Helper.testFailingMatcher;
import static co.unruly.matchers.Java8Matchers.where;
import static co.unruly.matchers.Java8Matchers.whereNot;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
-import static org.junit.Assert.assertThat;
-public class Java8MatchersTest {
+class Java8MatchersTest {
final A entity = new A();
@Test
- public void propertiesWhichAreTrue() {
+ void propertiesWhichAreTrue() {
assertThat(entity, where(A::isCool));
assertThat(entity, where(a -> a.isCool()));
}
@Test
- public void propertiesWhichAreFalse() {
+ void propertiesWhichAreFalse() {
assertThat(entity, whereNot(A::isBoring));
assertThat(entity, whereNot(a -> a.isBoring()));
}
@Test
- public void matchProperties() {
+ void matchProperties() {
assertThat(entity, where(A::name, is("A")));
assertThat(entity, where(a -> a.name(), is("A")));
}
@Test
- public void failMatchingProperties() {
+ void failMatchingProperties() {
testFailingMatcher(entity, where(A::name, is("X")), "with a name (a String) which is \"X\"", "had the name (a String) \"A\"");
testFailingMatcher(entity, where(a -> a.name(), is("X")), "with a String which is \"X\"", "had the String \"A\"");
testFailingMatcher(entity, where(A::age, not(is(42))), "with an age (an int) which not is <42>", "had the age (an int) <42>");
diff --git a/src/test/java/co/unruly/matchers/OptionalMatchersTest.java b/src/test/java/co/unruly/matchers/OptionalMatchersTest.java
index 3362952..b7b31e9 100644
--- a/src/test/java/co/unruly/matchers/OptionalMatchersTest.java
+++ b/src/test/java/co/unruly/matchers/OptionalMatchersTest.java
@@ -2,119 +2,119 @@
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.OptionalInt;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.not;
-import static org.junit.Assert.assertThat;
-public class OptionalMatchersTest {
+class OptionalMatchersTest {
@Test
- public void empty_success() throws Exception {
+ void empty_success() {
assertThat(Optional.empty(), OptionalMatchers.empty());
}
@Test
- public void empty_failure() throws Exception {
- assertThat(Optional.of(1),not(OptionalMatchers.empty()));
+ void empty_failure() {
+ assertThat(Optional.of(1), not(OptionalMatchers.empty()));
}
@Test
- public void empty_failureMessage() throws Exception {
+ void empty_failureMessage() {
Helper.testFailingMatcher(Optional.of(1), OptionalMatchers.empty(), "An empty Optional","");
}
@Test
- public void contains_success() throws Exception {
+ void contains_success() {
assertThat(Optional.of("Hi!"), OptionalMatchers.contains("Hi!"));
}
@Test
- public void contains_failureNonEmpty() throws Exception {
+ void contains_failureNonEmpty() {
assertThat(Optional.of("Hi!"), not(OptionalMatchers.contains("Yay")));
}
@Test
- public void contains_failureEmpty() throws Exception {
- assertThat(Optional.empty(),not(OptionalMatchers.contains("Woot")));
+ void contains_failureEmpty() {
+ assertThat(Optional.empty(), not(OptionalMatchers.contains("Woot")));
}
@Test
- public void contains_failureMessages() throws Exception {
+ void contains_failureMessages() {
Helper.testFailingMatcher(Optional.of(1), OptionalMatchers.contains(2), "Optional[2]","");
}
@Test
- public void containsMatcher_success() throws Exception {
- assertThat(Optional.of(4),OptionalMatchers.contains(Matchers.greaterThan(3)));
+ void containsMatcher_success() {
+ assertThat(Optional.of(4), OptionalMatchers.contains(Matchers.greaterThan(3)));
}
@Test
- public void containsMatcher_success_typechecksWhenOptionalsArgIsStrictSubtype() {
+ void containsMatcher_success_typechecksWhenOptionalsArgIsStrictSubtype() {
Optional> optionalToMatch = Optional.of(Arrays.asList("a"));
Matcher> matcherOfStrictSuperType = hasItem("a");
assertThat(optionalToMatch, OptionalMatchers.contains(matcherOfStrictSuperType));
}
@Test
- public void containsMatcher_failureDiffering() throws Exception {
- assertThat(Optional.of(100),not(OptionalMatchers.contains(Matchers.lessThanOrEqualTo(19))));
+ void containsMatcher_failureDiffering() {
+ assertThat(Optional.of(100), not(OptionalMatchers.contains(Matchers.lessThanOrEqualTo(19))));
}
@Test
- public void containsMatcher_failureEmpty() throws Exception {
- assertThat(Optional.empty(),not(OptionalMatchers.contains(Matchers.lessThanOrEqualTo(19))));
+ void containsMatcher_failureEmpty() {
+ assertThat(Optional.empty(), not(OptionalMatchers.contains(Matchers.lessThanOrEqualTo(19))));
}
@Test
- public void containsMatcher_failureMessage() throws Exception {
+ void containsMatcher_failureMessage() {
Helper.testFailingMatcher(Optional.of(2), OptionalMatchers.contains(Matchers.equalTo(4)), "Optional with an item that matches<4>","");
}
@Test
- public void emptyInt_success() throws Exception {
- assertThat(OptionalInt.empty(),OptionalMatchers.emptyInt());
+ void emptyInt_success() {
+ assertThat(OptionalInt.empty(), OptionalMatchers.emptyInt());
}
@Test
- public void emptyInt_failure() throws Exception {
- assertThat(OptionalInt.of(0),not(OptionalMatchers.emptyInt()));
+ void emptyInt_failure() {
+ assertThat(OptionalInt.of(0), not(OptionalMatchers.emptyInt()));
}
@Test
- public void containsInt_success() throws Exception {
- assertThat(OptionalInt.of(0),OptionalMatchers.containsInt(0));
+ void containsInt_success() {
+ assertThat(OptionalInt.of(0), OptionalMatchers.containsInt(0));
}
@Test
- public void containsInt_failureDiffering() throws Exception {
- assertThat(OptionalInt.of(0),not(OptionalMatchers.containsInt(1)));
+ void containsInt_failureDiffering() {
+ assertThat(OptionalInt.of(0), not(OptionalMatchers.containsInt(1)));
}
@Test
- public void containsInt_failureEmpty() throws Exception {
- assertThat(OptionalInt.empty(),not(OptionalMatchers.containsInt(1)));
+ void containsInt_failureEmpty() {
+ assertThat(OptionalInt.empty(), not(OptionalMatchers.containsInt(1)));
}
@Test
- public void containsIntMatcher_success() throws Exception {
- assertThat(OptionalInt.of(0),OptionalMatchers.containsInt(Matchers.equalTo(0)));
+ void containsIntMatcher_success() {
+ assertThat(OptionalInt.of(0), OptionalMatchers.containsInt(Matchers.equalTo(0)));
}
@Test
- public void containsIntMatcher_failureEmpty() throws Exception {
- assertThat(OptionalInt.empty(),not(OptionalMatchers.containsInt(Matchers.equalTo(1))));
+ void containsIntMatcher_failureEmpty() {
+ assertThat(OptionalInt.empty(), not(OptionalMatchers.containsInt(Matchers.equalTo(1))));
}
@Test
- public void containsIntMatcher_failureDiffering() throws Exception {
- assertThat(OptionalInt.of(0),not(OptionalMatchers.containsInt(Matchers.equalTo(1))));
+ void containsIntMatcher_failureDiffering() {
+ assertThat(OptionalInt.of(0), not(OptionalMatchers.containsInt(Matchers.equalTo(1))));
}
}
diff --git a/src/test/java/co/unruly/matchers/StreamMatchersTest.java b/src/test/java/co/unruly/matchers/StreamMatchersTest.java
index 509adf4..c0183f5 100644
--- a/src/test/java/co/unruly/matchers/StreamMatchersTest.java
+++ b/src/test/java/co/unruly/matchers/StreamMatchersTest.java
@@ -2,212 +2,221 @@
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-import java.util.stream.*;
+import java.util.stream.BaseStream;
+import java.util.stream.DoubleStream;
+import java.util.stream.IntStream;
+import java.util.stream.LongStream;
+import java.util.stream.Stream;
-import static co.unruly.matchers.StreamMatchers.*;
+import static co.unruly.matchers.StreamMatchers.allMatch;
+import static co.unruly.matchers.StreamMatchers.anyMatch;
import static co.unruly.matchers.StreamMatchers.contains;
import static co.unruly.matchers.StreamMatchers.empty;
import static co.unruly.matchers.StreamMatchers.equalTo;
import static co.unruly.matchers.StreamMatchers.startsWith;
-import static org.hamcrest.Matchers.*;
-import static org.junit.Assert.assertThat;
+import static co.unruly.matchers.StreamMatchers.startsWithInt;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.lessThanOrEqualTo;
+import static org.hamcrest.Matchers.not;
-public class StreamMatchersTest {
+class StreamMatchersTest {
@Test
- public void equalTo_failureDifferingSingleItem() throws Exception {
+ void equalTo_failureDifferingSingleItem() {
assertThat(Stream.of("a"), is(not(equalTo(Stream.of("b")))));
}
@Test
- public void contains_failureDifferingSingleItem() throws Exception {
+ void contains_failureDifferingSingleItem() {
assertThat(Stream.of("a"), is(not(contains("b"))));
}
@Test
- public void equalTo_failureDifferingLength() throws Exception {
+ void equalTo_failureDifferingLength() {
assertThat(Stream.of("a"), is(not(equalTo(Stream.of("a", "b")))));
}
@Test
- public void contains_failureDifferingLength() throws Exception {
+ void contains_failureDifferingLength() {
assertThat(Stream.of("a"), is(not(contains("a", "b"))));
}
@Test
- public void equalTo_failureDifferingItems() throws Exception {
+ void equalTo_failureDifferingItems() {
assertThat(Stream.of("a","c"), is(not(equalTo(Stream.of("a", "b")))));
}
@Test
- public void contains_failureDifferingItems() throws Exception {
+ void contains_failureDifferingItems() {
assertThat(Stream.of("a","c"), is(not(contains("a", "b"))));
}
@Test
- public void equalTo_successEmpty() throws Exception {
+ void equalTo_successEmpty() {
assertThat(Stream.empty(), equalTo(Stream.empty()));
}
@Test
- public void empty_Success() throws Exception {
- assertThat(Stream.empty(),empty());
+ void empty_Success() {
+ assertThat(Stream.empty(), empty());
}
@Test
- public void empty_Failure() throws Exception {
+ void empty_Failure() {
Helper.testFailingMatcher(Stream.of(3), empty(), "An empty Stream", "A non empty Stream starting with <3>");
}
@Test
- public void equalToIntStream_success() throws Exception {
+ void equalToIntStream_success() {
assertThat(IntStream.range(1, 10), equalTo(IntStream.range(1, 10)));
}
@Test
- public void containsIntStream_success() throws Exception {
- assertThat(IntStream.range(1, 4), contains(1,2,3));
+ void containsIntStream_success() {
+ assertThat(IntStream.range(1, 4), contains(1, 2, 3));
}
@Test
- public void equalTo_successManyItems() throws Exception {
+ void equalTo_successManyItems() {
assertThat(Stream.of("a", "b", "c"), equalTo(Stream.of("a", "b", "c")));
}
@Test
- public void contains_successManyItems() throws Exception {
+ void contains_successManyItems() {
assertThat(Stream.of("a", "b", "c"), contains("a", "b", "c"));
}
@Test
- public void contains_is_nullsafe() {
+ void contains_is_nullsafe() {
assertThat(Stream.of("a", null, "c"), contains("a", null, "c"));
}
@Test
- public void allMatch_success() throws Exception {
- assertThat(Stream.of("bar","baz"),allMatch(containsString("a")));
+ void allMatch_success() {
+ assertThat(Stream.of("bar","baz"), allMatch(containsString("a")));
}
@Test
- public void allMatch_failure() throws Exception {
+ void allMatch_failure() {
Matcher> matcher = StreamMatchers.allMatch(containsString("a"));
Stream testData = Stream.of("bar", "bar", "foo", "grault", "garply", "waldo");
Helper.testFailingMatcher(testData, matcher, "All to match ", "Item 2 failed to match: \"foo\"");
}
@Test
- public void allMatchInt_failure() throws Exception {
+ void allMatchInt_failure() {
Matcher matcher = StreamMatchers.allMatchInt(Matchers.lessThan(3));
- IntStream testData = IntStream.range(0,10);
+ IntStream testData = IntStream.range(0, 10);
Helper.testFailingMatcher(testData, matcher, "All to match >", "Item 3 failed to match: <3>");
}
@Test
- public void allMatchLong_failure() throws Exception {
+ void allMatchLong_failure() {
Matcher matcher = StreamMatchers.allMatchLong(Matchers.lessThan(3L));
- LongStream testData = LongStream.range(0,10);
+ LongStream testData = LongStream.range(0, 10);
Helper.testFailingMatcher(testData, matcher, "All to match >", "Item 3 failed to match: <3L>");
}
@Test
- public void allMatchDouble_failure() throws Exception {
+ void allMatchDouble_failure() {
Matcher matcher = StreamMatchers.allMatchDouble(Matchers.lessThan(3d));
- DoubleStream testData = DoubleStream.iterate(0d,d -> d + 1).limit(10);
+ DoubleStream testData = DoubleStream.iterate(0d, d -> d + 1).limit(10);
Helper.testFailingMatcher(testData, matcher, "All to match >", "Item 3 failed to match: <3.0>");
}
@Test
- public void allMatch_empty() throws Exception {
- assertThat(Stream.empty(),allMatch(containsString("foo")));
+ void allMatch_empty() {
+ assertThat(Stream.empty(), allMatch(containsString("foo")));
}
@Test
- public void anyMatch_success() throws Exception {
- assertThat(Stream.of("bar", "bar", "foo", "grault", "garply", "waldo"),StreamMatchers.anyMatch(containsString("ald")));
+ void anyMatch_success() {
+ assertThat(Stream.of("bar", "bar", "foo", "grault", "garply", "waldo"), StreamMatchers.anyMatch(containsString("ald")));
}
@Test
- public void anyMatch_failure() throws Exception {
+ void anyMatch_failure() {
Matcher> matcher = StreamMatchers.anyMatch(containsString("z"));
Stream testData = Stream.of("bar", "bar", "foo", "grault", "garply", "waldo");
Helper.testFailingMatcher(testData, matcher, "Any to match >", "None of these items matched: [<0>,<1>,<2>,<3>,<4>]");
+ void anyMatchInt_failure() {
+ Helper.testFailingMatcher(IntStream.range(0, 5), StreamMatchers.anyMatchInt(Matchers.equalTo(101)), "Any to match <<101>>", "None of these items matched: [<0>,<1>,<2>,<3>,<4>]");
}
@Test
- public void anyMatchLong_success() throws Exception {
- assertThat(LongStream.range(0,1_000),StreamMatchers.anyMatchLong(Matchers.equalTo(10L)));
+ void anyMatchLong_success() {
+ assertThat(LongStream.range(0, 1_000), StreamMatchers.anyMatchLong(Matchers.equalTo(10L)));
}
@Test
- public void anyMatchLong_failure() throws Exception {
- Helper.testFailingMatcher(LongStream.range(0,5), StreamMatchers.anyMatchLong(Matchers.equalTo(101L)), "Any to match <<101L>>", "None of these items matched: [<0L>,<1L>,<2L>,<3L>,<4L>]");
+ void anyMatchLong_failure() {
+ Helper.testFailingMatcher(LongStream.range(0, 5), StreamMatchers.anyMatchLong(Matchers.equalTo(101L)), "Any to match <<101L>>", "None of these items matched: [<0L>,<1L>,<2L>,<3L>,<4L>]");
}
@Test
- public void anyMatchDouble_success() throws Exception {
- assertThat(DoubleStream.iterate(0d,i -> i + 1),StreamMatchers.anyMatchDouble(Matchers.equalTo(10d)));
+ void anyMatchDouble_success() {
+ assertThat(DoubleStream.iterate(0d, i -> i + 1), StreamMatchers.anyMatchDouble(Matchers.equalTo(10d)));
}
@Test
- public void anyMatchDouble_failure() throws Exception {
- Helper.testFailingMatcher(DoubleStream.iterate(0d,i -> i + 1).limit(5), StreamMatchers.anyMatchDouble(Matchers.equalTo(101d)), "Any to match <<101.0>>", "None of these items matched: [<0.0>,<1.0>,<2.0>,<3.0>,<4.0>]");
+ void anyMatchDouble_failure() {
+ Helper.testFailingMatcher(DoubleStream.iterate(0d, i -> i + 1).limit(5), StreamMatchers.anyMatchDouble(Matchers.equalTo(101d)), "Any to match <<101.0>>", "None of these items matched: [<0.0>,<1.0>,<2.0>,<3.0>,<4.0>]");
}
@Test
- public void anyMatch_empty() throws Exception {
+ void anyMatch_empty() {
assertThat(Stream.empty(),not(anyMatch(containsString("foo"))));
}
@Test
- public void startsWithMatcher_success() throws Exception {
- assertThat(Stream.iterate(0,i -> i + 1), startsWith(Stream.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), 10));
+ void startsWithMatcher_success() {
+ assertThat(Stream.iterate(0, i -> i + 1), startsWith(Stream.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), 10));
}
@Test
- public void startsWithMatcher_successBothInfinite() throws Exception {
+ void startsWithMatcher_successBothInfinite() {
assertThat(Stream.iterate(0,i -> i + 1), startsWith(Stream.iterate(0, i -> i + 1), 10));
}
@Test
- public void startsWithMatcherInt_successBothInfinite() throws Exception {
- assertThat(IntStream.iterate(0,i -> i + 1), startsWith(IntStream.iterate(0, i -> i + 1), 10));
+ void startsWithMatcherInt_successBothInfinite() {
+ assertThat(IntStream.iterate(0, i -> i + 1), startsWith(IntStream.iterate(0, i -> i + 1), 10));
}
@Test
- public void startsWithMatcherLong_successBothInfinite() throws Exception {
- assertThat(LongStream.iterate(0,i -> i + 1), startsWith(LongStream.iterate(0, i -> i + 1), 10));
+ void startsWithMatcherLong_successBothInfinite() {
+ assertThat(LongStream.iterate(0, i -> i + 1), startsWith(LongStream.iterate(0, i -> i + 1), 10));
}
@Test
- public void startsWithMatcherDouble_successBothInfinite() throws Exception {
- assertThat(DoubleStream.iterate(0,i -> i + 1), startsWith(DoubleStream.iterate(0, i -> i + 1), 10));
+ void startsWithMatcherDouble_successBothInfinite() {
+ assertThat(DoubleStream.iterate(0, i -> i + 1), startsWith(DoubleStream.iterate(0, i -> i + 1), 10));
}
@Test
- public void startsWithItems_success() throws Exception {
- assertThat(Stream.of("a","b","c","d","e", "f", "g", "h"), startsWith("a", "b", "c", "d", "e"));
+ void startsWithItems_success() {
+ assertThat(Stream.of("a", "b", "c", "d", "e", "f", "g", "h"), startsWith("a", "b", "c", "d", "e"));
}
@Test
- public void startsWithItemsIntStream_success() throws Exception {
- assertThat(IntStream.range(0,Integer.MAX_VALUE), startsWithInt(0, 1, 2, 3, 4));
+ void startsWithItemsIntStream_success() {
+ assertThat(IntStream.range(0, Integer.MAX_VALUE), startsWithInt(0, 1, 2, 3, 4));
}
@Test
- public void equalTo_failureMessages() throws Exception {
+ void equalTo_failureMessages() {
Matcher>> matcher = equalTo(Stream.of("a", "b", "c", "d", "e", "f", "g", "h"));
Stream testData = Stream.of("a", "b", "c", "d", "e");
Helper.testFailingMatcher(testData, matcher, "Stream of [\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\"]", "Stream of [\"a\",\"b\",\"c\",\"d\",\"e\"]");
@@ -215,106 +224,106 @@ public void equalTo_failureMessages() throws Exception {
@Test
- public void contains_failureMessages() throws Exception {
+ void contains_failureMessages() {
Stream testData = Stream.of("a", "b", "c", "d", "e");
Matcher> matcher = contains("a", "b", "c", "d", "e", "f", "g", "h");
Helper.testFailingMatcher(testData, matcher, "Stream of [\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\"]", "Stream of [\"a\",\"b\",\"c\",\"d\",\"e\"]");
}
@Test
- public void equalToIntStream_failureMessages() throws Exception {
+ void equalToIntStream_failureMessages() {
IntStream testData = IntStream.range(8, 10);
Matcher> matcher = equalTo(IntStream.range(0, 6));
Helper.testFailingMatcher(testData, matcher, "Stream of [<0>,<1>,<2>,<3>,<4>,<5>]", "Stream of [<8>,<9>]");
}
@Test
- public void startsWithAll_success() throws Exception {
+ void startsWithAll_success() {
assertThat(Stream.generate(() -> 10), StreamMatchers.startsWithAll(Matchers.equalTo(10),100));
}
@Test
- public void startsWithAll_fail() throws Exception {
+ void startsWithAll_fail() {
Helper.testFailingMatcher(Stream.generate(() -> 11), StreamMatchers.startsWithAll(Matchers.equalTo(10), 100), "First 100 to match <<10>>", "Item 0 failed to match: <11>");
}
@Test
- public void startsWithAllInt_success() throws Exception {
+ void startsWithAllInt_success() {
assertThat(IntStream.generate(() -> 10), StreamMatchers.startsWithAllInt(Matchers.equalTo(10), 100));
}
@Test
- public void startsWithAllInt_fail() throws Exception {
+ void startsWithAllInt_fail() {
Helper.testFailingMatcher(IntStream.iterate(0, i -> i + 1), StreamMatchers.startsWithAllInt(Matchers.lessThan(3), 100), "First 100 to match >", "Item 3 failed to match: <3>");
}
@Test
- public void startsWithAllLong_success() throws Exception {
+ void startsWithAllLong_success() {
assertThat(LongStream.generate(() -> 10), StreamMatchers.startsWithAllLong(Matchers.equalTo(10L), 100));
}
@Test
- public void startsWithAllLong_fail() throws Exception {
+ void startsWithAllLong_fail() {
Helper.testFailingMatcher(LongStream.iterate(0, i -> i + 1), StreamMatchers.startsWithAllLong(Matchers.lessThan(3L), 100), "First 100 to match >", "Item 3 failed to match: <3L>");
}
@Test
- public void startsWithAllDouble_success() throws Exception {
+ void startsWithAllDouble_success() {
assertThat(DoubleStream.generate(() -> 10), StreamMatchers.startsWithAllDouble(Matchers.equalTo(10d), 100));
}
@Test
- public void startsWithAllDouble_fail() throws Exception {
+ void startsWithAllDouble_fail() {
Helper.testFailingMatcher(DoubleStream.iterate(0,i -> i + 1), StreamMatchers.startsWithAllDouble(Matchers.lessThan(3d), 100), "First 100 to match >", "Item 3 failed to match: <3.0>");
}
@Test
- public void startsWithAny_success() throws Exception {
+ void startsWithAny_success() {
assertThat(Stream.iterate(0, i -> i + 1), StreamMatchers.startsWithAny(Matchers.equalTo(10), 100));
}
@Test
- public void startsWithAny_fail() throws Exception {
+ void startsWithAny_fail() {
Helper.testFailingMatcher(Stream.iterate(0, i -> i + 1), StreamMatchers.startsWithAny(Matchers.equalTo(-1), 10), "Any of first 10 to match <<-1>>", "None of these items matched: [<0>,<1>,<2>,<3>,<4>,<5>,<6>,<7>,<8>,<9>]");
}
@Test
- public void startsWithAnyInt_success() throws Exception {
+ void startsWithAnyInt_success() {
assertThat(IntStream.iterate(0, i -> i + 1), StreamMatchers.startsWithAnyInt(Matchers.equalTo(10), 100));
}
@Test
- public void startsWithAnyInt_fail() throws Exception {
+ void startsWithAnyInt_fail() {
Helper.testFailingMatcher(IntStream.iterate(0, i -> i + 1), StreamMatchers.startsWithAnyInt(Matchers.equalTo(-1), 10), "Any of first 10 to match <<-1>>", "None of these items matched: [<0>,<1>,<2>,<3>,<4>,<5>,<6>,<7>,<8>,<9>]");
}
@Test
- public void startsWithAnyLong_success() throws Exception {
+ void startsWithAnyLong_success() {
assertThat(LongStream.iterate(0, i -> i + 1), StreamMatchers.startsWithAnyLong(Matchers.equalTo(10L), 100));
}
@Test
- public void startsWithAnyLong_fail() throws Exception {
+ void startsWithAnyLong_fail() {
Helper.testFailingMatcher(LongStream.iterate(0, i -> i + 1), StreamMatchers.startsWithAnyLong(Matchers.equalTo(-1L), 10), "Any of first 10 to match <<-1L>>", "None of these items matched: [<0L>,<1L>,<2L>,<3L>,<4L>,<5L>,<6L>,<7L>,<8L>,<9L>]");
}
@Test
- public void startsWithAnyDouble_success() throws Exception {
+ void startsWithAnyDouble_success() {
assertThat(DoubleStream.iterate(0, i -> i + 1), StreamMatchers.startsWithAnyDouble(Matchers.equalTo(10d), 100));
}
@Test
- public void startsWithAnyDouble_fail() throws Exception {
+ void startsWithAnyDouble_fail() {
Helper.testFailingMatcher(DoubleStream.iterate(0, i -> i + 1), StreamMatchers.startsWithAnyDouble(Matchers.equalTo(-1d), 10), "Any of first 10 to match <<-1.0>>", "None of these items matched: [<0.0>,<1.0>,<2.0>,<3.0>,<4.0>,<5.0>,<6.0>,<7.0>,<8.0>,<9.0>]");
}
@Test
- public void contains_returnsParameterizedMatcher() {
+ void contains_returnsParameterizedMatcher() {
usesStreamMatcher(Stream.of(10), StreamMatchers.contains(10));
}
@Test
- public void contains_acceptsMatchers() {
+ void contains_acceptsMatchers() {
usesStreamMatcher(
Stream.of(10, 20, 30),
StreamMatchers.contains(
@@ -325,7 +334,7 @@ public void contains_acceptsMatchers() {
);
}
- private void usesStreamMatcher(Stream stream, Matcher> matcher) {
+ private static void usesStreamMatcher(Stream stream, Matcher> matcher) {
assertThat(stream, matcher);
}
}
diff --git a/src/test/java/co/unruly/matchers/TimeMatchersTest.java b/src/test/java/co/unruly/matchers/TimeMatchersTest.java
index 30dae50..0626a26 100644
--- a/src/test/java/co/unruly/matchers/TimeMatchersTest.java
+++ b/src/test/java/co/unruly/matchers/TimeMatchersTest.java
@@ -1,16 +1,16 @@
package co.unruly.matchers;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.Period;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
-import static org.junit.Assert.assertThat;
-public class TimeMatchersTest {
+class TimeMatchersTest {
private Instant instant2016 = Instant.parse("2016-01-01T00:00:00.00Z");
private Instant instant2015 = Instant.parse("2015-01-01T00:00:00.00Z");
@@ -19,97 +19,97 @@ public class TimeMatchersTest {
private LocalDate localDate2014 = LocalDate.parse("2014-01-01");
@Test
- public void after_successInstant() throws Exception {
+ void after_successInstant() {
assertThat(instant2015, TimeMatchers.after(instant2014));
}
@Test
- public void after_successLocalDate() throws Exception {
+ void after_successLocalDate() {
assertThat(localDate2015, TimeMatchers.after(localDate2014));
}
@Test
- public void after_failureMessage() throws Exception {
+ void after_failureMessage() {
Helper.testFailingMatcher(instant2014, TimeMatchers.after(instant2015), "after <2015-01-01T00:00:00Z>","2014-01-01T00:00:00Z");
}
@Test
- public void before_successInstant() throws Exception {
+ void before_successInstant() {
assertThat(instant2014, TimeMatchers.before(instant2015));
}
@Test
- public void before_successLocalDate() throws Exception {
+ void before_successLocalDate() {
assertThat(localDate2014, TimeMatchers.before(localDate2015));
}
@Test
- public void beforeTemporal_failureMessage() throws Exception {
+ void beforeTemporal_failureMessage() {
Helper.testFailingMatcher(instant2015, TimeMatchers.before(instant2014), "before <2014-01-01T00:00:00Z>","2015-01-01T00:00:00Z");
}
@Test
- public void betweenTemporal_successSameTimes() throws Exception {
+ void betweenTemporal_successSameTimes() {
assertThat(instant2015, TimeMatchers.between(instant2015, instant2015));
}
@Test
- public void betweenTemporal_successDifferentTimes() throws Exception {
+ void betweenTemporal_successDifferentTimes() {
assertThat(instant2015, TimeMatchers.between(instant2014, instant2016));
}
@Test
- public void betweenTemporal_failureBefore() throws Exception {
+ void betweenTemporal_failureBefore() {
Helper.testFailingMatcher(instant2014, TimeMatchers.between(instant2015, instant2016), "between <2015-01-01T00:00:00Z> and <2016-01-01T00:00:00Z> inclusive", "<2014-01-01T00:00:00Z>");
}
@Test
- public void betweenTemporal_failureAfter() throws Exception {
- Helper.testFailingMatcher(instant2016,TimeMatchers.between(instant2014,instant2015),"between <2014-01-01T00:00:00Z> and <2015-01-01T00:00:00Z> inclusive","<2016-01-01T00:00:00Z>");
+ void betweenTemporal_failureAfter() {
+ Helper.testFailingMatcher(instant2016, TimeMatchers.between(instant2014,instant2015),"between <2014-01-01T00:00:00Z> and <2015-01-01T00:00:00Z> inclusive","<2016-01-01T00:00:00Z>");
}
@Test
- public void longer_success() throws Exception {
+ void longer_success() {
assertThat(Duration.ofMinutes(4), TimeMatchers.longerThan(Duration.ofSeconds(4)));
}
@Test
- public void longer_failureMessage() throws Exception {
+ void longer_failureMessage() {
Helper.testFailingMatcher(Duration.ofMillis(1), TimeMatchers.longerThan(Duration.ofSeconds(4)), "longer than ", "");
}
@Test
- public void shorter_success() throws Exception {
+ void shorter_success() {
assertThat(Duration.ofSeconds(4), TimeMatchers.shorterThan(Duration.ofMinutes(4)));
}
@Test
- public void shorter_failureMessage() throws Exception {
+ void shorter_failureMessage() {
Helper.testFailingMatcher(Duration.ofDays(1), TimeMatchers.shorterThan(Duration.ofSeconds(4)), "shorter than ", "");
}
@Test
- public void betweenTemporalAmount_successSame() throws Exception {
+ void betweenTemporalAmount_successSame() {
assertThat(Duration.ofSeconds(3), TimeMatchers.between(Duration.ofSeconds(3), Duration.ofSeconds(3)));
}
@Test
- public void periodMatcher_success() throws Exception {
+ void periodMatcher_success() {
assertThat(Period.of(1, 2, 3), TimeMatchers.matches(equalTo(1), equalTo(2), equalTo(3)));
}
@Test
- public void periodMatcher_failureMessage() throws Exception {
+ void periodMatcher_failureMessage() {
Helper.testFailingMatcher(Period.of(4, 5, 6), TimeMatchers.matches(equalTo(1), equalTo(2), equalTo(3)), "a Period with years matching <<1>> months matching <<1>> and days matching <<3>>", "P4Y5M6D");
}
/* @Test
- public void shouldNotCompileWithUnlikeTimes() throws Exception {
+ void shouldNotCompileWithUnlikeTimes() {
assertThat(instant2014, TimeMatchers.after(localDate2015));
}
@Test
- public void shouldNotCompileWithNonTimes() throws Exception {
+ void shouldNotCompileWithNonTimes() {
assertThat(Integer.valueOf(3), TimeMatchers.after(Integer.valueOf(4)));
}*/
-}
\ No newline at end of file
+}
diff --git a/src/test/java/co/unruly/matchers/function/LambdaMethodFinderTest.java b/src/test/java/co/unruly/matchers/function/LambdaMethodFinderTest.java
index 86937f1..5d7f7bc 100644
--- a/src/test/java/co/unruly/matchers/function/LambdaMethodFinderTest.java
+++ b/src/test/java/co/unruly/matchers/function/LambdaMethodFinderTest.java
@@ -1,25 +1,25 @@
package co.unruly.matchers.function;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
-public class LambdaMethodFinderTest {
+class LambdaMethodFinderTest {
@Test
- public void getArgumentDescription_resolvesTypeOfArgumentForPredicate() {
+ void getArgumentDescription_resolvesTypeOfArgumentForPredicate() {
assertThat(((DescribablePredicate) s -> s.isEmpty()).getArgumentDescription(), is(String.class.getSimpleName()));
}
@Test
- public void getArgumentDescription_resolvesTypeOfArgumentForFunction() {
+ void getArgumentDescription_resolvesTypeOfArgumentForFunction() {
assertThat(((DescribableFunction) s -> s.length()).getArgumentDescription(), is("String"));
assertThat(((DescribableFunction) String::length).getArgumentDescription(), is("String"));
}
@Test
- public void getResultDescription_resolvesMethodNameAndTypeForMethodReferences() {
+ void getResultDescription_resolvesMethodNameAndTypeForMethodReferences() {
assertThat(((DescribableFunction) String::length).getResultDescription(), is("length (an int)"));
assertThat(((DescribableFunction) String::getBytes).getResultDescription(), is("getBytes (a byte[])"));
}