程序包 org.hamcrest
接口 Matcher<T>
- 所有超级接口:
SelfDescribing
- 所有已知实现类:
AllOf
,AnyOf
,BaseMatcher
,CombinableMatcher
,CustomMatcher
,CustomTypeSafeMatcher
,DescribedAs
,DiagnosingMatcher
,Every
,FeatureMatcher
,Is
,IsAnything
,IsCollectionContaining
,IsEqual
,IsInstanceOf
,IsNot
,IsNull
,IsSame
,StringContains
,StringEndsWith
,StringStartsWith
,SubstringMatcher
,TypeSafeDiagnosingMatcher
,TypeSafeMatcher
public interface Matcher<T> extends SelfDescribing
A matcher over acceptable values. A matcher is able to describe itself to give feedback when it fails. Matcher implementations should NOT directly implement this interface. Instead, extend theBaseMatcher
abstract class, which will ensure that the Matcher API can grow to support new features and remain compatible with all Matcher implementations. For easy access to common Matcher implementations, use the static factory methods inCoreMatchers
. N.B. Well designed matchers should be immutable.- 另请参阅:
CoreMatchers
,BaseMatcher
方法概要
所有方法 实例方法 抽象方法 已过时的方法 修饰符和类型 方法 说明 void
_dont_implement_Matcher___instead_extend_BaseMatcher_()
已过时。to makevoid
describeMismatch(Object item, Description mismatchDescription)
Generate a description of why the matcher has not accepted the item.boolean
matches(Object item)
Evaluates the matcher for argument item.从接口继承的方法 org.hamcrest.SelfDescribing
describeTo
方法详细资料
matches
boolean matches(Object item)
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.- 参数:
item
- the object against which the matcher is evaluated.- 返回:
true
if item matches, otherwisefalse
.- 另请参阅:
BaseMatcher
describeMismatch
void describeMismatch(Object item, Description mismatchDescription)
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 thatmatches(item)
is false, but will not check this.- 参数:
item
- The item that the Matcher has rejected.mismatchDescription
- The description to be built or appended to.
_dont_implement_Matcher___instead_extend_BaseMatcher_
@Deprecated void _dont_implement_Matcher___instead_extend_BaseMatcher_()
已过时。to makeThis method simply acts a friendly reminder not to implement Matcher directly and instead extend BaseMatcher. It's easy to ignore JavaDoc, but a bit harder to ignore compile errors .- 另请参阅:
for reasons why.
,BaseMatcher