org.hamcrest.object.HasToString Maven / Gradle / Ivy
Go to download
A self-contained hamcrest jar containing all of the sub-modules in a single artifact.
package org.hamcrest.object;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.Factory;
import org.hamcrest.BaseMatcher;
public class HasToString extends BaseMatcher {
private final Matcher toStringMatcher;
public HasToString(Matcher toStringMatcher) {
this.toStringMatcher = toStringMatcher;
}
public boolean matches(Object item) {
return item != null && toStringMatcher.matches(item.toString());
}
public void describeTo(Description description) {
description.appendText("asString(");
toStringMatcher.describeTo(description);
description.appendText(")");
}
@Factory
public static Matcher hasToString(Matcher toStringMatcher) {
return new HasToString(toStringMatcher);
}
}