Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
20 changes: 12 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
187 changes: 125 additions & 62 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
<version>1.9-SNAPSHOT</version>

<name>java-8-matchers</name>

<description>Hamcrest matchers for JDK8's Optionals and Streams, and the java.time package</description>

<description>Hamcrest matchers for features introduced in Java 8: Optional, Stream, the Java Time API, and lambdas.</description>
<url>https://github.com/mrwilson/java-8-matchers</url>

<properties>
Expand Down Expand Up @@ -39,37 +37,144 @@
<tag>HEAD</tag>
</scm>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.7.0-M1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to bump up JUnit to 5, but I think bumping hamcrest from 1.x to 2.x is backwards incompatible.

So this is probably a major version bump for this library if this change makes it in. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, strictly speaking, yes. Though the only parts of Hamcrest used by java-8-matchers are:

  • org.hamcrest.Matchers
  • org.hamcrest.Description
  • org.hamcrest.TypeSafeDiagnosingMatcher
  • org.hamcrest.TypeSafeMatcher

Screenshot 2020-07-28 at 22 43 00

These classes are already in Hamcrest 1.3, and the APIs of these have not changed in 2.2. The upgrade to Hamcrest 2.2 did not result in any changes in src/main/java. If anybody uses java-8-matchers with Hamcrest 1.3 (typically depends directly on Hamcrest 1.3 as well as java-8-matchers), they will work together.

Though there are no mechanisms to tell us if backwards compatibility is broken at a later time, with changes in the library down the road. So the most correct thing may be to bump the major version. But merging this PR will actually not introduce any incompatibility with Hamcrest 1.3.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Myself, I really don't have any preference on bumping major version or not, as this is a type of library which is probably mostly, or maybe even always, used as a direct test-dependency, and not pulled in as a transitive dependency of something else. So upgrading java-8-matchers is just bumping the version from 1.x to 2, and I don't see the potential of any major version convergence conflicts with other dependencies which themselves may depend on 1.x of java-8-matchers.

As I see it, there should be no big deal to bumping the major version for a release after merging this PR.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll probably make a major version bump then, so at least v1 = Hamcrest 1.x, v2 = Hamcrest 2.x

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about merging #6 and #7 first to create a 1.9 release?

</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<rules>
<requireMavenVersion>
<version>3.0.5</version>
</requireMavenVersion>
</rules>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<failOnWarning>true</failOnWarning>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<doclint>all,-missing</doclint>
<quiet>true</quiet>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M1</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile>
<releaseProfiles>release</releaseProfiles>
<goals>deploy</goals>
<mavenExecutorId>forked-path</mavenExecutorId>
</configuration>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.7</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>analyze-only</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -80,12 +185,7 @@
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<doclint>none</doclint>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -98,42 +198,6 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<useReleaseProfile>false</useReleaseProfile>
<releaseProfiles>release</releaseProfiles>
<goals>deploy</goals>
<mavenExecutorId>forked-path</mavenExecutorId>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand All @@ -144,7 +208,6 @@
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
Expand Down Expand Up @@ -173,4 +236,4 @@
</snapshotRepository>
</distributionManagement>

</project>
</project>
6 changes: 3 additions & 3 deletions src/main/java/uk/co/probablyfine/matchers/Java8Matchers.java
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/uk/co/probablyfine/matchers/StreamMatchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an automatic fix suggested by doclint? Since it specifies @type <T> The type of items I'd expect it to be okay with the generic rather than Object

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an automatic fix, but seems to be the correct way of referencing a generically typed vararg parameter. Using #startsWith(T...) generates the following error from the javadoc-tool:

Error while generating Javadoc:
Exit code: 1 - StreamMatchers.java:363: error: reference not found
      * For infinite BaseStreams see {@link #startsWith(T...)} or a primitive stream variant
                                            ^
StreamMatchers.java:373: warning - Tag @link: can't find startsWith(T...) in uk.co.probablyfine.matchers.StreamMatchers

* @param expectedMatchers Matchers for the items that should be produced by the BaseStream
* @param <T> The type of items
* @param <S> The type of the BaseStream
* @see #startsWith(T...)
* @see #startsWith(Object...)
* @see #startsWithInt(int...)
* @see #startsWithLong(long...)
* @see #startsWithDouble(double...)
Expand All @@ -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 <T> The type of items
* @param <S> The type of the BaseStream
* @see #startsWith(T...)
* @see #startsWith(Object...)
* @see #startsWithInt(int...)
* @see #startsWithLong(long...)
* @see #startsWithDouble(double...)
Expand Down Expand Up @@ -675,7 +675,7 @@ boolean remainingItemsEqual(Iterator<T> expectedIterator, Iterator<T> 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);
}
}
Expand Down Expand Up @@ -708,7 +708,7 @@ boolean remainingItemsMatch(Iterator<Matcher<T>> expectedIterator, Iterator<T> a
expectedAccumulator.add(nextExpected);
T nextActual = actualIterator.next();
actualAccumulator.add(nextActual);
if(nextExpected.matches(nextActual)) {
if (nextExpected.matches(nextActual)) {
return remainingItemsMatch(expectedIterator, actualIterator);
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/test/java/uk/co/probablyfine/matchers/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <S> void testFailingMatcher(S testData, Matcher<S> 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)));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down
Loading