org.hamcrest
Class CoreMatchers

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

public class CoreMatchers
extends Object


Constructor Summary
CoreMatchers()
           
 
Method Summary
static
<T> Matcher<T>
allOf(Iterable<Matcher<? super T>> matchers)
          Evaluates to true only if ALL of the passed in matchers evaluate to true.
static
<T> Matcher<T>
allOf(Matcher<? super T>... matchers)
          Evaluates to true only if ALL of the passed in matchers evaluate to true.
static
<T> Matcher<T>
allOf(Matcher<T> first, Matcher<? super T> second)
          Evaluates to true only if ALL of the passed in matchers evaluate to true.
static
<T> Matcher<T>
allOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third)
          Evaluates to true only if ALL of the passed in matchers evaluate to true.
static
<T> Matcher<T>
allOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth)
          Evaluates to true only if ALL of the passed in matchers evaluate to true.
static
<T> Matcher<T>
allOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, Matcher<? super T> fifth)
          Evaluates to true only if ALL of the passed in matchers evaluate to true.
static
<T> Matcher<T>
allOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, Matcher<? super T> fifth, Matcher<? super T> sixth)
          Evaluates to true only if ALL of the passed in matchers evaluate to true.
static
<T> Matcher<T>
any(Class<T> type)
          Is the value an instance of a particular type? Use this version to make generics conform, for example in the JMock clause with(any(Thing.class))
static
<T> AnyOf<T>
anyOf(Iterable<Matcher<? super T>> matchers)
          Evaluates to true if ANY of the passed in matchers evaluate to true.
static
<T> AnyOf<T>
anyOf(Matcher<? super T>... matchers)
          Evaluates to true if ANY of the passed in matchers evaluate to true.
static
<T> AnyOf<T>
anyOf(Matcher<T> first, Matcher<? super T> second)
          Evaluates to true if ANY of the passed in matchers evaluate to true.
static
<T> AnyOf<T>
anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third)
          Evaluates to true if ANY of the passed in matchers evaluate to true.
static
<T> AnyOf<T>
anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth)
          Evaluates to true if ANY of the passed in matchers evaluate to true.
static
<T> AnyOf<T>
anyOf(Matcher<T> first, Matcher<? super T> second, Matcher<? super T> third, Matcher<? super T> fourth, Matcher<? super T> fifth)
          Evaluates to true if ANY of the passed in matchers evaluate to true.
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)
          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(String description)
          This matcher always evaluates to true.
static
<LHS> CombinableMatcher<LHS>
both(Matcher<? super LHS> matcher)
          This is useful for fluently combining matchers that must both pass.
static Matcher<String> containsString(String substring)
           
static
<T> Matcher<T>
describedAs(String description, Matcher<T> matcher, Object... values)
          Wraps an existing matcher and overrides the description when it fails.
static
<LHS> CombinableMatcher<LHS>
either(Matcher<? super LHS> matcher)
          This is useful for fluently combining matchers where either may pass, for example:
static Matcher<String> endsWith(String substring)
           
static
<T> Matcher<? super T>
equalTo(T operand)
          Is the value equal to another value, as tested by the Object.equals(java.lang.Object) invokedMethod?
static
<U> Matcher<Iterable<U>>
everyItem(Matcher<U> itemMatcher)
           
static
<T> Matcher<Iterable<? super T>>
hasItem(Matcher<? super T> elementMatcher)
           
static
<T> Matcher<Iterable<? super T>>
hasItem(T element)
           
static
<T> Matcher<Iterable<T>>
hasItems(Matcher<? super T>... elementMatchers)
           
static
<T> Matcher<Iterable<T>>
hasItems(T... elements)
           
static
<T> Matcher<T>
instanceOf(Class<?> type)
          Is the value an instance of a particular type? This version assumes no relationship between the required type and the signature of the method that sets it up, for example in assertThat(anObject, instanceOf(Thing.class));
static
<T> Matcher<? super T>
is(Class<T> 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<? super T>
is(T value)
          This is a shortcut to the frequently used is(equalTo(x)).
static
<T> Matcher<T>
not(Matcher<T> matcher)
          Inverts the rule.
static
<T> Matcher<? super 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(Class<T> type)
          Matches if value is not null.
static
<T> Matcher<T>
nullValue()
          Matches if value is null.
static
<T> Matcher<T>
nullValue(Class<T> type)
          Matches if value is null.
static
<T> Matcher<T>
sameInstance(T object)
          Creates a new instance of IsSame
static Matcher<String> startsWith(String substring)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CoreMatchers

public CoreMatchers()
Method Detail

allOf

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


allOf

public static <T> Matcher<T> allOf(Matcher<T> first,
                                   Matcher<? super T> second,
                                   Matcher<? super T> third)
Evaluates to true only if ALL of the passed in matchers evaluate to true.


allOf

public static <T> Matcher<T> allOf(Matcher<T> first,
                                   Matcher<? super T> second,
                                   Matcher<? super T> third,
                                   Matcher<? super T> fourth)
Evaluates to true only if ALL of the passed in matchers evaluate to true.


allOf

public static <T> Matcher<T> allOf(Matcher<T> first,
                                   Matcher<? super T> second,
                                   Matcher<? super T> third,
                                   Matcher<? super T> fourth,
                                   Matcher<? super T> fifth)
Evaluates to true only if ALL of the passed in matchers evaluate to true.


allOf

public static <T> Matcher<T> allOf(Matcher<T> first,
                                   Matcher<? super T> second,
                                   Matcher<? super T> third,
                                   Matcher<? super T> fourth,
                                   Matcher<? super T> fifth,
                                   Matcher<? super T> sixth)
Evaluates to true only if ALL of the passed in matchers evaluate to true.


allOf

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


allOf

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


anyOf

public static <T> AnyOf<T> anyOf(Matcher<T> first,
                                 Matcher<? super T> second,
                                 Matcher<? super T> third,
                                 Matcher<? super T> fourth)
Evaluates to true if ANY of the passed in matchers evaluate to true.


anyOf

public static <T> AnyOf<T> anyOf(Matcher<T> first,
                                 Matcher<? super T> second)
Evaluates to true if ANY of the passed in matchers evaluate to true.


anyOf

public static <T> AnyOf<T> anyOf(Matcher<T> first,
                                 Matcher<? super T> second,
                                 Matcher<? super T> third)
Evaluates to true if ANY of the passed in matchers evaluate to true.


anyOf

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


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)
Evaluates to true if ANY of the passed in matchers evaluate to true.


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)
Evaluates to true if ANY of the passed in matchers evaluate to true.


anyOf

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


both

public static <LHS> CombinableMatcher<LHS> both(Matcher<? super LHS> matcher)
This is useful for fluently combining matchers that must both pass. For example:
 assertThat(string, both(containsString("a")).and(containsString("b")));
 


either

public static <LHS> CombinableMatcher<LHS> either(Matcher<? super LHS> matcher)
This is useful for fluently combining matchers where either may pass, for example:
 assertThat(string, both(containsString("a")).and(containsString("b")));
 


describedAs

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


everyItem

public static <U> Matcher<Iterable<U>> everyItem(Matcher<U> itemMatcher)
Parameters:
itemMatcher - A matcher to apply to every element in a collection.
Returns:
Evaluates to TRUE for a collection in which every item matches itemMatcher

is

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


is

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


is

public static <T> Matcher<? super T> is(Class<T> type)
This is a shortcut to the frequently used is(instanceOf(SomeClass.class)). For example: assertThat(cheese, is(instanceOf(Cheddar.class))) vs. assertThat(cheese, is(Cheddar.class))


anything

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


anything

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

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

hasItem

public static <T> Matcher<Iterable<? super T>> hasItem(T element)

hasItem

public static <T> Matcher<Iterable<? super T>> hasItem(Matcher<? super T> elementMatcher)

hasItems

public static <T> Matcher<Iterable<T>> hasItems(Matcher<? super T>... elementMatchers)

hasItems

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

equalTo

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


any

public static <T> Matcher<T> any(Class<T> type)
Is the value an instance of a particular type? Use this version to make generics conform, for example in the JMock clause with(any(Thing.class))


instanceOf

public static <T> Matcher<T> instanceOf(Class<?> type)
Is the value an instance of a particular type? This version assumes no relationship between the required type and the signature of the method that sets it up, for example in assertThat(anObject, instanceOf(Thing.class));


not

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


not

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


nullValue

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


nullValue

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


notNullValue

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


notNullValue

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


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.

containsString

public static Matcher<String> containsString(String substring)

startsWith

public static Matcher<String> startsWith(String substring)

endsWith

public static Matcher<String> endsWith(String substring)