org.hamcrest
Class Matchers

java.lang.Object
  extended by org.hamcrest.Matchers

public class Matchers
extends java.lang.Object


Constructor Summary
Matchers()
           
 
Method Summary
static
<T> Matcher<T>
allOf(java.lang.Iterable<Matcher<? extends T>> matchers)
          Evaluates to true only if ALL of the passed in matchers evaluate to true.
static
<T> Matcher<T>
allOf(Matcher<? extends T>... matchers)
          Evaluates to true only if ALL of the passed in matchers evaluate to true.
static
<T> Matcher<T>
any(java.lang.Class<T> type)
          This matcher always evaluates to true.
static
<T> Matcher<T>
anyOf(java.lang.Iterable<Matcher<? extends T>> matchers)
          Evaluates to true if ANY of the passed in matchers evaluate to true.
static
<T> Matcher<T>
anyOf(Matcher<? extends T>... matchers)
          Evaluates to true if ANY of the passed in matchers evaluate to true.
static
<T> Matcher<T>
anything()
          This matcher always evaluates to true.
static
<T> Matcher<T>
anything(java.lang.String description)
          This matcher always evaluates to true.
static Matcher<java.lang.Double> closeTo(double operand, double error)
           
static Matcher<java.lang.String> containsString(java.lang.String substring)
           
static
<T> Matcher<T>
describedAs(java.lang.String description, Matcher<T> matcher, java.lang.Object... values)
          Wraps an existing matcher and overrides the description when it fails.
static Matcher<java.lang.String> endsWith(java.lang.String substring)
           
static
<T> Matcher<T>
equalTo(T operand)
          Is the value equal to another value, as tested by the Object.equals(java.lang.Object) invokedMethod?
static Matcher<java.lang.String> equalToIgnoringCase(java.lang.String string)
           
static Matcher<java.lang.String> equalToIgnoringWhiteSpace(java.lang.String string)
           
static Matcher<java.util.EventObject> eventFrom(java.lang.Class<? extends java.util.EventObject> eventClass, java.lang.Object source)
          Constructs an IsEventFrom Matcher that returns true for any object derived from eventClass announced by source.
static Matcher<java.util.EventObject> eventFrom(java.lang.Object source)
          Constructs an IsEventFrom Matcher that returns true for any object derived from EventObject announced by source .
static
<T extends java.lang.Comparable<T>>
Matcher<T>
greaterThan(T value)
           
static
<T extends java.lang.Comparable<T>>
Matcher<T>
greaterThanOrEqualTo(T value)
           
static
<K,V> Matcher<java.util.Map<K,V>>
hasEntry(K key, V value)
           
static
<K,V> Matcher<java.util.Map<K,V>>
hasEntry(Matcher<K> keyMatcher, Matcher<V> valueMatcher)
           
static
<T> Matcher<java.lang.Iterable<T>>
hasItem(Matcher<? extends T> elementMatcher)
           
static
<T> Matcher<java.lang.Iterable<T>>
hasItem(T element)
           
static
<T> Matcher<T[]>
hasItemInArray(Matcher<T> elementMatcher)
           
static
<T> Matcher<T[]>
hasItemInArray(T element)
           
static
<T> Matcher<java.lang.Iterable<T>>
hasItems(Matcher<? extends T>... elementMatchers)
           
static
<T> Matcher<java.lang.Iterable<T>>
hasItems(T... elements)
           
static
<K,V> Matcher<java.util.Map<K,V>>
hasKey(K key)
           
static
<K,V> Matcher<java.util.Map<K,V>>
hasKey(Matcher<K> keyMatcher)
           
static
<T> Matcher<T>
hasProperty(java.lang.String propertyName)
           
static
<T> Matcher<T>
hasProperty(java.lang.String propertyName, Matcher value)
           
static
<T> Matcher<T>
hasToString(Matcher<java.lang.String> toStringMatcher)
           
static
<K,V> Matcher<java.util.Map<K,V>>
hasValue(Matcher<V> valueMatcher)
           
static
<K,V> Matcher<java.util.Map<K,V>>
hasValue(V value)
           
static Matcher<org.w3c.dom.Node> hasXPath(java.lang.String xPath)
           
static Matcher<org.w3c.dom.Node> hasXPath(java.lang.String xPath, Matcher<java.lang.String> valueMatcher)
           
static Matcher<java.lang.Object> instanceOf(java.lang.Class<?> type)
          Is the value an instance of a particular type?
static Matcher<java.lang.Object> is(java.lang.Class<?> type)
          This is a shortcut to the frequently used is(instanceOf(SomeClass.class)).
static
<T> Matcher<T>
is(Matcher<T> matcher)
          Decorates another Matcher, retaining the behavior but allowing tests to be slightly more expressive.
static
<T> Matcher<T>
is(T value)
          This is a shortcut to the frequently used is(equalTo(x)).
static
<T> Matcher<T>
isIn(java.util.Collection<T> collection)
           
static
<T> Matcher<T>
isIn(T[] param1)
           
static
<T> Matcher<T>
isOneOf(T... elements)
           
static
<T extends java.lang.Comparable<T>>
Matcher<T>
lessThan(T value)
           
static
<T extends java.lang.Comparable<T>>
Matcher<T>
lessThanOrEqualTo(T value)
           
static
<T> Matcher<T>
not(Matcher<T> matcher)
          Inverts the rule.
static
<T> Matcher<T>
not(T value)
          This is a shortcut to the frequently used not(equalTo(x)).
static
<T> Matcher<T>
notNullValue()
          Matches if value is not null.
static
<T> Matcher<T>
notNullValue(java.lang.Class<T> type)
          Matches if value is not null.
static
<T> Matcher<T>
nullValue()
          Matches if value is null.
static
<T> Matcher<T>
nullValue(java.lang.Class<T> type)
          Matches if value is null.
static
<T> Matcher<T>
sameInstance(T object)
          Creates a new instance of IsSame
static Matcher<java.lang.String> startsWith(java.lang.String substring)
           
static
<T> Matcher<java.lang.Class<?>>
typeCompatibleWith(java.lang.Class<T> baseType)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Matchers

public Matchers()
Method Detail

is

public static <T> Matcher<T> is(Matcher<T> matcher)
Decorates another Matcher, retaining the behavior but allowing tests to be slightly more expressive. eg. assertThat(cheese, equalTo(smelly)) vs assertThat(cheese, is(equalTo(smelly)))


is

public static <T> Matcher<T> is(T value)
This is a shortcut to the frequently used is(equalTo(x)). eg. assertThat(cheese, is(equalTo(smelly))) vs assertThat(cheese, is(smelly))


is

public static Matcher<java.lang.Object> is(java.lang.Class<?> type)
This is a shortcut to the frequently used is(instanceOf(SomeClass.class)). eg. assertThat(cheese, is(instanceOf(Cheddar.class))) vs assertThat(cheese, is(Cheddar.class))


not

public static <T> Matcher<T> not(Matcher<T> matcher)
Inverts the rule.


not

public static <T> Matcher<T> not(T value)
This is a shortcut to the frequently used not(equalTo(x)). eg. assertThat(cheese, is(not(equalTo(smelly)))) vs assertThat(cheese, is(not(smelly)))


equalTo

public static <T> Matcher<T> equalTo(T operand)
Is the value equal to another value, as tested by the Object.equals(java.lang.Object) invokedMethod?


instanceOf

public static Matcher<java.lang.Object> instanceOf(java.lang.Class<?> type)
Is the value an instance of a particular type?


allOf

public static <T> Matcher<T> allOf(Matcher<? extends T>... matchers)
Evaluates to true only if ALL of the passed in matchers evaluate to true.


allOf

public static <T> Matcher<T> allOf(java.lang.Iterable<Matcher<? extends T>> matchers)
Evaluates to true only if ALL of the passed in matchers evaluate to true.


anyOf

public static <T> Matcher<T> anyOf(Matcher<? extends T>... matchers)
Evaluates to true if ANY of the passed in matchers evaluate to true.


anyOf

public static <T> Matcher<T> anyOf(java.lang.Iterable<Matcher<? extends T>> matchers)
Evaluates to true if ANY of the passed in matchers evaluate to true.


sameInstance

public static <T> Matcher<T> sameInstance(T object)
Creates a new instance of IsSame

Parameters:
object - The predicate evaluates to true only when the argument is this object.

anything

public static <T> Matcher<T> anything()
This matcher always evaluates to true.


anything

public static <T> Matcher<T> anything(java.lang.String description)
This matcher always evaluates to true.

Parameters:
description - A meaningful string used when describing itself.

any

public static <T> Matcher<T> any(java.lang.Class<T> type)
This matcher always evaluates to true. With type inference.


nullValue

public static <T> Matcher<T> nullValue()
Matches if value is null.


