Skip to content

Commit ef2c6f5

Browse files
dgrouptumbarumba
authored andcommitted
AllOf/AnyOf: Pass matchers to ctor using varargs
1 parent f337a05 commit ef2c6f5

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

hamcrest/src/main/java/org/hamcrest/core/AllOf.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ public class AllOf<T> extends DiagnosingMatcher<T> {
1414

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

17+
@SafeVarargs
18+
public AllOf(Matcher<? super T> ... matchers) {
19+
this(Arrays.asList(matchers));
20+
}
21+
1722
public AllOf(Iterable<Matcher<? super T>> matchers) {
1823
this.matchers = matchers;
1924
}

hamcrest/src/main/java/org/hamcrest/core/AnyOf.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
*/
1212
public class AnyOf<T> extends ShortcutCombination<T> {
1313

14+
@SafeVarargs
15+
public AnyOf(Matcher<? super T> ... matchers) {
16+
this(Arrays.asList(matchers));
17+
}
18+
1419
public AnyOf(Iterable<Matcher<? super T>> matchers) {
1520
super(matchers);
1621
}

hamcrest/src/test/java/org/hamcrest/core/AllOfTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
import org.junit.Test;
55

66
import static org.hamcrest.AbstractMatcherTest.*;
7+
import static org.hamcrest.MatcherAssert.assertThat;
78
import static org.hamcrest.core.AllOf.allOf;
89
import static org.hamcrest.core.Is.is;
910
import static org.hamcrest.core.IsEqual.equalTo;
1011
import static org.hamcrest.core.IsNull.notNullValue;
12+
import static org.hamcrest.core.StringContains.containsString;
1113
import static org.hamcrest.core.StringEndsWith.endsWith;
1214
import static org.hamcrest.core.StringStartsWith.startsWith;
1315

@@ -60,4 +62,9 @@ public final class AllOfTest {
6062
hasAMismatchDescriptionDescribingTheFirstFailingMatch() {
6163
assertMismatchDescription("\"good\" was \"bad\"", allOf(equalTo("bad"), equalTo("good")), "bad");
6264
}
65+
66+
@Test public void
67+
varargs(){
68+
assertThat("the text!", new AllOf<>(startsWith("the"), containsString("text"), endsWith("!")));
69+
}
6370
}

hamcrest/src/test/java/org/hamcrest/core/AnyOfTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.junit.Test;
55

66
import static org.hamcrest.AbstractMatcherTest.*;
7+
import static org.hamcrest.MatcherAssert.assertThat;
78
import static org.hamcrest.core.AnyOf.anyOf;
89
import static org.hamcrest.core.IsEqual.equalTo;
910
import static org.hamcrest.core.StringEndsWith.endsWith;
@@ -53,4 +54,9 @@ public final class AnyOfTest {
5354
assertDescription("(\"good\" or \"bad\" or \"ugly\")",
5455
anyOf(equalTo("good"), equalTo("bad"), equalTo("ugly")));
5556
}
57+
58+
@Test public void
59+
varargs(){
60+
assertThat("the text!", new AnyOf<>(startsWith("the"), endsWith(".")));
61+
}
5662
}

0 commit comments

Comments
 (0)