org.hamcrest.core
Class AnyOf<T>

java.lang.Object
  extended by org.hamcrest.BaseMatcher<T>
      extended by org.hamcrest.core.AnyOf<T>
All Implemented Interfaces:
Matcher<T>, SelfDescribing

public class AnyOf<T>
extends BaseMatcher<T>

Calculates the logical disjunction of multiple matchers. Evaluation is shortcut, so subsequent matchers are not called if an earlier matcher returns true.


Constructor Summary
AnyOf(Iterable<Matcher<? super T>> matchers)
           
 
Method Summary
static
<T> AnyOf<T>
anyOf(Iterable<Matcher<? super T>> matchers)
          Creates a matcher that matches if the examined object matches ANY of the specified matchers.
static
<T> AnyOf<T>
anyOf(Matcher<? super T>... matchers)
          Creates a matcher that matches if the examined object matches ANY of the specified matchers.
static
<T> AnyOf<T>
anyOf(Matcher<T> first, Matcher<? super T> second)
          Creates a matcher that matches if the examined object matches ANY of the specified matchers.
static
<T> AnyOf<T>
anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third)
          Creates a matcher that matches if the examined object matches ANY of the specified matchers.
static
<T> AnyOf<T>
anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth)
          Creates a matcher that matches if the examined object matches ANY of the specified matchers.
static
<T> AnyOf<T>
anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, Matcher<? super T> fifth)
          Creates a matcher that matches if the examined object matches ANY of the specified matchers.
static
<T> AnyOf<T>
anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, Matcher<? super T> fifth, Matcher<? super T> sixth)
          Creates a matcher that matches if the examined object matches ANY of the specified matchers.
 void describeTo(Description description)
          Generates a description of the object.
 void describeTo(Description description, String operator)
           
 boolean matches(Object o)
          Evaluates the matcher for argument item.
protected  boolean matches(Object o, boolean shortcut)
           
 
Methods inherited from class org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, describeMismatch, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AnyOf

public AnyOf(Iterable<Matcher<? super T>> matchers)
Method Detail

matches

public boolean matches(Object o)
Description copied from interface: Matcher
Evaluates the matcher for argument item.

This method matches against Object, instead of the generic type T. This is because the caller of the Matcher does not know at runtime what the type is (because of type erasure with Java generics). It is down to the implementations to check the correct type.

Specified by:
matches in interface Matcher<T>
Parameters:
o - the object against which the matcher is evaluated.
Returns:
true if item matches, otherwise false.
See Also:
BaseMatcher

describeTo

public void describeTo(Description description)
Description copied from interface: SelfDescribing
Generates a description of the object. The description may be part of a a description of a larger object of which this is just a component, so it should be worded appropriately.

Specified by:
describeTo in interface SelfDescribing
Parameters:
description - The description to be built or appended to.

anyOf

public static <T> AnyOf<T> anyOf(Iterable<Matcher<? super T>> matchers)
Creates a matcher that matches if the examined object matches ANY of the specified matchers.

For example:

assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))


anyOf

public static <T> AnyOf<T> anyOf(Matcher<? super T>... matchers)
Creates a matcher that matches if the examined object matches ANY of the specified matchers.

For example:

assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))


anyOf

public static <T> AnyOf<T> anyOf(Matcher<T> first,
                                 Matcher<? super T> second)
Creates a matcher that matches if the examined object matches ANY of the specified matchers.

For example:

assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))


anyOf

public static <T> AnyOf<T> anyOf(Matcher<T> first,
                                 Matcher<? super T> second,
                                 Matcher<? super T> third)
Creates a matcher that matches if the examined object matches ANY of the specified matchers.

For example:

assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))


anyOf

public static <T> AnyOf<T> anyOf(Matcher<T> first,
                                 Matcher<? super T> second,
                                 Matcher<? super T> third,
                                 Matcher<? super T> fourth)
Creates a matcher that matches if the examined object matches ANY of the specified matchers.

For example:

assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))


anyOf

public static <T> AnyOf<T> anyOf(Matcher<T> first,
                                 Matcher<? super T> second,
                                 Matcher<? super T> third,
                                 Matcher<? super T> fourth,
                                 Matcher<? super T> fifth)
Creates a matcher that matches if the examined object matches ANY of the specified matchers.

For example:

assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))


anyOf

public static <T> AnyOf<T> anyOf(Matcher<T> first,
                                 Matcher<? super T> second,
                                 Matcher<? super T> third,
                                 Matcher<? super T> fourth,
                                 Matcher<? super T> fifth,
                                 Matcher<? super T> sixth)
Creates a matcher that matches if the examined object matches ANY of the specified matchers.

For example:

assertThat("myValue", anyOf(startsWith("foo"), containsString("Val")))


matches

protected boolean matches(Object o,
                          boolean shortcut)

describeTo

public void describeTo(Description description,
                       String operator)


Copyright © 2002–2017 JUnit. All rights reserved.