Package org.hamcrest.object
Class HasToString<T>
java.lang.Object
org.hamcrest.BaseMatcher<T>
org.hamcrest.TypeSafeDiagnosingMatcher<T>
org.hamcrest.FeatureMatcher<T,String>
org.hamcrest.object.HasToString<T>
- Type Parameters:
T
- The Matcher type.
- All Implemented Interfaces:
Matcher<T>
,SelfDescribing
A Matcher that checks the output of the
toString()
method.-
Constructor Summary
ConstructorDescriptionHasToString
(Matcher<? super String> toStringMatcher) Constructor, best called fromhasToString(String)
orhasToString(Matcher)
. -
Method Summary
Modifier and TypeMethodDescriptionprotected String
featureValueOf
(T actual) Implement this to extract the interesting feature.static <T> Matcher
<T> hasToString
(String expectedToString) Creates a matcher that matches any examined object whosetoString
method returns a value equalTo the specified string.static <T> Matcher
<T> hasToString
(Matcher<? super String> toStringMatcher) Creates a matcher that matches any examined object whosetoString
method returns a value that satisfies the specified matcher.Methods inherited from class org.hamcrest.FeatureMatcher
describeTo, matchesSafely
Methods inherited from class org.hamcrest.TypeSafeDiagnosingMatcher
describeMismatch, matches
Methods inherited from class org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
-
Constructor Details
-
HasToString
Constructor, best called fromhasToString(String)
orhasToString(Matcher)
.- Parameters:
toStringMatcher
- expected result from callingtoString()
-
-
Method Details
-
featureValueOf
Description copied from class:FeatureMatcher
Implement this to extract the interesting feature.- Specified by:
featureValueOf
in classFeatureMatcher<T,
String> - Parameters:
actual
- the target object- Returns:
- the feature to be matched
-
hasToString
Creates a matcher that matches any examined object whosetoString
method returns a value that satisfies the specified matcher. For example:assertThat(true, hasToString(equalTo("TRUE")))
- Type Parameters:
T
- the matcher type.- Parameters:
toStringMatcher
- the matcher used to verify the toString result- Returns:
- The matcher.
-
hasToString
Creates a matcher that matches any examined object whosetoString
method returns a value equalTo the specified string. For example:assertThat(true, hasToString("TRUE"))
- Type Parameters:
T
- the matcher type.- Parameters:
expectedToString
- the expected toString result- Returns:
- The matcher.
-