Skip to content
This repository was archived by the owner on Sep 30, 2020. It is now read-only.
Open
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
11 changes: 10 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
language: java

cache:
directories:
- $HOME/.m2

jdk:
- oraclejdk8
- openjdk8

install: true

script: mvn clean install
185 changes: 125 additions & 60 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
<version>1.7-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/unruly/java-8-matchers</url>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<additionalparam>-Xdoclint:none</additionalparam>
</properties>

<developers>
Expand All @@ -40,37 +37,144 @@
<tag>HEAD</tag>
</scm>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.6.2</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>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</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-M4</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.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>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -81,9 +185,7 @@
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand All @@ -96,42 +198,6 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.5</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>2.5</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>2.19.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand All @@ -142,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 @@ -171,4 +236,4 @@
</snapshotRepository>
</distributionManagement>

</project>
</project>
22 changes: 13 additions & 9 deletions src/main/java/co/unruly/matchers/StreamMatchers.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -356,11 +360,11 @@ public void describeTo(Description description) {
/**
* The BaseStream must produce exactly the given expected items in order, and no more.
*
* For infinite BaseStreams see {@link #startsWith(T...)} or a primitive stream variant
* For infinite BaseStreams see {@link #startsWith(Object...)} or a primitive stream variant
* @param expectedMatchers Matchers for the items that should be produced by the BaseStream
* @param <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 @@ -379,11 +383,11 @@ protected boolean matchesSafely(S actual) {
/**
* The BaseStream must produce exactly the given expected items in order, and no more.
*
* For infinite BaseStreams see {@link #startsWith(T...)} or a primitive stream variant
* For infinite BaseStreams see {@link #startsWith(Object...)} or a primitive stream variant
* @param expected The items that should be produced by the BaseStream
* @param <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 @@ -671,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 @@ -704,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 Expand Up @@ -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;
}
Expand Down
9 changes: 4 additions & 5 deletions src/test/java/co/unruly/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
Loading