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

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

There is a newer version: 3.0
Show newest version
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 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 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