Package org.hamcrest
Interface Matcher<T>
-
- All Superinterfaces:
SelfDescribing
- All Known Implementing Classes:
AllOf
,AnyOf
,ArrayAsIterableMatcher
,BaseMatcher
,BigDecimalCloseTo
,CharSequenceLength
,CombinableMatcher
,ComparatorMatcherBuilder.ComparatorMatcher
,CustomMatcher
,CustomTypeSafeMatcher
,DescribedAs
,DiagnosingMatcher
,Every
,FeatureMatcher
,HasEqualValues
,HasEqualValues.FieldMatcher
,HasItemInArray
,HasProperty
,HasPropertyWithValue
,HasToString
,HasXPath
,Is
,IsAnything
,IsArray
,IsArrayContainingInAnyOrder
,IsArrayContainingInOrder
,IsArrayWithSize
,IsBlankString
,IsCloseTo
,IsCollectionContaining
,IsCollectionWithSize
,IsCompatibleType
,IsEmptyCollection
,IsEmptyIterable
,IsEmptyString
,IsEqual
,IsEqualCompressingWhiteSpace
,IsEqualIgnoringCase
,IsEventFrom
,IsIn
,IsInstanceOf
,IsIterableContaining
,IsIterableContainingInAnyOrder
,IsIterableContainingInOrder
,IsIterableContainingInRelativeOrder
,IsIterableWithSize
,IsMapContaining
,IsMapWithSize
,IsNaN
,IsNot
,IsNull
,IsSame
,MatchesPattern
,SamePropertyValuesAs
,SamePropertyValuesAs.PropertyMatcher
,ShortcutCombination
,StringContains
,StringContainsInOrder
,StringEndsWith
,StringRegularExpression
,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 the
BaseMatcher
abstract class, which will ensure that the Matcher API can grow to support new features and remain compatible with all Matcher implementations.When using Hamcrest, there is no guarantee as to how often
matches()
ordescribeMismatch()
will be called, so the objects passed asactual
arguments should not change when referenced. If you're testing a stream, a good practice is to collect the contents of the stream before matching.N.B. Well designed matchers should be immutable.
- See Also:
BaseMatcher
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description void
_dont_implement_Matcher___instead_extend_BaseMatcher_()
Deprecated.to makevoid
describeMismatch(java.lang.Object actual, Description mismatchDescription)
Generate a description of why the matcher has not accepted the item.boolean
matches(java.lang.Object actual)
Evaluates the matcher for argument item.-
Methods inherited from interface org.hamcrest.SelfDescribing
describeTo
-
-
-
-
Method Detail
-
matches
boolean matches(java.lang.Object actual)
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:
actual
- the object against which the matcher is evaluated.- Returns:
true
if item matches, otherwisefalse
.- See Also:
BaseMatcher
-
describeMismatch
void describeMismatch(java.lang.Object actual, 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.- Parameters:
actual
- 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_()
Deprecated.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 .- See Also:
for reasons why.
,BaseMatcher
-
-