Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AllOf/AnyOf: Pass the matchers to constructor using varargs #245

Merged
merged 1 commit into from Feb 2, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions hamcrest/src/main/java/org/hamcrest/core/AllOf.java
Expand Up @@ -14,6 +14,11 @@ public class AllOf<T> extends DiagnosingMatcher<T> {

private final Iterable<Matcher<? super T>> matchers;

@SafeVarargs
public AllOf(Matcher<? super T> ... matchers) {
this(Arrays.asList(matchers));
}

public AllOf(Iterable<Matcher<? super T>> matchers) {
this.matchers = matchers;
}
Expand Down
5 changes: 5 additions & 0 deletions hamcrest/src/main/java/org/hamcrest/core/AnyOf.java
Expand Up @@ -11,6 +11,11 @@
*/
public class AnyOf<T> extends ShortcutCombination<T> {

@SafeVarargs
public AnyOf(Matcher<? super T> ... matchers) {
this(Arrays.asList(matchers));
}

public AnyOf(Iterable<Matcher<? super T>> matchers) {
super(matchers);
}
Expand Down
7 changes: 7 additions & 0 deletions hamcrest/src/test/java/org/hamcrest/core/AllOfTest.java
Expand Up @@ -4,10 +4,12 @@
import org.junit.Test;

import static org.hamcrest.AbstractMatcherTest.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.AllOf.allOf;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.StringContains.containsString;
import static org.hamcrest.core.StringEndsWith.endsWith;
import static org.hamcrest.core.StringStartsWith.startsWith;

Expand Down Expand Up @@ -60,4 +62,9 @@ public final class AllOfTest {
hasAMismatchDescriptionDescribingTheFirstFailingMatch() {
assertMismatchDescription("\"good\" was \"bad\"", allOf(equalTo("bad"), equalTo("good")), "bad");
}

@Test public void
varargs(){
assertThat("the text!", new AllOf<>(startsWith("the"), containsString("text"), endsWith("!")));
}
}
6 changes: 6 additions & 0 deletions hamcrest/src/test/java/org/hamcrest/core/AnyOfTest.java
Expand Up @@ -4,6 +4,7 @@
import org.junit.Test;

import static org.hamcrest.AbstractMatcherTest.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.AnyOf.anyOf;
import static org.hamcrest.core.IsEqual.equalTo;
import static org.hamcrest.core.StringEndsWith.endsWith;
Expand Down Expand Up @@ -53,4 +54,9 @@ public final class AnyOfTest {
assertDescription("(\"good\" or \"bad\" or \"ugly\")",
anyOf(equalTo("good"), equalTo("bad"), equalTo("ugly")));
}

@Test public void
varargs(){
assertThat("the text!", new AnyOf<>(startsWith("the"), endsWith(".")));
}
}