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

org.hamcrest.object.HasToString Maven / Gradle / Ivy

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 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 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)); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy