Top Description Fields Constructors Methods
org.hamcrest.core

public Class Is<T>

extends BaseMatcher<T>
Class Inheritance
Imports
org.hamcrest.BaseMatcher, .Description, .Matcher

Decorates another Matcher, retaining the behaviour but allowing tests to be slightly more expressive. For example: assertThat(cheese, equalTo(smelly)) vs. assertThat(cheese, is(equalTo(smelly)))

Field Summary

Modifier and TypeField and Description
private final Matcher<T>

Constructor Summary

AccessConstructor and Description
public
Is(Matcher<T> matcher)

Method Summary

Modifier and TypeMethod and Description
public void
describeMismatch(Object
The item that the Matcher has rejected.
item
,
Description
The description to be built or appended to.
mismatchDescription
)

Overrides org.hamcrest.BaseMatcher.describeMismatch.

Implements org.hamcrest.Matcher.describeMismatch.

Generate a description of why the matcher has not accepted the item.
public void
describeTo(Description
The description to be built or appended to.
description
)

Implements org.hamcrest.SelfDescribing.describeTo.

Generates a description of the object.
public static <T> Matcher<T>
is(Matcher<T> matcher)

Decorates another Matcher, retaining its behaviour, but allowing tests to be slightly more expressive.

public static <T> Matcher<T>
is(T value)

A shortcut to the frequently used is(equalTo(x)).

public static <T> Matcher<T>
isA(Class<?> type)

A shortcut to the frequently used is(instanceOf(SomeClass.class)).

public boolean
matches(Object
the object against which the matcher is evaluated.
arg
)

Implements org.hamcrest.Matcher.matches.

Evaluates the matcher for argument item.
Inherited from org.hamcrest.BaseMatcher:
_dont_implement_Matcher___instead_extend_BaseMatcher_isNotNulltoString

Field Detail

matcherback to summary
private final Matcher<T> matcher

Constructor Detail

Isback to summary
public Is(Matcher<T> matcher)

Method Detail

describeMismatchback to summary
public void describeMismatch(Object item, Description mismatchDescription)

Overrides org.hamcrest.BaseMatcher.describeMismatch.

Implements org.hamcrest.Matcher.describeMismatch.

Doc from org.hamcrest.Matcher.describeMismatch.

Generate a description of why the matcher has not accepted the item. The description will be part of a larger description of why a matching failed, so it should be concise. This method assumes that matches(item) is false, but will not check this.

Parameters
item:Object

The item that the Matcher has rejected.

mismatchDescription:Description

The description to be built or appended to.

Annotations
@Override
describeToback to summary
public void describeTo(Description description)

Implements org.hamcrest.SelfDescribing.describeTo.

Doc from org.hamcrest.SelfDescribing.describeTo.

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.

Parameters
description:Description

The description to be built or appended to.

Annotations
@Override
isback to summary
public static <T> Matcher<T> is(Matcher<T> matcher)

Decorates another Matcher, retaining its behaviour, but allowing tests to be slightly more expressive. For example:

assertThat(cheese, is(equalTo(smelly)))
instead of:
assertThat(cheese, equalTo(smelly))
isback to summary
public static <T> Matcher<T> is(T value)

A shortcut to the frequently used is(equalTo(x)). For example:

assertThat(cheese, is(smelly))
instead of:
assertThat(cheese, is(equalTo(smelly)))
isAback to summary
public static <T> Matcher<T> isA(Class<?> type)

A shortcut to the frequently used is(instanceOf(SomeClass.class)). For example:

assertThat(cheese, isA(Cheddar.class))
instead of:
assertThat(cheese, is(instanceOf(Cheddar.class)))
matchesback to summary
public boolean matches(Object arg)

Implements org.hamcrest.Matcher.matches.

Doc from org.hamcrest.Matcher.matches.

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.

Parameters
arg:Object

the object against which the matcher is evaluated.

Returns:boolean

true if item matches, otherwise false.

Annotations
@Override