notNullValue

public static <T> Matcher<T> notNullValue()
Matches if value is not null.


nullValue

public static <T> Matcher<T> nullValue(java.lang.Class<T> type)
Matches if value is null. With type inference.


notNullValue

public static <T> Matcher<T> notNullValue(java.lang.Class<T> type)
Matches if value is not null. With type inference.


describedAs

public static <T> Matcher<T> describedAs(java.lang.String description,
                                         Matcher<T> matcher,
                                         java.lang.Object... values)
Wraps an existing matcher and overrides the description when it fails.


hasItemInArray

public static <T> Matcher<T[]> hasItemInArray(Matcher<T> elementMatcher)

hasItemInArray

public static <T> Matcher<T[]> hasItemInArray(T element)

hasItem

public static <T> Matcher<java.lang.Iterable<T>> hasItem(Matcher<? extends T> elementMatcher)

hasItem

public static <T> Matcher<java.lang.Iterable<T>> hasItem(T element)

hasItems

public static <T> Matcher<java.lang.Iterable<T>> hasItems(Matcher<? extends T>... elementMatchers)

hasItems

public static <T> Matcher<java.lang.Iterable<T>> hasItems(T... elements)

hasEntry

public static <K,V> Matcher<java.util.Map<K,V>> hasEntry(Matcher<K> keyMatcher,
                                                         Matcher<V> valueMatcher)

hasEntry

public static <K,V> Matcher<java.util.Map<K,V>> hasEntry(K key,
                                                         V value)

hasKey

public static <K,V> Matcher<java.util.Map<K,V>> hasKey(Matcher<K> keyMatcher)

hasKey

public static <K,V> Matcher<java.util.Map<K,V>> hasKey(K key)

hasValue

public static <K,V> Matcher<java.util.Map<K,V>> hasValue(Matcher<V> valueMatcher)

hasValue

public static <K,V> Matcher<java.util.Map<K,V>> hasValue(V value)

isIn

public static <T> Matcher<T> isIn(java.util.Collection<T> collection)

isIn

public static <T> Matcher<T> isIn(T[] param1)

isOneOf

public static <T> Matcher<T> isOneOf(T... elements)

closeTo

public static Matcher<java.lang.Double> closeTo(double operand,
                                                double error)

greaterThan

public static <T extends java.lang.Comparable<T>> Matcher<T> greaterThan(T value)

greaterThanOrEqualTo

public static <T extends java.lang.Comparable<T>> Matcher<T> greaterThanOrEqualTo(T value)

lessThan

public static <T extends java.lang.Comparable<T>> Matcher<T> lessThan(T value)

lessThanOrEqualTo

public static <T extends java.lang.Comparable<T>> Matcher<T> lessThanOrEqualTo(T value)

equalToIgnoringCase

public static Matcher<java.lang.String> equalToIgnoringCase(java.lang.String string)

equalToIgnoringWhiteSpace

public static Matcher<java.lang.String> equalToIgnoringWhiteSpace(java.lang.String string)

containsString

public static Matcher<java.lang.String> containsString(java.lang.String substring)

endsWith

public static Matcher<java.lang.String> endsWith(java.lang.String substring)

startsWith

public static Matcher<java.lang.String> startsWith(java.lang.String substring)

hasToString

public static <T> Matcher<T> hasToString(Matcher<java.lang.String> toStringMatcher)

typeCompatibleWith

public static <T> Matcher<java.lang.Class<?>> typeCompatibleWith(java.lang.Class<T> baseType)

eventFrom

public static Matcher<java.util.EventObject> eventFrom(java.lang.Class<? extends java.util.EventObject> eventClass,
                                                       java.lang.Object source)
Constructs an IsEventFrom Matcher that returns true for any object derived from eventClass announced by source.


eventFrom

public static Matcher<java.util.EventObject> eventFrom(java.lang.Object source)
Constructs an IsEventFrom Matcher that returns true for any object derived from EventObject announced by source .


hasProperty

public static <T> Matcher<T> hasProperty(java.lang.String propertyName)

hasProperty

public static <T> Matcher<T> hasProperty(java.lang.String propertyName,
                                         Matcher value)

hasXPath

public static Matcher<org.w3c.dom.Node> hasXPath(java.lang.String xPath,
                                                 Matcher<java.lang.String> valueMatcher)

hasXPath

public static Matcher<org.w3c.dom.Node> hasXPath(java.lang.String xPath)