All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ext.test4j.hamcrest.object.HasToString Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
package ext.test4j.hamcrest.object;

import ext.test4j.hamcrest.Factory;
import ext.test4j.hamcrest.FeatureMatcher;
import ext.test4j.hamcrest.Matcher;

import static ext.test4j.hamcrest.core.IsEqual.equalTo;

public class HasToString extends FeatureMatcher {
    public HasToString(Matcher toStringMatcher) {
      super(toStringMatcher, "with toString()", "toString()");
    }
    
    @Override
    protected String featureValueOf(T actual) {
      return actual.toString();
    }

    /**
     * Evaluates whether item.toString() satisfies a given matcher.
     */
    @Factory
    public static  HasToString hasToString(Matcher toStringMatcher) {
        return new HasToString(toStringMatcher);
    }

    /**
     * This is a shortcut to the frequently used has_string(equalTo(x)).
     *
     * For example,  assertThat(hasToString(equal_to(x)))
     *          vs.  assertThat(hasToString(x))
     */
    @Factory
    public static  HasToString hasToString(String expectedToString) {
        return new HasToString(equalTo(expectedToString));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy