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 fc863f5..c031ad1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,14 @@ language: java + +cache: + directories: + - $HOME/.m2 + jdk: - - openjdk8 - - openjdk9 - - openjdk11 - -matrix: - allow_failures: - - jdk: openjdk9 - - jdk: openjdk11 + - openjdk8 + - openjdk9 + - openjdk11 + +install: true + +script: mvn clean install diff --git a/pom.xml b/pom.xml index b895531..8877c4c 100644 --- a/pom.xml +++ b/pom.xml @@ -7,9 +7,7 @@ 1.9-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/mrwilson/java-8-matchers @@ -39,37 +37,144 @@ HEAD + + + + org.junit + junit-bom + 5.7.0-M1 + pom + import + + + + org.hamcrest - hamcrest-core - 1.3 + hamcrest + 2.2 - junit - junit - 4.13 - 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-M5 + + + 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.8.1 + maven-enforcer-plugin + + + + enforce + + + + + + maven-dependency-plugin + + + + analyze-only + + + - org.apache.maven.plugins maven-source-plugin - 3.2.1 attach-sources @@ -80,12 +185,7 @@ - org.apache.maven.plugins maven-javadoc-plugin - 3.2.0 - - none - attach-javadocs @@ -98,42 +198,6 @@ org.sonatype.plugins nexus-staging-maven-plugin - 1.6.8 - true - - ossrh - https://oss.sonatype.org/ - true - - - - org.apache.maven.plugins - maven-release-plugin - 3.0.0-M1 - - true - false - release - deploy - forked-path - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M5 - - - org.apache.maven.plugins - maven-jar-plugin - 3.2.0 - - - - test-jar - - - @@ -144,7 +208,6 @@ - org.apache.maven.plugins maven-gpg-plugin 1.6 @@ -173,4 +236,4 @@ - \ No newline at end of file + diff --git a/src/main/java/uk/co/probablyfine/matchers/Java8Matchers.java b/src/main/java/uk/co/probablyfine/matchers/Java8Matchers.java index 28b1cff..ccceb18 100644 --- a/src/main/java/uk/co/probablyfine/matchers/Java8Matchers.java +++ b/src/main/java/uk/co/probablyfine/matchers/Java8Matchers.java @@ -1,15 +1,15 @@ package uk.co.probablyfine.matchers; -import uk.co.probablyfine.matchers.function.DescribableFunction; -import uk.co.probablyfine.matchers.function.DescribablePredicate; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeDiagnosingMatcher; +import uk.co.probablyfine.matchers.function.DescribableFunction; +import uk.co.probablyfine.matchers.function.DescribablePredicate; import java.util.function.Function; +import static org.hamcrest.Matchers.is; import static uk.co.probablyfine.matchers.internal.DescriptionUtils.withPrefixedArticle; -import static org.hamcrest.CoreMatchers.is; public final class Java8Matchers { diff --git a/src/main/java/uk/co/probablyfine/matchers/StreamMatchers.java b/src/main/java/uk/co/probablyfine/matchers/StreamMatchers.java index 9907658..098664c 100644 --- a/src/main/java/uk/co/probablyfine/matchers/StreamMatchers.java +++ b/src/main/java/uk/co/probablyfine/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...) @@ -675,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); } } @@ -708,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); } } diff --git a/src/test/java/uk/co/probablyfine/matchers/Helper.java b/src/test/java/uk/co/probablyfine/matchers/Helper.java index d5cd3df..1d8c23c 100644 --- a/src/test/java/uk/co/probablyfine/matchers/Helper.java +++ b/src/test/java/uk/co/probablyfine/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/uk/co/probablyfine/matchers/Java8MatchersTest.java b/src/test/java/uk/co/probablyfine/matchers/Java8MatchersTest.java index d1cfa18..34757dc 100644 --- a/src/test/java/uk/co/probablyfine/matchers/Java8MatchersTest.java +++ b/src/test/java/uk/co/probablyfine/matchers/Java8MatchersTest.java @@ -1,12 +1,11 @@ package uk.co.probablyfine.matchers; -import org.junit.Test; -import static uk.co.probablyfine.matchers.Java8Matchers.where; -import static uk.co.probablyfine.matchers.Java8Matchers.whereNot; +import org.junit.jupiter.api.Test; + +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 { diff --git a/src/test/java/uk/co/probablyfine/matchers/OptionalMatchersTest.java b/src/test/java/uk/co/probablyfine/matchers/OptionalMatchersTest.java index 654e8f2..a59f0bf 100644 --- a/src/test/java/uk/co/probablyfine/matchers/OptionalMatchersTest.java +++ b/src/test/java/uk/co/probablyfine/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/uk/co/probablyfine/matchers/StreamMatchersTest.java b/src/test/java/uk/co/probablyfine/matchers/StreamMatchersTest.java index 29da849..bf61b53 100644 --- a/src/test/java/uk/co/probablyfine/matchers/StreamMatchersTest.java +++ b/src/test/java/uk/co/probablyfine/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 uk.co.probablyfine.matchers.function.DescribableFunction; import java.util.stream.BaseStream; @@ -11,208 +11,209 @@ import java.util.stream.LongStream; import java.util.stream.Stream; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.lessThanOrEqualTo; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertThat; import static uk.co.probablyfine.matchers.Java8Matchers.where; -public class StreamMatchersTest { +class StreamMatchersTest { + @Test - public void equalTo_failureDifferingSingleItem() throws Exception { + void equalTo_failureDifferingSingleItem() { assertThat(Stream.of("a"), is(not(StreamMatchers.equalTo(Stream.of("b"))))); } @Test - public void contains_failureDifferingSingleItem() throws Exception { + void contains_failureDifferingSingleItem() { assertThat(Stream.of("a"), not(StreamMatchers.contains("b"))); } @Test - public void equalTo_failureDifferingLength() throws Exception { + void equalTo_failureDifferingLength() { assertThat(Stream.of("a"), is(not(StreamMatchers.equalTo(Stream.of("a", "b"))))); } @Test - public void contains_failureDifferingLength() throws Exception { + void contains_failureDifferingLength() { assertThat(Stream.of("a"), not(StreamMatchers.contains("a", "b"))); } @Test - public void equalTo_failureDifferingItems() throws Exception { + void equalTo_failureDifferingItems() { assertThat(Stream.of("a","c"), is(not(StreamMatchers.equalTo(Stream.of("a", "b"))))); } @Test - public void contains_failureDifferingItems() throws Exception { + void contains_failureDifferingItems() { assertThat(Stream.of("a","c"), not(StreamMatchers.contains("a", "b"))); } @Test - public void equalTo_successEmpty() throws Exception { + void equalTo_successEmpty() { assertThat(Stream.empty(), StreamMatchers.equalTo(Stream.empty())); } @Test - public void empty_Success() throws Exception { + void empty_Success() { assertThat(Stream.empty(), StreamMatchers.empty()); } @Test - public void empty_Failure() throws Exception { + void empty_Failure() { Helper.testFailingMatcher(Stream.of(3), StreamMatchers.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), StreamMatchers.equalTo(IntStream.range(1, 10))); } @Test - public void containsIntStream_success() throws Exception { - assertThat(IntStream.range(1, 4), StreamMatchers.contains(1,2,3)); + void containsIntStream_success() { + assertThat(IntStream.range(1, 4), StreamMatchers.contains(1, 2, 3)); } @Test - public void equalTo_successManyItems() throws Exception { + void equalTo_successManyItems() { assertThat(Stream.of("a", "b", "c"), StreamMatchers.equalTo(Stream.of("a", "b", "c"))); } @Test - public void contains_successManyItems() throws Exception { + void contains_successManyItems() { assertThat(Stream.of("a", "b", "c"), StreamMatchers.contains("a", "b", "c")); } @Test - public void contains_is_nullsafe() { + void contains_is_nullsafe() { assertThat(Stream.of("a", null, "c"), StreamMatchers.contains("a", null, "c")); } @Test - public void allMatch_success() throws Exception { + void allMatch_success() { assertThat(Stream.of("bar","baz"), StreamMatchers.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 { + void allMatch_empty() { assertThat(Stream.empty(), StreamMatchers.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(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(equalTo(10L))); + void anyMatchLong_success() { + assertThat(LongStream.range(0, 1_000), StreamMatchers.anyMatchLong(equalTo(10L))); } @Test - public void anyMatchLong_failure() throws Exception { - Helper.testFailingMatcher(LongStream.range(0,5), StreamMatchers.anyMatchLong(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(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(equalTo(10d))); + void anyMatchDouble_success() { + assertThat(DoubleStream.iterate(0d, i -> i + 1), StreamMatchers.anyMatchDouble(equalTo(10d))); } @Test - public void anyMatchDouble_failure() throws Exception { - Helper.testFailingMatcher(DoubleStream.iterate(0d,i -> i + 1).limit(5), StreamMatchers.anyMatchDouble(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(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 { - assertThat(Stream.empty(), Matchers.not(StreamMatchers.anyMatch(containsString("foo")))); + void anyMatch_empty() { + assertThat(Stream.empty(),not(StreamMatchers.anyMatch(containsString("foo")))); } @Test - public void startsWithMatcher_success() throws Exception { - assertThat(Stream.iterate(0,i -> i + 1), StreamMatchers.startsWith(Stream.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), 10)); + void startsWithMatcher_success() { + assertThat(Stream.iterate(0, i -> i + 1), StreamMatchers.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), StreamMatchers.startsWith(Stream.iterate(0, i -> i + 1), 10)); } @Test - public void startsWithMatcherInt_successBothInfinite() throws Exception { - assertThat(IntStream.iterate(0,i -> i + 1), StreamMatchers.startsWith(IntStream.iterate(0, i -> i + 1), 10)); + void startsWithMatcherInt_successBothInfinite() { + assertThat(IntStream.iterate(0, i -> i + 1), StreamMatchers.startsWith(IntStream.iterate(0, i -> i + 1), 10)); } @Test - public void startsWithMatcherLong_successBothInfinite() throws Exception { - assertThat(LongStream.iterate(0,i -> i + 1), StreamMatchers.startsWith(LongStream.iterate(0, i -> i + 1), 10)); + void startsWithMatcherLong_successBothInfinite() { + assertThat(LongStream.iterate(0, i -> i + 1), StreamMatchers.startsWith(LongStream.iterate(0, i -> i + 1), 10)); } @Test - public void startsWithMatcherDouble_successBothInfinite() throws Exception { - assertThat(DoubleStream.iterate(0,i -> i + 1), StreamMatchers.startsWith(DoubleStream.iterate(0, i -> i + 1), 10)); + void startsWithMatcherDouble_successBothInfinite() { + assertThat(DoubleStream.iterate(0, i -> i + 1), StreamMatchers.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"), StreamMatchers.startsWith("a", "b", "c", "d", "e")); + void startsWithItems_success() { + assertThat(Stream.of("a", "b", "c", "d", "e", "f", "g", "h"), StreamMatchers.startsWith("a", "b", "c", "d", "e")); } @Test - public void startsWithItemsIntStream_success() throws Exception { - assertThat(IntStream.range(0,Integer.MAX_VALUE), StreamMatchers.startsWithInt(0, 1, 2, 3, 4)); + void startsWithItemsIntStream_success() { + assertThat(IntStream.range(0, Integer.MAX_VALUE), StreamMatchers.startsWithInt(0, 1, 2, 3, 4)); } @Test - public void equalTo_failureMessages() throws Exception { + void equalTo_failureMessages() { Matcher> matcher = StreamMatchers.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\"]"); @@ -241,106 +242,106 @@ public void contains_handles_types() { @Test - public void contains_failureMessages() throws Exception { + void contains_failureMessages() { Stream testData = Stream.of("a", "b", "c", "d", "e"); Matcher> matcher = StreamMatchers.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 = StreamMatchers.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(equalTo(10),100)); } @Test - public void startsWithAll_fail() throws Exception { + void startsWithAll_fail() { Helper.testFailingMatcher(Stream.generate(() -> 11), StreamMatchers.startsWithAll(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(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(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(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(equalTo(10), 100)); } @Test - public void startsWithAny_fail() throws Exception { + void startsWithAny_fail() { Helper.testFailingMatcher(Stream.iterate(0, i -> i + 1), StreamMatchers.startsWithAny(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(equalTo(10), 100)); } @Test - public void startsWithAnyInt_fail() throws Exception { + void startsWithAnyInt_fail() { Helper.testFailingMatcher(IntStream.iterate(0, i -> i + 1), StreamMatchers.startsWithAnyInt(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(equalTo(10L), 100)); } @Test - public void startsWithAnyLong_fail() throws Exception { + void startsWithAnyLong_fail() { Helper.testFailingMatcher(LongStream.iterate(0, i -> i + 1), StreamMatchers.startsWithAnyLong(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(equalTo(10d), 100)); } @Test - public void startsWithAnyDouble_fail() throws Exception { + void startsWithAnyDouble_fail() { Helper.testFailingMatcher(DoubleStream.iterate(0, i -> i + 1), StreamMatchers.startsWithAnyDouble(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( @@ -351,7 +352,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/uk/co/probablyfine/matchers/TimeMatchersTest.java b/src/test/java/uk/co/probablyfine/matchers/TimeMatchersTest.java index df60d0b..cad24b5 100644 --- a/src/test/java/uk/co/probablyfine/matchers/TimeMatchersTest.java +++ b/src/test/java/uk/co/probablyfine/matchers/TimeMatchersTest.java @@ -1,16 +1,16 @@ package uk.co.probablyfine.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/uk/co/probablyfine/matchers/function/LambdaMethodFinderTest.java b/src/test/java/uk/co/probablyfine/matchers/function/LambdaMethodFinderTest.java index 0d65067..312a097 100644 --- a/src/test/java/uk/co/probablyfine/matchers/function/LambdaMethodFinderTest.java +++ b/src/test/java/uk/co/probablyfine/matchers/function/LambdaMethodFinderTest.java @@ -1,25 +1,25 @@ package uk.co.probablyfine.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[])")); }