Top Description Fields Constructors Methods
org.hamcrest.core

public Class DescribedAs<T>

extends BaseMatcher<T>
Class Inheritance
Imports
org.hamcrest.BaseMatcher, .Description, .Matcher, java.util.regex.Pattern

Provides a custom description to another matcher.

Field Summary

Modifier and TypeField and Description
private static final Pattern
private final String
private final Matcher<T>
private final Object[]

Constructor Summary

AccessConstructor and Description
public
DescribedAs(String descriptionTemplate, Matcher<T> matcher, Object[] values)

Method Summary

Modifier and TypeMethod and Description
public static <T> Matcher<T>
describedAs(String
the new description for the wrapped matcher
description
,
Matcher<T>
the matcher to wrap
matcher
,
Object...
optional values to insert into the tokenised description
values
)

Wraps an existing matcher, overriding its description with that specified.

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

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 boolean
matches(Object
the object against which the matcher is evaluated.
o
)

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

ARG_PATTERNback to summary
private static final Pattern ARG_PATTERN
descriptionTemplateback to summary
private final String descriptionTemplate
matcherback to summary
private final Matcher<T> matcher
valuesback to summary
private final Object[] values

Constructor Detail

DescribedAsback to summary
public DescribedAs(String descriptionTemplate, Matcher<T> matcher, Object[] values)

Method Detail

describedAsback to summary
public static <T> Matcher<T> describedAs(String description, Matcher<T> matcher, Object... values)

Wraps an existing matcher, overriding its description with that specified. All other functions are delegated to the decorated matcher, including its mismatch description. For example:

describedAs("a big decimal equal to %0", equalTo(myBigDecimal), myBigDecimal.toPlainString())
Parameters
description:String

the new description for the wrapped matcher

matcher:Matcher<T>

the matcher to wrap

values:Object[]

optional values to insert into the tokenised description

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

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.

description: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
matchesback to summary
public boolean matches(Object o)

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
o:Object

the object against which the matcher is evaluated.

Returns:boolean

true if item matches, otherwise false.

Annotations
@Override