Class Strings

java.lang.Object
org.fest.assertions.internal.Strings

public class Strings extends Object
Reusable assertions for Strings.
Author:
Alex Ruiz, Joel Costigliola, Nicolas François
  • Constructor Details

  • Method Details

    • instance

      public static Strings instance()
      Returns the singleton instance of this class based on StandardComparisonStrategy.
      Returns:
      the singleton instance of this class based on StandardComparisonStrategy.
    • getComparator

      public Comparator<?> getComparator()
    • assertNullOrEmpty

      public void assertNullOrEmpty(AssertionInfo info, String actual)
      Asserts that the given String is null or empty.
      Parameters:
      info - contains information about the assertion.
      actual - the given String.
      Throws:
      AssertionError - if the given String is not null *and* it is not empty.
    • assertEmpty

      public void assertEmpty(AssertionInfo info, String actual)
      Asserts that the given String is empty.
      Parameters:
      info - contains information about the assertion.
      actual - the given String.
      Throws:
      AssertionError - if the given String is null.
      AssertionError - if the given String is not empty.
    • assertNotEmpty

      public void assertNotEmpty(AssertionInfo info, String actual)
      Asserts that the given String is not empty.
      Parameters:
      info - contains information about the assertion.
      actual - the given String.
      Throws:
      AssertionError - if the given String is null.
      AssertionError - if the given String is empty.
    • assertHasSize

      public void assertHasSize(AssertionInfo info, String actual, int expectedSize)
      Asserts that the size of the given String is equal to the expected one.
      Parameters:
      info - contains information about the assertion.
      actual - the given String.
      expectedSize - the expected size of actual.
      Throws:
      AssertionError - if the given String is null.
      AssertionError - if the size of the given String is different than the expected one.
    • assertHasSameSizeAs

      public void assertHasSameSizeAs(AssertionInfo info, String actual, Iterable<?> other)
      Asserts that the number of entries in the given String has the same size as the other Iterable.
      Parameters:
      info - contains information about the assertion.
      actual - the given String.
      other - the group to compare
      Throws:
      AssertionError - if the given String. is null.
      AssertionError - if the given Iterable is null.
      AssertionError - if the number of entries in the given String does not have the same size.
    • assertHasSameSizeAs

      public void assertHasSameSizeAs(AssertionInfo info, String actual, Object[] other)
      Asserts that the number of entries in the given String has the same size as the other array.
      Parameters:
      info - contains information about the assertion.
      actual - the given String.
      other - the group to compare
      Throws:
      AssertionError - if the given String is null.
      AssertionError - if the given array is null.
      AssertionError - if the number of entries in the given String does not have the same size.
    • assertContains

      public void assertContains(AssertionInfo info, String actual, String sequence)
      Verifies that the given String contains the given sequence.
      Parameters:
      info - contains information about the assertion.
      actual - the actual String.
      sequence - the sequence to search for.
      Throws:
      NullPointerException - if the given sequence is null.
      AssertionError - if the given String is null.
      AssertionError - if the actual String does not contain the given sequence.
    • assertContainsIgnoringCase

      public void assertContainsIgnoringCase(AssertionInfo info, String actual, String sequence)
      Verifies that the given String contains the given sequence, ignoring case considerations.
      Parameters:
      info - contains information about the assertion.
      actual - the actual String.
      sequence - the sequence to search for.
      Throws:
      NullPointerException - if the given sequence is null.
      AssertionError - if the given String is null.
      AssertionError - if the actual String does not contain the given sequence.
    • assertDoesNotContain

      public void assertDoesNotContain(AssertionInfo info, String actual, String sequence)
      Verifies that the given String does not contain the given sequence.
      Parameters:
      info - contains information about the assertion.
      actual - the actual String.
      sequence - the sequence to search for.
      Throws:
      NullPointerException - if the given sequence is null.
      AssertionError - if the given String is null.
      AssertionError - if the actual String contains the given sequence.
    • assertEqualsIgnoringCase

      public void assertEqualsIgnoringCase(AssertionInfo info, String actual, String expected)
      Verifies that two Strings are equal, ignoring case considerations.
      Parameters:
      info - contains information about the assertion.
      actual - the actual String.
      expected - the expected String.
      Throws:
      AssertionError - if the given Strings are not equal.
    • assertContainsOnlyOnce

      public void assertContainsOnlyOnce(AssertionInfo info, String actual, String sequence)
      Verifies that actual Strings contains only once the given sequence.
      Parameters:
      info - contains information about the assertion.
      actual - the actual String.
      sequence - the given String.
      Throws:
      NullPointerException - if the given sequence is null.
      AssertionError - if the given String is null.
      AssertionError - if the actual String does not contains only once the given String.
    • assertStartsWith

      public void assertStartsWith(AssertionInfo info, String actual, String prefix)
      Verifies that the given String starts with the given prefix.
      Parameters:
      info - contains information about the assertion.
      actual - the actual String.
      prefix - the given prefix.
      Throws:
      NullPointerException - if the given sequence is null.
      AssertionError - if the given String is null.
      AssertionError - if the actual String does not start with the given prefix.
    • assertEndsWith

      public void assertEndsWith(AssertionInfo info, String actual, String suffix)
      Verifies that the given String ends with the given suffix.
      Parameters:
      info - contains information about the assertion.
      actual - the actual String.
      suffix - the given suffix.
      Throws:
      NullPointerException - if the given sequence is null.
      AssertionError - if the given String is null.
      AssertionError - if the actual String does not end with the given suffix.
    • assertMatches

      public void assertMatches(AssertionInfo info, String actual, String regex)
      Verifies that the given String matches the given regular expression.
      Parameters:
      info - contains information about the assertion.
      actual - the given String.
      regex - the regular expression to which the actual String is to be matched.
      Throws:
      NullPointerException - if the given pattern is null.
      PatternSyntaxException - if the regular expression's syntax is invalid.
      AssertionError - if the given String is null.
      AssertionError - if the actual String does not match the given regular expression.
    • assertDoesNotMatch

      public void assertDoesNotMatch(AssertionInfo info, String actual, String regex)
      Verifies that the given String does not match the given regular expression.
      Parameters:
      info - contains information about the assertion.
      actual - the given String.
      regex - the regular expression to which the actual String is to be matched.
      Throws:
      NullPointerException - if the given pattern is null.
      PatternSyntaxException - if the regular expression's syntax is invalid.
      AssertionError - if the actual String matches the given regular expression.
    • assertMatches

      public void assertMatches(AssertionInfo info, String actual, Pattern pattern)
      Verifies that the given String matches the given regular expression.
      Parameters:
      info - contains information about the assertion.
      actual - the given String.
      pattern - the regular expression to which the actual String is to be matched.
      Throws:
      NullPointerException - if the given pattern is null.
      AssertionError - if the given String is null.
      AssertionError - if the given String does not match the given regular expression.
    • assertDoesNotMatch

      public void assertDoesNotMatch(AssertionInfo info, String actual, Pattern pattern)
      Verifies that the given String does not match the given regular expression.
      Parameters:
      info - contains information about the assertion.
      actual - the given String.
      pattern - the regular expression to which the actual String is to be matched.
      Throws:
      NullPointerException - if the given pattern is null.
      AssertionError - if the given String matches the given regular expression.