Package org.assertj.core.internal
Class Strings
- java.lang.Object
-
- org.assertj.core.internal.Strings
-
public class Strings extends Object
Reusable assertions fors.CharSequence- Author:
- Alex Ruiz, Joel Costigliola, Nicolas François, Mikhail Mazursky, Michal Kordas
-
-
Field Summary
Fields Modifier and Type Field Description private ComparisonStrategycomparisonStrategy(package private) Failuresfailuresprivate static StringsINSTANCE
-
Constructor Summary
Constructors Constructor Description Strings()Strings(ComparisonStrategy comparisonStrategy)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleanareEqualIgnoringCase(CharSequence actual, CharSequence expected)private booleanareEqualIgnoringWhitespace(CharSequence actual, CharSequence expected)private booleanareEqualNormalizingWhitespace(CharSequence actual, CharSequence expected)voidassertBlank(AssertionInfo info, CharSequence actual)Asserts that the givenCharSequenceisNull, empty or consists of one or more whitespace characters.voidassertContains(AssertionInfo info, CharSequence actual, CharSequence... values)Verifies that the givenCharSequencecontains the given strings.voidassertContainsIgnoringCase(AssertionInfo info, CharSequence actual, CharSequence sequence)Verifies that the givenCharSequencecontains the given sequence, ignoring case considerations.voidassertContainsOnlyDigits(AssertionInfo info, CharSequence actual)Verifies that the givenCharSequencecontains only digits.voidassertContainsOnlyOnce(AssertionInfo info, CharSequence actual, CharSequence sequence)Verifies that actualCharSequences contains only once the given sequence.voidassertContainsOnlyWhitespaces(AssertionInfo info, CharSequence actual)Asserts that the givenCharSequenceconsists of one or more whitespace characters.voidassertContainsPattern(AssertionInfo info, CharSequence actual, CharSequence regex)Verifies that the givenCharSequencecontains the given regular expression.voidassertContainsPattern(AssertionInfo info, CharSequence actual, Pattern pattern)Verifies that the givenCharSequencecontains the given regular expression.voidassertContainsSequence(AssertionInfo info, CharSequence actual, CharSequence[] sequence)Verifies that the given charSequence contains the given sequence of charSequence, without any other charSequences between them.voidassertContainsSubsequence(AssertionInfo info, CharSequence actual, CharSequence[] subsequence)Verifies that the actualCharSequencecontains all the given values in the given order (possibly with other values between them).voidassertContainsWhitespaces(AssertionInfo info, CharSequence actual)Asserts that the givenCharSequencecontains one or more whitespace characters.voidassertDoesNotContain(AssertionInfo info, CharSequence actual, CharSequence... values)Verifies that the givenCharSequencedoes not contain any one of the given values.voidassertDoesNotContainAnyWhitespaces(AssertionInfo info, CharSequence actual)Asserts that the givenCharSequenceisNull, empty or contains only non-whitespace characters.voidassertDoesNotContainOnlyWhitespaces(AssertionInfo info, CharSequence actual)Asserts that the givenCharSequenceisNull, empty or contains at least one non-whitespace character.voidassertDoesNotContainPattern(AssertionInfo info, CharSequence actual, CharSequence regex)Verifies that the givenCharSequencedoes not contain the given regular expression.voidassertDoesNotContainPattern(AssertionInfo info, CharSequence actual, Pattern pattern)Verifies that the givenCharSequencedoes not contain the given regular expression.voidassertDoesNotEndWith(AssertionInfo info, CharSequence actual, CharSequence suffix)Verifies that the givenCharSequencedoes not end with the given suffix.voidassertDoesNotMatch(AssertionInfo info, CharSequence actual, CharSequence regex)Verifies that the givenCharSequencedoes not match the given regular expression.voidassertDoesNotMatch(AssertionInfo info, CharSequence actual, Pattern pattern)Verifies that the givenCharSequencedoes not match the given regular expression.voidassertDoesNotStartWith(AssertionInfo info, CharSequence actual, CharSequence prefix)Verifies that the givenCharSequencedoes not start with the given prefix.voidassertEmpty(AssertionInfo info, CharSequence actual)Asserts that the givenCharSequenceis empty.voidassertEndsWith(AssertionInfo info, CharSequence actual, CharSequence suffix)Verifies that the givenCharSequenceends with the given suffix.voidassertEqualsIgnoringCase(AssertionInfo info, CharSequence actual, CharSequence expected)Verifies that twoCharSequences are equal, ignoring case considerations.voidassertEqualsIgnoringWhitespace(AssertionInfo info, CharSequence actual, CharSequence expected)Verifies that twoCharSequences are equal, ignoring any differences in whitespace.voidassertEqualsNormalizingWhitespace(AssertionInfo info, CharSequence actual, CharSequence expected)Verifies that twoCharSequences are equal, after the whitespace of both strings has been normalized.voidassertHasLineCount(AssertionInfo info, CharSequence actual, int expectedLineCount)Asserts that the line count of the givenCharSequenceis equal to the expected one.voidassertHasSameSizeAs(AssertionInfo info, CharSequence actual, CharSequence other)voidassertHasSameSizeAs(AssertionInfo info, CharSequence actual, Iterable<?> other)Asserts that the number of entries in the givenCharSequencehas the same size as the otherIterable.voidassertHasSameSizeAs(AssertionInfo info, CharSequence actual, Object array)Asserts that the number of entries in the givenCharSequencehas the same size as the other array.voidassertHasSize(AssertionInfo info, CharSequence actual, int expectedSize)Asserts that the size of the givenCharSequenceis equal to the expected one.voidassertHasSizeBetween(AssertionInfo info, CharSequence actual, int lowerBoundary, int higherBoundary)Asserts that the size of the givenCharSequenceis between the given lower and higher boundary (inclusive).voidassertHasSizeGreaterThan(AssertionInfo info, CharSequence actual, int expectedMinSizeExcluded)Asserts that the size of the givenCharSequenceis greater than the expected sizevoidassertHasSizeGreaterThanOrEqualTo(AssertionInfo info, CharSequence actual, int expectedMinSizeIncluded)Asserts that the size of the givenCharSequenceis greater than or equal to the expected sizevoidassertHasSizeLessThan(AssertionInfo info, CharSequence actual, int expectedMaxSizeExcluded)Asserts that the size of the givenCharSequenceis less than the expected sizevoidassertHasSizeLessThanOrEqualTo(AssertionInfo info, CharSequence actual, int expectedMaxSizeIncluded)Asserts that the size of the givenCharSequenceis less than or equal to the expected sizevoidassertIsEqualToIgnoringNewLines(AssertionInfo info, CharSequence actual, CharSequence expected)Verifies that actual is equal to expected ignoring new linesvoidassertIsEqualToNormalizingNewlines(AssertionInfo info, CharSequence actual, CharSequence expected)Verifies that twoCharSequences are not equal, normalizing newlines.voidassertIsSubstringOf(AssertionInfo info, CharSequence actual, CharSequence sequence)voidassertJavaBlank(AssertionInfo info, CharSequence actual)Asserts that the givenCharSequenceconsists of one or more whitespace characters according toCharacter.isWhitespace(char).voidassertLowerCase(AssertionInfo info, CharSequence actual)voidassertMatches(AssertionInfo info, CharSequence actual, CharSequence regex)Verifies that the givenCharSequencematches the given regular expression.voidassertMatches(AssertionInfo info, CharSequence actual, Pattern pattern)Verifies that the givenCharSequencematches the given regular expression.voidassertNotBlank(AssertionInfo info, CharSequence actual)Asserts that the givenCharSequencecontains at least one non-whitespace character.voidassertNotEmpty(AssertionInfo info, CharSequence actual)Asserts that the givenCharSequenceis not empty.voidassertNotEqualsIgnoringCase(AssertionInfo info, CharSequence actual, CharSequence expected)Verifies that twoCharSequences are not equal, ignoring case considerations.voidassertNotEqualsIgnoringWhitespace(AssertionInfo info, CharSequence actual, CharSequence expected)Verifies that twoCharSequences are not equal, ignoring any differences in whitespace.voidassertNotEqualsNormalizingWhitespace(AssertionInfo info, CharSequence actual, CharSequence expected)Verifies that twoCharSequences are not equal, after the whitespace of both strings has been normalized.voidassertNotJavaBlank(AssertionInfo info, CharSequence actual)Asserts that the givenCharSequenceisNull, empty or contains at least one non-whitespace character according toCharacter.isWhitespace(char).private voidassertNotNull(AssertionInfo info, CharSequence actual)voidassertNullOrEmpty(AssertionInfo info, CharSequence actual)Asserts that the givenCharSequenceisnullor empty.voidassertStartsWith(AssertionInfo info, CharSequence actual, CharSequence prefix)Verifies that the givenCharSequencestarts with the given prefix.voidassertUpperCase(AssertionInfo info, CharSequence actual)voidassertXmlEqualsTo(AssertionInfo info, CharSequence actualXml, CharSequence expectedXml)private voidcheckCharSequenceArrayDoesNotHaveNullElements(CharSequence[] values)private voidcheckCharSequenceIsNotNull(CharSequence sequence)private voidcheckIsNotEmpty(CharSequence... values)private voidcheckIsNotNull(CharSequence... values)private voidcheckIsNotNull(Pattern pattern)private voidcheckRegexIsNotNull(CharSequence regex)private booleancontainsOneOrMoreWhitespaces(CharSequence actual)private booleancontainsOnlyWhitespaces(CharSequence actual)private booleancontainsWhitespaces(CharSequence actual)private intcountOccurrences(CharSequence sequenceToSearch, CharSequence actual)Count occurrences of sequenceToSearch in actualCharSequence.private voiddoCommonCheckForCharSequence(AssertionInfo info, CharSequence actual, CharSequence[] sequence)private static voidfailIfPrefixIsNull(CharSequence prefix)private static voidfailIfSuffixIsNull(CharSequence suffix)Comparator<?>getComparator()private static booleanhasContent(CharSequence s)private intindexOf(String string, CharSequence toFind)static Stringsinstance()Returns the singleton instance of this class based onStandardComparisonStrategy.private booleanisBlank(CharSequence actual)private booleanisJavaBlank(CharSequence actual)private booleanisNullOrEmpty(CharSequence actual)private static StringnormalizeNewlines(CharSequence actual)private StringnormalizeWhitespace(CharSequence toNormalize)private NullPointerExceptionpatternToMatchIsNull()private StringremoveAllWhitespaces(CharSequence toBeStripped)private static StringremoveNewLines(CharSequence text)private StringremoveUpTo(String string, CharSequence toRemove)private booleanstrictlyContainsWhitespaces(CharSequence actual)private booleanstringContains(CharSequence actual, CharSequence sequence)
-
-
-
Field Detail
-
INSTANCE
private static final Strings INSTANCE
-
comparisonStrategy
private final ComparisonStrategy comparisonStrategy
-
failures
Failures failures
-
-
Constructor Detail
-
Strings
Strings()
-
Strings
public Strings(ComparisonStrategy comparisonStrategy)
-
-
Method Detail
-
instance
public static Strings instance()
Returns the singleton instance of this class based onStandardComparisonStrategy.- Returns:
- the singleton instance of this class based on
StandardComparisonStrategy.
-
getComparator
public Comparator<?> getComparator()
-
assertNullOrEmpty
public void assertNullOrEmpty(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequenceisnullor empty.- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.- Throws:
AssertionError- if the givenCharSequenceis notnull*and* it is not empty.
-
assertEmpty
public void assertEmpty(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequenceis empty.- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.- Throws:
AssertionError- if the givenCharSequenceisnull.AssertionError- if the givenCharSequenceis not empty.
-
assertNotEmpty
public void assertNotEmpty(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequenceis not empty.- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.- Throws:
AssertionError- if the givenCharSequenceisnull.AssertionError- if the givenCharSequenceis empty.
-
hasContent
private static boolean hasContent(CharSequence s)
-
assertBlank
public void assertBlank(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequenceisNull, empty or consists of one or more whitespace characters.- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.- Throws:
AssertionError- if the givenCharSequenceis not blank.
-
assertNotBlank
public void assertNotBlank(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequencecontains at least one non-whitespace character.- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.- Throws:
AssertionError- if the givenCharSequenceis blank.
-
isBlank
private boolean isBlank(CharSequence actual)
-
containsWhitespaces
private boolean containsWhitespaces(CharSequence actual)
-
containsOnlyWhitespaces
private boolean containsOnlyWhitespaces(CharSequence actual)
-
isNullOrEmpty
private boolean isNullOrEmpty(CharSequence actual)
-
containsOneOrMoreWhitespaces
private boolean containsOneOrMoreWhitespaces(CharSequence actual)
-
strictlyContainsWhitespaces
private boolean strictlyContainsWhitespaces(CharSequence actual)
-
assertContainsWhitespaces
public void assertContainsWhitespaces(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequencecontains one or more whitespace characters.- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.- Throws:
AssertionError- if the givenCharSequencedoes not contain any whitespace characters.
-
assertContainsOnlyWhitespaces
public void assertContainsOnlyWhitespaces(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequenceconsists of one or more whitespace characters.- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.- Throws:
AssertionError- if the givenCharSequenceis not blank.
-
assertDoesNotContainAnyWhitespaces
public void assertDoesNotContainAnyWhitespaces(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequenceisNull, empty or contains only non-whitespace characters.- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.- Throws:
AssertionError- if the givenCharSequencecontains one or more whitespace characters.
-
assertDoesNotContainOnlyWhitespaces
public void assertDoesNotContainOnlyWhitespaces(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequenceisNull, empty or contains at least one non-whitespace character.- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.- Throws:
AssertionError- if the givenCharSequenceis blank.
-
assertJavaBlank
public void assertJavaBlank(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequenceconsists of one or more whitespace characters according toCharacter.isWhitespace(char).- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.- Throws:
AssertionError- if the givenCharSequenceis not blank.
-
assertNotJavaBlank
public void assertNotJavaBlank(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequenceisNull, empty or contains at least one non-whitespace character according toCharacter.isWhitespace(char).- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.- Throws:
AssertionError- if the givenCharSequenceis blank.
-
isJavaBlank
private boolean isJavaBlank(CharSequence actual)
-
assertHasSize
public void assertHasSize(AssertionInfo info, CharSequence actual, int expectedSize)
Asserts that the size of the givenCharSequenceis equal to the expected one.- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.expectedSize- the expected size ofactual.- Throws:
AssertionError- if the givenCharSequenceisnull.AssertionError- if the size of the givenCharSequenceis different than the expected one.
-
assertHasSizeLessThan
public void assertHasSizeLessThan(AssertionInfo info, CharSequence actual, int expectedMaxSizeExcluded)
Asserts that the size of the givenCharSequenceis less than the expected size- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.expectedMaxSizeExcluded- the expected max size ofactual- Throws:
AssertionError- if the givenCharSequenceisnull.AssertionError- if the size of the givenCharSequenceis equal to or greater than the expected max size
-
assertHasSizeLessThanOrEqualTo
public void assertHasSizeLessThanOrEqualTo(AssertionInfo info, CharSequence actual, int expectedMaxSizeIncluded)
Asserts that the size of the givenCharSequenceis less than or equal to the expected size- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.expectedMaxSizeIncluded- the expected max size ofactual- Throws:
AssertionError- if the givenCharSequenceisnull.AssertionError- if the size of the givenCharSequenceis greater than the expected max size
-
assertHasSizeGreaterThan
public void assertHasSizeGreaterThan(AssertionInfo info, CharSequence actual, int expectedMinSizeExcluded)
Asserts that the size of the givenCharSequenceis greater than the expected size- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.expectedMinSizeExcluded- the expected min size ofactual- Throws:
AssertionError- if the givenCharSequenceisnull.AssertionError- if the size of the givenCharSequenceis equal to or less than the expected max size
-
assertHasSizeGreaterThanOrEqualTo
public void assertHasSizeGreaterThanOrEqualTo(AssertionInfo info, CharSequence actual, int expectedMinSizeIncluded)
Asserts that the size of the givenCharSequenceis greater than or equal to the expected size- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.expectedMinSizeIncluded- the expected min size ofactual- Throws:
AssertionError- if the givenCharSequenceisnull.AssertionError- if the size of the givenCharSequenceis greater than the expected max size
-
assertHasSizeBetween
public void assertHasSizeBetween(AssertionInfo info, CharSequence actual, int lowerBoundary, int higherBoundary)
Asserts that the size of the givenCharSequenceis between the given lower and higher boundary (inclusive).- Parameters:
info- contains information about the assertion.actual- the givenIterable.lowerBoundary- the lower boundary compared to which actual size should be greater than or equal to.higherBoundary- the higher boundary compared to which actual size should be less than or equal to.- Throws:
AssertionError- if the given array isnull.AssertionError- if the number of elements in the given array is not between the boundaries.
-
assertHasLineCount
public void assertHasLineCount(AssertionInfo info, CharSequence actual, int expectedLineCount)
Asserts that the line count of the givenCharSequenceis equal to the expected one.- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.expectedLineCount- the expected line count ofactual.- Throws:
AssertionError- if the givenCharSequenceisnull.AssertionError- if the line count of the givenCharSequenceis different than the expected one.
-
assertHasSameSizeAs
public void assertHasSameSizeAs(AssertionInfo info, CharSequence actual, Iterable<?> other)
Asserts that the number of entries in the givenCharSequencehas the same size as the otherIterable.- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.other- the group to compare- Throws:
AssertionError- if the givenCharSequenceisnull.AssertionError- if the givenIterableisnull.AssertionError- if the number of entries in the givenCharSequencedoes not have the same size.
-
assertHasSameSizeAs
public void assertHasSameSizeAs(AssertionInfo info, CharSequence actual, Object array)
Asserts that the number of entries in the givenCharSequencehas the same size as the other array.- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.array- the array to compare- Throws:
AssertionError- if the givenCharSequenceisnull.AssertionError- if the given array isnull.AssertionError- if the number of entries in the givenCharSequencedoes not have the same size.
-
assertHasSameSizeAs
public void assertHasSameSizeAs(AssertionInfo info, CharSequence actual, CharSequence other)
-
assertContains
public void assertContains(AssertionInfo info, CharSequence actual, CharSequence... values)
Verifies that the givenCharSequencecontains the given strings.- Parameters:
info- contains information about the assertion.actual- the actualCharSequence.values- the values to look for.- Throws:
NullPointerException- if the given sequence isnull.IllegalArgumentException- if the given values is empty.AssertionError- if the givenCharSequenceisnull.AssertionError- if the actualCharSequencedoes not contain the given sequence.
-
assertContainsOnlyDigits
public void assertContainsOnlyDigits(AssertionInfo info, CharSequence actual)
Verifies that the givenCharSequencecontains only digits.- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.- Throws:
NullPointerException- ifactualisnull.AssertionError- ifactualcontains non-digit characters or contains no digits at all.
-
checkIsNotNull
private void checkIsNotNull(CharSequence... values)
-
checkIsNotEmpty
private void checkIsNotEmpty(CharSequence... values)
-
stringContains
private boolean stringContains(CharSequence actual, CharSequence sequence)
-
assertContainsIgnoringCase
public void assertContainsIgnoringCase(AssertionInfo info, CharSequence actual, CharSequence sequence)
Verifies that the givenCharSequencecontains the given sequence, ignoring case considerations.- Parameters:
info- contains information about the assertion.actual- the actualCharSequence.sequence- the sequence to search for.- Throws:
NullPointerException- if the given sequence isnull.AssertionError- if the givenCharSequenceisnull.AssertionError- if the actualCharSequencedoes not contain the given sequence.
-
assertDoesNotContain
public void assertDoesNotContain(AssertionInfo info, CharSequence actual, CharSequence... values)
Verifies that the givenCharSequencedoes not contain any one of the given values.- Parameters:
info- contains information about the assertion.actual- the actualCharSequence.values- the values to search for.- Throws:
NullPointerException- if the given list of values isnull.NullPointerException- if any one of the given values isnull.IllegalArgumentException- if the list of given values is empty.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencecontains any one of the given values.
-
checkCharSequenceIsNotNull
private void checkCharSequenceIsNotNull(CharSequence sequence)
-
assertEqualsIgnoringCase
public void assertEqualsIgnoringCase(AssertionInfo info, CharSequence actual, CharSequence expected)
Verifies that twoCharSequences are equal, ignoring case considerations.- Parameters:
info- contains information about the assertion.actual- the actualCharSequence.expected- the expectedCharSequence.- Throws:
AssertionError- if the givenCharSequences are not equal.
-
assertNotEqualsIgnoringCase
public void assertNotEqualsIgnoringCase(AssertionInfo info, CharSequence actual, CharSequence expected)
Verifies that twoCharSequences are not equal, ignoring case considerations.- Parameters:
info- contains information about the assertion.actual- the actualCharSequence.expected- the expectedCharSequence.- Throws:
AssertionError- if the givenCharSequences are equal ignoring case considerations.
-
areEqualIgnoringCase
private boolean areEqualIgnoringCase(CharSequence actual, CharSequence expected)
-
assertIsEqualToNormalizingNewlines
public void assertIsEqualToNormalizingNewlines(AssertionInfo info, CharSequence actual, CharSequence expected)
Verifies that twoCharSequences are not equal, normalizing newlines.- Parameters:
info- contains information about the assertion.actual- the actualCharSequence(newlines will be normalized).expected- the expectedCharSequence(newlines will be normalized)..- Throws:
AssertionError- if the givenCharSequences are equal after normalizing newlines.
-
normalizeNewlines
private static String normalizeNewlines(CharSequence actual)
-
assertEqualsIgnoringWhitespace
public void assertEqualsIgnoringWhitespace(AssertionInfo info, CharSequence actual, CharSequence expected)
Verifies that twoCharSequences are equal, ignoring any differences in whitespace.- Parameters:
info- contains information about the assertion.actual- the actualCharSequence.expected- the expectedCharSequence.- Throws:
AssertionError- if the givenCharSequences are not equal.
-
assertNotEqualsIgnoringWhitespace
public void assertNotEqualsIgnoringWhitespace(AssertionInfo info, CharSequence actual, CharSequence expected)
Verifies that twoCharSequences are not equal, ignoring any differences in whitespace.- Parameters:
info- contains information about the assertion.actual- the actualCharSequence.expected- the expectedCharSequence.- Throws:
AssertionError- if the givenCharSequences are equal.
-
areEqualIgnoringWhitespace
private boolean areEqualIgnoringWhitespace(CharSequence actual, CharSequence expected)
-
removeAllWhitespaces
private String removeAllWhitespaces(CharSequence toBeStripped)
-
assertEqualsNormalizingWhitespace
public void assertEqualsNormalizingWhitespace(AssertionInfo info, CharSequence actual, CharSequence expected)
Verifies that twoCharSequences are equal, after the whitespace of both strings has been normalized.- Parameters:
info- contains information about the assertion.actual- the actualCharSequence.expected- the expectedCharSequence.- Throws:
AssertionError- if the givenCharSequences are not equal.- Since:
- 2.8.0 / 3.8.0
-
assertNotEqualsNormalizingWhitespace
public void assertNotEqualsNormalizingWhitespace(AssertionInfo info, CharSequence actual, CharSequence expected)
Verifies that twoCharSequences are not equal, after the whitespace of both strings has been normalized.- Parameters:
info- contains information about the assertion.actual- the actualCharSequence.expected- the expectedCharSequence.- Throws:
AssertionError- if the givenCharSequences are equal.- Since:
- 2.8.0 / 3.8.0
-
areEqualNormalizingWhitespace
private boolean areEqualNormalizingWhitespace(CharSequence actual, CharSequence expected)
-
normalizeWhitespace
private String normalizeWhitespace(CharSequence toNormalize)
-
assertContainsOnlyOnce
public void assertContainsOnlyOnce(AssertionInfo info, CharSequence actual, CharSequence sequence)
Verifies that actualCharSequences contains only once the given sequence.- Parameters:
info- contains information about the assertion.actual- the actualCharSequence.sequence- the givenCharSequence.- Throws:
NullPointerException- if the given sequence isnull.AssertionError- if the givenCharSequenceisnull.AssertionError- if the actualCharSequencedoes not contains only once the givenCharSequence.
-
countOccurrences
private int countOccurrences(CharSequence sequenceToSearch, CharSequence actual)
Count occurrences of sequenceToSearch in actualCharSequence.- Parameters:
sequenceToSearch- the sequence to search in in actualCharSequence.actual- theCharSequenceto search occurrences in.- Returns:
- the number of occurrences of sequenceToSearch in actual
CharSequence.
-
assertStartsWith
public void assertStartsWith(AssertionInfo info, CharSequence actual, CharSequence prefix)
Verifies that the givenCharSequencestarts with the given prefix.- Parameters:
info- contains information about the assertion.actual- the actualCharSequence.prefix- the given prefix.- Throws:
NullPointerException- if the given sequence isnull.AssertionError- if the givenCharSequenceisnull.AssertionError- if the actualCharSequencedoes not start with the given prefix.
-
assertDoesNotStartWith
public void assertDoesNotStartWith(AssertionInfo info, CharSequence actual, CharSequence prefix)
Verifies that the givenCharSequencedoes not start with the given prefix.- Parameters:
info- contains information about the assertion.actual- the actualCharSequence.prefix- the given prefix.- Throws:
NullPointerException- if the given sequence isnull.AssertionError- if the givenCharSequenceisnull.AssertionError- if the actualCharSequencestarts with the given prefix.
-
failIfPrefixIsNull
private static void failIfPrefixIsNull(CharSequence prefix)
-
assertEndsWith
public void assertEndsWith(AssertionInfo info, CharSequence actual, CharSequence suffix)
Verifies that the givenCharSequenceends with the given suffix.- Parameters:
info- contains information about the assertion.actual- the actualCharSequence.suffix- the given suffix.- Throws:
NullPointerException- if the given sequence isnull.AssertionError- if the givenCharSequenceisnull.AssertionError- if the actualCharSequencedoes not end with the given suffix.
-
assertDoesNotEndWith
public void assertDoesNotEndWith(AssertionInfo info, CharSequence actual, CharSequence suffix)
Verifies that the givenCharSequencedoes not end with the given suffix.- Parameters:
info- contains information about the assertion.actual- the actualCharSequence.suffix- the given suffix.- Throws:
NullPointerException- if the given sequence isnull.AssertionError- if the givenCharSequenceisnull.AssertionError- if the actualCharSequenceends with the given suffix.
-
failIfSuffixIsNull
private static void failIfSuffixIsNull(CharSequence suffix)
-
assertMatches
public void assertMatches(AssertionInfo info, CharSequence actual, CharSequence regex)
Verifies that the givenCharSequencematches the given regular expression.- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.regex- the regular expression to which the actualCharSequenceis to be matched.- Throws:
NullPointerException- if the given pattern isnull.PatternSyntaxException- if the regular expression's syntax is invalid.AssertionError- if the givenCharSequenceisnull.AssertionError- if the actualCharSequencedoes not match the given regular expression.
-
assertDoesNotMatch
public void assertDoesNotMatch(AssertionInfo info, CharSequence actual, CharSequence regex)
Verifies that the givenCharSequencedoes not match the given regular expression.- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.regex- the regular expression to which the actualCharSequenceis to be matched.- Throws:
NullPointerException- if the given pattern isnull.PatternSyntaxException- if the regular expression's syntax is invalid.AssertionError- if the givenCharSequenceisnull.AssertionError- if the actualCharSequencematches the given regular expression.
-
checkRegexIsNotNull
private void checkRegexIsNotNull(CharSequence regex)
-
assertMatches
public void assertMatches(AssertionInfo info, CharSequence actual, Pattern pattern)
Verifies that the givenCharSequencematches the given regular expression.- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.pattern- the regular expression to which the actualCharSequenceis to be matched.- Throws:
NullPointerException- if the given pattern isnull.AssertionError- if the givenCharSequenceisnull.AssertionError- if the givenCharSequencedoes not match the given regular expression.
-
assertDoesNotMatch
public void assertDoesNotMatch(AssertionInfo info, CharSequence actual, Pattern pattern)
Verifies that the givenCharSequencedoes not match the given regular expression.- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.pattern- the regular expression to which the actualCharSequenceis to be matched.- Throws:
NullPointerException- if the given pattern isnull.AssertionError- if the givenCharSequencematches the given regular expression.
-
checkIsNotNull
private void checkIsNotNull(Pattern pattern)
-
patternToMatchIsNull
private NullPointerException patternToMatchIsNull()
-
assertNotNull
private void assertNotNull(AssertionInfo info, CharSequence actual)
-
assertContainsSequence
public void assertContainsSequence(AssertionInfo info, CharSequence actual, CharSequence[] sequence)
Verifies that the given charSequence contains the given sequence of charSequence, without any other charSequences between them.- Parameters:
info- contains information about the assertion.actual- the given charSequence.sequence- the sequence of charSequence to look for.- Throws:
NullPointerException- if the given sequence of charSequence isnull.IllegalArgumentException- if the given sequence of charSequence is empty.AssertionError- if the givenCharSequenceisnull.AssertionError- if the givenCharSequencedoes not contain the given sequence of charSequence.
-
assertContainsSubsequence
public void assertContainsSubsequence(AssertionInfo info, CharSequence actual, CharSequence[] subsequence)
Verifies that the actualCharSequencecontains all the given values in the given order (possibly with other values between them).- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.subsequence- the Strings to look for, in order.- Throws:
AssertionError- if the givenCharSequenceisnull.NullPointerException- if the given subsequence isnull.IllegalArgumentException- if the given subsequence is empty.AssertionError- if the givenCharSequencedoes not contain the given subsequence of charSequence.
-
removeUpTo
private String removeUpTo(String string, CharSequence toRemove)
-
indexOf
private int indexOf(String string, CharSequence toFind)
-
assertXmlEqualsTo
public void assertXmlEqualsTo(AssertionInfo info, CharSequence actualXml, CharSequence expectedXml)
-
assertIsSubstringOf
public void assertIsSubstringOf(AssertionInfo info, CharSequence actual, CharSequence sequence)
-
assertContainsPattern
public void assertContainsPattern(AssertionInfo info, CharSequence actual, CharSequence regex)
Verifies that the givenCharSequencecontains the given regular expression.- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.regex- the regular expression to find in the actualCharSequence.- Throws:
NullPointerException- if the given pattern isnull.PatternSyntaxException- if the regular expression's syntax is invalid.AssertionError- if the givenCharSequenceisnull.AssertionError- if the actualCharSequencedoes not contain the given regular expression.
-
assertContainsPattern
public void assertContainsPattern(AssertionInfo info, CharSequence actual, Pattern pattern)
Verifies that the givenCharSequencecontains the given regular expression.- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.pattern- the regular expression to find in the actualCharSequence.- Throws:
NullPointerException- if the given pattern isnull.AssertionError- if the givenCharSequenceisnull.AssertionError- if the givenCharSequencedoes not contain the given regular expression.
-
assertDoesNotContainPattern
public void assertDoesNotContainPattern(AssertionInfo info, CharSequence actual, CharSequence regex)
Verifies that the givenCharSequencedoes not contain the given regular expression.- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.regex- the regular expression to find in the actualCharSequence.- Throws:
NullPointerException- if the given pattern isnull.PatternSyntaxException- if the regular expression's syntax is invalid.AssertionError- if the givenCharSequenceisnull.AssertionError- if the actualCharSequencecontains the given regular expression.
-
assertDoesNotContainPattern
public void assertDoesNotContainPattern(AssertionInfo info, CharSequence actual, Pattern pattern)
Verifies that the givenCharSequencedoes not contain the given regular expression.- Parameters:
info- contains information about the assertion.actual- the givenCharSequence.pattern- the regular expression to find in the actualCharSequence.- Throws:
NullPointerException- if the given pattern isnull.AssertionError- if the givenCharSequenceisnull.AssertionError- if the givenCharSequencecontains the given regular expression.
-
checkCharSequenceArrayDoesNotHaveNullElements
private void checkCharSequenceArrayDoesNotHaveNullElements(CharSequence[] values)
-
assertIsEqualToIgnoringNewLines
public void assertIsEqualToIgnoringNewLines(AssertionInfo info, CharSequence actual, CharSequence expected)
Verifies that actual is equal to expected ignoring new lines- Parameters:
info- contains information about the assertion.actual- the actualCharSequence(new lines will be ignored).expected- the expectedCharSequence(new lines will be ignored).
-
assertLowerCase
public void assertLowerCase(AssertionInfo info, CharSequence actual)
-
assertUpperCase
public void assertUpperCase(AssertionInfo info, CharSequence actual)
-
removeNewLines
private static String removeNewLines(CharSequence text)
-
doCommonCheckForCharSequence
private void doCommonCheckForCharSequence(AssertionInfo info, CharSequence actual, CharSequence[] sequence)
-
-