Class StringStartsWith

All Implemented Interfaces:
Matcher<String>, SelfDescribing

public class StringStartsWith extends SubstringMatcher
Tests if the argument is a string that starts with a specific substring.
  • Constructor Details

    • StringStartsWith

      public StringStartsWith(String prefix)
      Constructor, best used with startsWith(String).
      Parameters:
      prefix - the expected start of the string.
    • StringStartsWith

      public StringStartsWith(boolean ignoringCase, String prefix)
      Constructor, best used with startsWith(String) or startsWithIgnoringCase(String).
      Parameters:
      ignoringCase - whether to ignore case when matching
      prefix - the expected start of the string.
  • Method Details

    • evalSubstringOf

      protected boolean evalSubstringOf(String s)
      Description copied from class: SubstringMatcher
      Checks if the input matches the specific substring.
      Specified by:
      evalSubstringOf in class SubstringMatcher
      Parameters:
      s - the string to check
      Returns:
      the result of the match
    • startsWith

      public static Matcher<String> startsWith(String prefix)

      Creates a matcher that matches if the examined String starts with the specified String.

      For example:
      assertThat("myStringOfNote", startsWith("my"))
      Parameters:
      prefix - the substring that the returned matcher will expect at the start of any examined string
      Returns:
      The matcher.
    • startsWithIgnoringCase

      public static Matcher<String> startsWithIgnoringCase(String prefix)

      Creates a matcher that matches if the examined String starts with the specified String, ignoring case

      For example:
      assertThat("myStringOfNote", startsWithIgnoringCase("My"))
      Parameters:
      prefix - the substring that the returned matcher will expect at the start of any examined string
      Returns:
      The matcher.