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

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.

There is a newer version: 1.3
Show newest version
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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy