org.hamcrest.object.HasToString Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hamcrest Show documentation
Show all versions of hamcrest Show documentation
Core API and libraries of hamcrest matcher framework.
The newest version!
package org.hamcrest.object;
import org.hamcrest.FeatureMatcher;
import org.hamcrest.Matcher;
import static org.hamcrest.core.IsEqual.equalTo;
public class HasToString extends FeatureMatcher {
public HasToString(Matcher super String> toStringMatcher) {
super(toStringMatcher, "with toString()", "toString()");
}
@Override
protected String featureValueOf(T actual) {
return String.valueOf(actual);
}
/**
* Creates a matcher that matches any examined object whose toString
method
* returns a value that satisfies the specified matcher.
* For example:
* assertThat(true, hasToString(equalTo("TRUE")))
*
* @param
* the matcher type.
* @param toStringMatcher
* the matcher used to verify the toString result
* @return The matcher.
*/
public static Matcher hasToString(Matcher super String> toStringMatcher) {
return new HasToString<>(toStringMatcher);
}
/**
* Creates a matcher that matches any examined object whose toString
method
* returns a value equalTo the specified string.
* For example:
* assertThat(true, hasToString("TRUE"))
*
* @param
* the matcher type.
* @param expectedToString
* the expected toString result
* @return The matcher.
*/
public static Matcher hasToString(String expectedToString) {
return new HasToString<>(equalTo(expectedToString));
}
}