From 9de27267f93b7accdb2ca4f4f08426ffa2036dc6 Mon Sep 17 00:00:00 2001 From: Rune Flobakk Date: Mon, 13 Apr 2020 14:25:47 +0200 Subject: [PATCH 01/12] Add .editorconfig and fix minor formatting issues - missing whitespace - star-imports --- .editorconfig | 13 +++++ .travis.yml | 2 +- pom.xml | 2 +- .../co/unruly/matchers/StreamMatchers.java | 14 +++-- .../unruly/matchers/OptionalMatchersTest.java | 26 ++++----- .../unruly/matchers/StreamMatchersTest.java | 57 +++++++++++-------- .../co/unruly/matchers/TimeMatchersTest.java | 4 +- 7 files changed, 72 insertions(+), 46 deletions(-) create mode 100644 .editorconfig 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..9bcf999 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,3 @@ language: java jdk: - - oraclejdk8 + - oraclejdk8 diff --git a/pom.xml b/pom.xml index 89c3006..b7cf185 100644 --- a/pom.xml +++ b/pom.xml @@ -171,4 +171,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..8b59fca 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 { @@ -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/OptionalMatchersTest.java b/src/test/java/co/unruly/matchers/OptionalMatchersTest.java index 3362952..3514842 100644 --- a/src/test/java/co/unruly/matchers/OptionalMatchersTest.java +++ b/src/test/java/co/unruly/matchers/OptionalMatchersTest.java @@ -22,7 +22,7 @@ public void empty_success() throws Exception { @Test public void empty_failure() throws Exception { - assertThat(Optional.of(1),not(OptionalMatchers.empty())); + assertThat(Optional.of(1), not(OptionalMatchers.empty())); } @Test @@ -42,7 +42,7 @@ public void contains_failureNonEmpty() throws Exception { @Test public void contains_failureEmpty() throws Exception { - assertThat(Optional.empty(),not(OptionalMatchers.contains("Woot"))); + assertThat(Optional.empty(), not(OptionalMatchers.contains("Woot"))); } @@ -53,7 +53,7 @@ public void contains_failureMessages() throws Exception { @Test public void containsMatcher_success() throws Exception { - assertThat(Optional.of(4),OptionalMatchers.contains(Matchers.greaterThan(3))); + assertThat(Optional.of(4), OptionalMatchers.contains(Matchers.greaterThan(3))); } @Test @@ -65,12 +65,12 @@ public void containsMatcher_success_typechecksWhenOptionalsArgIsStrictSubtype() @Test public void containsMatcher_failureDiffering() throws Exception { - assertThat(Optional.of(100),not(OptionalMatchers.contains(Matchers.lessThanOrEqualTo(19)))); + 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)))); + assertThat(Optional.empty(), not(OptionalMatchers.contains(Matchers.lessThanOrEqualTo(19)))); } @Test @@ -80,41 +80,41 @@ public void containsMatcher_failureMessage() throws Exception { @Test public void emptyInt_success() throws Exception { - assertThat(OptionalInt.empty(),OptionalMatchers.emptyInt()); + assertThat(OptionalInt.empty(), OptionalMatchers.emptyInt()); } @Test public void emptyInt_failure() throws Exception { - assertThat(OptionalInt.of(0),not(OptionalMatchers.emptyInt())); + assertThat(OptionalInt.of(0), not(OptionalMatchers.emptyInt())); } @Test public void containsInt_success() throws Exception { - assertThat(OptionalInt.of(0),OptionalMatchers.containsInt(0)); + assertThat(OptionalInt.of(0), OptionalMatchers.containsInt(0)); } @Test public void containsInt_failureDiffering() throws Exception { - assertThat(OptionalInt.of(0),not(OptionalMatchers.containsInt(1))); + assertThat(OptionalInt.of(0), not(OptionalMatchers.containsInt(1))); } @Test public void containsInt_failureEmpty() throws Exception { - assertThat(OptionalInt.empty(),not(OptionalMatchers.containsInt(1))); + assertThat(OptionalInt.empty(), not(OptionalMatchers.containsInt(1))); } @Test public void containsIntMatcher_success() throws Exception { - assertThat(OptionalInt.of(0),OptionalMatchers.containsInt(Matchers.equalTo(0))); + 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)))); + 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)))); + 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..0ae52f1 100644 --- a/src/test/java/co/unruly/matchers/StreamMatchersTest.java +++ b/src/test/java/co/unruly/matchers/StreamMatchersTest.java @@ -4,14 +4,23 @@ import org.hamcrest.Matchers; import org.junit.Test; -import java.util.stream.*; - -import static co.unruly.matchers.StreamMatchers.*; +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.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 co.unruly.matchers.StreamMatchers.startsWithInt; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.lessThanOrEqualTo; +import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertThat; public class StreamMatchersTest { @@ -52,7 +61,7 @@ public void equalTo_successEmpty() throws Exception { @Test public void empty_Success() throws Exception { - assertThat(Stream.empty(),empty()); + assertThat(Stream.empty(), empty()); } @Test @@ -67,7 +76,7 @@ public void equalToIntStream_success() throws Exception { @Test public void containsIntStream_success() throws Exception { - assertThat(IntStream.range(1, 4), contains(1,2,3)); + assertThat(IntStream.range(1, 4), contains(1, 2, 3)); } @Test @@ -87,7 +96,7 @@ public void contains_is_nullsafe() { @Test public void allMatch_success() throws Exception { - assertThat(Stream.of("bar","baz"),allMatch(containsString("a"))); + assertThat(Stream.of("bar","baz"), allMatch(containsString("a"))); } @Test @@ -100,32 +109,32 @@ public void allMatch_failure() throws Exception { @Test public void allMatchInt_failure() throws Exception { 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 { 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 { 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"))); + 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"))); + assertThat(Stream.of("bar", "bar", "foo", "grault", "garply", "waldo"), StreamMatchers.anyMatch(containsString("ald"))); } @Test @@ -137,32 +146,32 @@ public void anyMatch_failure() throws Exception { @Test public void anyMatchInt_success() throws Exception { - assertThat(IntStream.range(0,1_000),StreamMatchers.anyMatchInt(Matchers.equalTo(10))); + assertThat(IntStream.range(0, 1_000), StreamMatchers.anyMatchInt(Matchers.equalTo(10))); } @Test public void anyMatchInt_failure() throws Exception { - 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>]"); + 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))); + 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>]"); + 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))); + 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>]"); + 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 @@ -172,7 +181,7 @@ public void anyMatch_empty() throws Exception { @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)); + assertThat(Stream.iterate(0, i -> i + 1), startsWith(Stream.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), 10)); } @Test @@ -182,28 +191,28 @@ public void startsWithMatcher_successBothInfinite() throws Exception { @Test public void startsWithMatcherInt_successBothInfinite() throws Exception { - assertThat(IntStream.iterate(0,i -> i + 1), startsWith(IntStream.iterate(0, i -> i + 1), 10)); + 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)); + 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)); + 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")); + 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)); + assertThat(IntStream.range(0, Integer.MAX_VALUE), startsWithInt(0, 1, 2, 3, 4)); } @Test diff --git a/src/test/java/co/unruly/matchers/TimeMatchersTest.java b/src/test/java/co/unruly/matchers/TimeMatchersTest.java index 30dae50..976be87 100644 --- a/src/test/java/co/unruly/matchers/TimeMatchersTest.java +++ b/src/test/java/co/unruly/matchers/TimeMatchersTest.java @@ -65,7 +65,7 @@ public void betweenTemporal_failureBefore() throws Exception { @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>"); + 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 @@ -112,4 +112,4 @@ public void shouldNotCompileWithUnlikeTimes() throws Exception { public void shouldNotCompileWithNonTimes() throws Exception { assertThat(Integer.valueOf(3), TimeMatchers.after(Integer.valueOf(4))); }*/ -} \ No newline at end of file +} From 54390c0af45234a55a7ca7a530c740b168dec475 Mon Sep 17 00:00:00 2001 From: Rune Flobakk Date: Mon, 13 Apr 2020 14:35:12 +0200 Subject: [PATCH 02/12] Fix javadoc errors, and use doclint The doclint is set to "all except missing tags". It's a reasonable setting to avoid having to add redundant noise for self-explanatory paramters, types and such. --- pom.xml | 15 ++++++++++++--- .../java/co/unruly/matchers/StreamMatchers.java | 8 ++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index b7cf185..e60eeb1 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,6 @@ 1.8 1.8 UTF-8 - -Xdoclint:none @@ -61,6 +60,18 @@ + + + + maven-javadoc-plugin + 3.2.0 + + all,-missing + true + + + + org.apache.maven.plugins @@ -81,9 +92,7 @@ - org.apache.maven.plugins maven-javadoc-plugin - 2.9.1 attach-javadocs diff --git a/src/main/java/co/unruly/matchers/StreamMatchers.java b/src/main/java/co/unruly/matchers/StreamMatchers.java index 8b59fca..99d2ef7 100644 --- a/src/main/java/co/unruly/matchers/StreamMatchers.java +++ b/src/main/java/co/unruly/matchers/StreamMatchers.java @@ -360,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...) @@ -383,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...) From ba74fec6670034227cf4def97230c617c2421c5d Mon Sep 17 00:00:00 2001 From: Rune Flobakk Date: Mon, 13 Apr 2020 14:46:07 +0200 Subject: [PATCH 03/12] Reword description to include lambda-support --- pom.xml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index e60eeb1..d50e4bd 100644 --- a/pom.xml +++ b/pom.xml @@ -7,9 +7,7 @@ 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 From 4780bae21701f7b2d60e9e3ed78e366ec72351ef Mon Sep 17 00:00:00 2001 From: Rune Flobakk Date: Mon, 13 Apr 2020 15:24:57 +0200 Subject: [PATCH 04/12] Upgrade all Maven plugins Use strictly pluginManagement for settings versions in order to be able to invoke single plugins and get the same version as specified in the build, as well as configuration. Executions, in addition to plugins part of the default (jar) lifecycle, are configured in build/plugins. Configure versions-maven-plugin to be able to check for newer dependencies/plugin versions Add maven-enforcer-plugin to set minimal Maven version required by configured plugins. --- pom.xml | 110 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 78 insertions(+), 32 deletions(-) diff --git a/pom.xml b/pom.xml index d50e4bd..1e7b8d4 100644 --- a/pom.xml +++ b/pom.xml @@ -60,6 +60,33 @@ + + maven-clean-plugin + 3.1.0 + + + maven-enforcer-plugin + 3.0.0-M3 + + + + 3.0.5 + + + + + + maven-resources-plugin + 3.1.0 + + + maven-compiler-plugin + 3.8.1 + + + maven-source-plugin + 3.2.1 + maven-javadoc-plugin 3.2.0 @@ -68,18 +95,64 @@ 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 + + + - org.apache.maven.plugins maven-source-plugin - 2.2.1 attach-sources @@ -103,35 +176,9 @@ 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 @@ -149,7 +196,6 @@ - org.apache.maven.plugins maven-gpg-plugin 1.6 From 9b5be5dedd32126049f36a55c5c4bba8cd6a7571 Mon Sep 17 00:00:00 2001 From: Rune Flobakk Date: Mon, 13 Apr 2020 15:53:47 +0200 Subject: [PATCH 05/12] Upgade to JUnit 5 and Hamcrest 2.2 Change tests to being package scoped, and remov unnecessary exception declarations. --- pom.xml | 27 ++-- src/test/java/co/unruly/matchers/Helper.java | 8 +- .../co/unruly/matchers/Java8MatchersTest.java | 14 +- .../unruly/matchers/OptionalMatchersTest.java | 46 +++---- .../unruly/matchers/StreamMatchersTest.java | 122 +++++++++--------- .../co/unruly/matchers/TimeMatchersTest.java | 44 +++---- .../function/LambdaMethodFinderTest.java | 12 +- 7 files changed, 139 insertions(+), 134 deletions(-) diff --git a/pom.xml b/pom.xml index 1e7b8d4..bd712de 100644 --- a/pom.xml +++ b/pom.xml @@ -37,22 +37,27 @@ 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 diff --git a/src/test/java/co/unruly/matchers/Helper.java b/src/test/java/co/unruly/matchers/Helper.java index 27528b7..887a793 100644 --- a/src/test/java/co/unruly/matchers/Helper.java +++ b/src/test/java/co/unruly/matchers/Helper.java @@ -3,14 +3,14 @@ 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()); 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 3514842..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 { + 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 { + 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 { + 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 { + void containsMatcher_failureDiffering() { assertThat(Optional.of(100), not(OptionalMatchers.contains(Matchers.lessThanOrEqualTo(19)))); } @Test - public void containsMatcher_failureEmpty() throws Exception { + 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 { + void emptyInt_success() { assertThat(OptionalInt.empty(), OptionalMatchers.emptyInt()); } @Test - public void emptyInt_failure() throws Exception { + void emptyInt_failure() { assertThat(OptionalInt.of(0), not(OptionalMatchers.emptyInt())); } @Test - public void containsInt_success() throws Exception { + void containsInt_success() { assertThat(OptionalInt.of(0), OptionalMatchers.containsInt(0)); } @Test - public void containsInt_failureDiffering() throws Exception { + void containsInt_failureDiffering() { assertThat(OptionalInt.of(0), not(OptionalMatchers.containsInt(1))); } @Test - public void containsInt_failureEmpty() throws Exception { + void containsInt_failureEmpty() { assertThat(OptionalInt.empty(), not(OptionalMatchers.containsInt(1))); } @Test - public void containsIntMatcher_success() throws Exception { + void containsIntMatcher_success() { assertThat(OptionalInt.of(0), OptionalMatchers.containsInt(Matchers.equalTo(0))); } @Test - public void containsIntMatcher_failureEmpty() throws Exception { + void containsIntMatcher_failureEmpty() { assertThat(OptionalInt.empty(), not(OptionalMatchers.containsInt(Matchers.equalTo(1)))); } @Test - public void containsIntMatcher_failureDiffering() throws Exception { + 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 0ae52f1..c0183f5 100644 --- a/src/test/java/co/unruly/matchers/StreamMatchersTest.java +++ b/src/test/java/co/unruly/matchers/StreamMatchersTest.java @@ -2,7 +2,7 @@ import org.hamcrest.Matcher; import org.hamcrest.Matchers; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.stream.BaseStream; import java.util.stream.DoubleStream; @@ -17,206 +17,206 @@ import static co.unruly.matchers.StreamMatchers.equalTo; import static co.unruly.matchers.StreamMatchers.startsWith; 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; -import static org.junit.Assert.assertThat; -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 { + 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 { + 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 { + 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); 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); 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); Helper.testFailingMatcher(testData, matcher, "All to match >", "Item 3 failed to match: <3.0>"); } @Test - public void allMatch_empty() throws Exception { + void allMatch_empty() { assertThat(Stream.empty(), allMatch(containsString("foo"))); } @Test - public void anyMatch_success() throws Exception { + 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>]"); } @Test - public void anyMatchLong_success() throws Exception { + void anyMatchLong_success() { assertThat(LongStream.range(0, 1_000), StreamMatchers.anyMatchLong(Matchers.equalTo(10L))); } @Test - public void anyMatchLong_failure() throws Exception { + 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 { + void anyMatchDouble_success() { assertThat(DoubleStream.iterate(0d, i -> i + 1), StreamMatchers.anyMatchDouble(Matchers.equalTo(10d))); } @Test - public void anyMatchDouble_failure() throws Exception { + 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 { + 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 { + 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 { + 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 { + 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 { + 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 { + 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\"]"); @@ -224,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( @@ -334,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 976be87..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 { + 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))); }*/ } 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[])")); } From dfba3ca938bb235c55ac3bfaf36eac1ae93836f4 Mon Sep 17 00:00:00 2001 From: Rune Flobakk Date: Mon, 13 Apr 2020 15:58:39 +0200 Subject: [PATCH 06/12] Do not build test-jar --- pom.xml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pom.xml b/pom.xml index bd712de..8baa00f 100644 --- a/pom.xml +++ b/pom.xml @@ -182,16 +182,6 @@ org.sonatype.plugins nexus-staging-maven-plugin - - maven-jar-plugin - - - - test-jar - - - - From 5295067d76753576da9a9f9e07fd95e3f56d4659 Mon Sep 17 00:00:00 2001 From: Rune Flobakk Date: Mon, 13 Apr 2020 16:20:20 +0200 Subject: [PATCH 07/12] Deny unused declared & used but undeclared deps maven-dependency-plugin analyzes and failes the build if: - code is using a dependency which has been pulled in transitively, but not declared as a dependency. Code used is direct dependency, and must be declared as such. - a dependency has been declared, but the code is actually not using it. Thus, is can be removed (unless it is a runtime dependency, but the nature of this library makes this very unlikely). --- pom.xml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pom.xml b/pom.xml index 8baa00f..f40b001 100644 --- a/pom.xml +++ b/pom.xml @@ -80,6 +80,13 @@ + + maven-dependency-plugin + 3.1.2 + + true + + maven-resources-plugin 3.1.0 @@ -156,6 +163,16 @@ + + maven-dependency-plugin + + + + analyze-only + + + + maven-source-plugin From 1070dd7ea5f90eda9f0e3b5a7ea9e82168ab3ae6 Mon Sep 17 00:00:00 2001 From: Rune Flobakk Date: Wed, 15 Apr 2020 18:17:41 +0200 Subject: [PATCH 08/12] Build on Travis on OpenJDK 8 oraclejdk8 only gives error: Expected feature release number in range of 9 to 15, but got: 8 The command "~/bin/install-jdk.sh --target "/home/travis/oraclejdk8" --workspace "/home/travis/.cache/install-jdk" --feature "8" --license "BCL"" failed and exited with 3 during . Supposedly it is possible to use oraclejdk8 if forcing the dist on Travis to be "trusty", but it is EOL, so let's not start using something which is already deprecated and will eventually go away. OpenJDK works just fine. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9bcf999..b179f30 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,3 @@ language: java jdk: - - oraclejdk8 + - openjdk8 From df49d2ea5401b8f1bf5ec839370aee784e8a097d Mon Sep 17 00:00:00 2001 From: Rune Flobakk Date: Wed, 15 Apr 2020 18:26:52 +0200 Subject: [PATCH 09/12] Remove println cluttering up the build log --- src/test/java/co/unruly/matchers/Helper.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/co/unruly/matchers/Helper.java b/src/test/java/co/unruly/matchers/Helper.java index 887a793..3cf8ac5 100644 --- a/src/test/java/co/unruly/matchers/Helper.java +++ b/src/test/java/co/unruly/matchers/Helper.java @@ -13,7 +13,6 @@ static void testFailingMatcher(S testData, Matcher matcher, String expect 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))); } } From 91a644e27ca6c755dd6600b193a0155371b5990b Mon Sep 17 00:00:00 2001 From: Rune Flobakk Date: Wed, 15 Apr 2020 18:32:45 +0200 Subject: [PATCH 10/12] Cache .m2 to speed up Travis building --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index b179f30..edaa091 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,8 @@ language: java + +cache: + directories: + - $HOME/.m2 + jdk: - openjdk8 From c81bac75852e0f11d2ebb454c1c0a5cc8bae3a6d Mon Sep 17 00:00:00 2001 From: Rune Flobakk Date: Wed, 15 Apr 2020 18:37:21 +0200 Subject: [PATCH 11/12] Build using mvn verify Default build command on Travis is mvn test --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index edaa091..dcfbb6f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,3 +6,5 @@ cache: jdk: - openjdk8 + +script: mvn verify From a2b6a3435856f28390b9bb8598bf10c85a61377c Mon Sep 17 00:00:00 2001 From: Rune Flobakk Date: Wed, 15 Apr 2020 18:45:07 +0200 Subject: [PATCH 12/12] Only do one build on Travis Travis' default behaviour is to first do mvn install without tests to "install" dependencies, and then execute a normal build with tests. This is to align with the build lifecycle defined by Travis, but it is not necessary for a Maven build, which should do everything it needs by executing the idiomatic mvn clean install. This should even further speed up the build. --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dcfbb6f..f8b2798 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,4 +7,6 @@ cache: jdk: - openjdk8 -script: mvn verify +install: true + +script: mvn clean install