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-library Show documentation
Show all versions of hamcrest-library Show documentation
A library of Hamcrest matchers - deprecated, please use "hamcrest" instead
package org.hamcrest.object;
import org.hamcrest.Factory;
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 toStringMatcher
* the matcher used to verify the toString result
*/
@Factory
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 expectedToString
* the expected toString result
*/
@Factory
public static Matcher hasToString(String expectedToString) {
return new HasToString(equalTo(expectedToString));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy