Class SubstringMatcher

All Implemented Interfaces:
Matcher<String>, SelfDescribing
Direct Known Subclasses:
StringContains, StringEndsWith, StringStartsWith

public abstract class SubstringMatcher extends TypeSafeMatcher<String>
Common behaviour for matchers that check substrings.
See Also:
  • Field Details

    • substring

      protected final String substring
      The substring to match
  • Constructor Details

    • SubstringMatcher

      protected SubstringMatcher(String relationship, boolean ignoringCase, String substring)
      Build a SubstringMatcher.
      Parameters:
      relationship - a description of the matcher, such as "containing", "ending with", or "starting with"
      ignoringCase - true for case-insensitive match
      substring - the substring to match
  • Method Details

    • matchesSafely

      public boolean matchesSafely(String item)
      Description copied from class: TypeSafeMatcher
      Check if the item matches. The item will already have been checked for the specific type and will never be null. Subclasses should implement this.
      Specified by:
      matchesSafely in class TypeSafeMatcher<String>
      Parameters:
      item - the type safe item to match against.
      Returns:
      boolean true/false depending if item matches matcher.
    • describeMismatchSafely

      public void describeMismatchSafely(String item, Description mismatchDescription)
      Description copied from class: TypeSafeMatcher
      Describe the mismatch. The item will already have been checked for the specific type and will never be null. Subclasses should override this.
      Overrides:
      describeMismatchSafely in class TypeSafeMatcher<String>
      Parameters:
      item - the type safe item to match against.
      mismatchDescription - the mismatch description.
    • describeTo

      public void describeTo(Description description)
      Description copied from interface: SelfDescribing
      Generates a description of the object. The description may be part of a description of a larger object of which this is just a component, so it should be worded appropriately.
      Parameters:
      description - The description to be built or appended to.
    • converted

      protected String converted(String arg)
      Helper method to allow subclasses to handle case insensitivity.
      Parameters:
      arg - the string to adjust for case
      Returns:
      the input string in lowercase if ignoring case, otherwise the original string
    • evalSubstringOf

      protected abstract boolean evalSubstringOf(String string)
      Checks if the input matches the specific substring.
      Parameters:
      string - the string to check
      Returns:
      the result of the match