/
AnyOf.java
51 lines (42 loc) · 1.47 KB
/
AnyOf.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package org.hamcrest.core;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import java.util.Arrays;
/**
* Calculates the logical disjunction of multiple matchers. Evaluation is shortcut, so
* subsequent matchers are not called if an earlier matcher returns <code>true</code>.
*/
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);
}
@Override
public boolean matches(Object o) {
return matches(o, true);
}
@Override
public void describeTo(Description description) {
describeTo(description, "or");
}
/**
* Creates a matcher that matches if the examined object matches <b>ANY</b> of the specified matchers.
* For example:
* <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>
*/
public static <T> AnyOf<T> anyOf(Iterable<Matcher<? super T>> matchers) {
return new AnyOf<>(matchers);
}
/**
* Creates a matcher that matches if the examined object matches <b>ANY</b> of the specified matchers.
* For example:
* <pre>assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))</pre>
*/
@SafeVarargs
public static <T> AnyOf<T> anyOf(Matcher<? super T>... matchers) {
return anyOf(Arrays.asList(matchers));
}
}