Class HasToString<T>

Type Parameters:
T - The Matcher type.
All Implemented Interfaces:
Matcher<T>, SelfDescribing

public class HasToString<T> extends FeatureMatcher<T,String>
A Matcher that checks the output of the toString() method.
  • Constructor Details

  • Method Details

    • featureValueOf

      protected String featureValueOf(T actual)
      Description copied from class: FeatureMatcher
      Implement this to extract the interesting feature.
      Specified by:
      featureValueOf in class FeatureMatcher<T,String>
      Parameters:
      actual - the target object
      Returns:
      the feature to be matched
    • hasToString

      public static <T> Matcher<T> hasToString(Matcher<? super String> toStringMatcher)
      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")))
      Type Parameters:
      T - the matcher type.
      Parameters:
      toStringMatcher - the matcher used to verify the toString result
      Returns:
      The matcher.
    • hasToString

      public static <T> Matcher<T> hasToString(String expectedToString)
      Creates a matcher that matches any examined object whose toString method returns a value equalTo the specified string. For example:
      assertThat(true, hasToString("TRUE"))
      Type Parameters:
      T - the matcher type.
      Parameters:
      expectedToString - the expected toString result
      Returns:
      The matcher.