Package org.assertj.core.internal
Class Strings
- java.lang.Object
-
- org.assertj.core.internal.Strings
-
public class Strings extends Object
Reusable assertions for
s.CharSequence
- Author:
- Alex Ruiz, Joel Costigliola, Nicolas François, Mikhail Mazursky, Michal Kordas
-
-
Constructor Summary
Constructors Constructor Description Strings(ComparisonStrategy comparisonStrategy)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
assertBlank(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequence
isNull
, empty or contains only whitespace.void
assertContains(AssertionInfo info, CharSequence actual, CharSequence... values)
Verifies that the givenCharSequence
contains the given strings.void
assertContainsIgnoringCase(AssertionInfo info, CharSequence actual, CharSequence sequence)
Verifies that the givenCharSequence
contains the given sequence, ignoring case considerations.void
assertContainsOnlyDigits(AssertionInfo info, CharSequence actual)
Verifies that the givenCharSequence
contains only digits.void
assertContainsOnlyOnce(AssertionInfo info, CharSequence actual, CharSequence sequence)
Verifies that actualCharSequence
s contains only once the given sequence.void
assertContainsPattern(AssertionInfo info, CharSequence actual, CharSequence regex)
Verifies that the givenCharSequence
contains the given regular expression.void
assertContainsPattern(AssertionInfo info, CharSequence actual, Pattern pattern)
Verifies that the givenCharSequence
contains the given regular expression.void
assertContainsSequence(AssertionInfo info, CharSequence actual, CharSequence[] sequence)
void
assertDoesNotContain(AssertionInfo info, CharSequence actual, CharSequence sequence)
Verifies that the givenCharSequence
does not contain the given sequence.void
assertDoesNotContainPattern(AssertionInfo info, CharSequence actual, CharSequence regex)
Verifies that the givenCharSequence
does not contain the given regular expression.void
assertDoesNotContainPattern(AssertionInfo info, CharSequence actual, Pattern pattern)
Verifies that the givenCharSequence
does not contain the given regular expression.void
assertDoesNotEndWith(AssertionInfo info, CharSequence actual, CharSequence suffix)
Verifies that the givenCharSequence
does not end with the given suffix.void
assertDoesNotMatch(AssertionInfo info, CharSequence actual, CharSequence regex)
Verifies that the givenCharSequence
does not match the given regular expression.void
assertDoesNotMatch(AssertionInfo info, CharSequence actual, Pattern pattern)
Verifies that the givenCharSequence
does not match the given regular expression.void
assertDoesNotStartWith(AssertionInfo info, CharSequence actual, CharSequence prefix)
Verifies that the givenCharSequence
does not start with the given prefix.void
assertEmpty(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequence
is empty.void
assertEndsWith(AssertionInfo info, CharSequence actual, CharSequence suffix)
Verifies that the givenCharSequence
ends with the given suffix.void
assertEqualsIgnoringCase(AssertionInfo info, CharSequence actual, CharSequence expected)
Verifies that twoCharSequence
s are equal, ignoring case considerations.void
assertEqualsIgnoringWhitespace(AssertionInfo info, CharSequence actual, CharSequence expected)
Verifies that twoCharSequence
s are equal, ignoring any differences in whitespace.void
assertEqualsNormalizingWhitespace(AssertionInfo info, CharSequence actual, CharSequence expected)
Verifies that twoCharSequence
s are equal, after the whitespace of both strings has been normalized.void
assertHasLineCount(AssertionInfo info, CharSequence actual, int expectedLineCount)
Asserts that the line count of the givenCharSequence
is equal to the expected one.void
assertHasSameSizeAs(AssertionInfo info, CharSequence actual, CharSequence other)
void
assertHasSameSizeAs(AssertionInfo info, CharSequence actual, Iterable<?> other)
Asserts that the number of entries in the givenCharSequence
has the same size as the otherIterable
.void
assertHasSameSizeAs(AssertionInfo info, CharSequence actual, Object array)
Asserts that the number of entries in the givenCharSequence
has the same size as the other array.void
assertHasSize(AssertionInfo info, CharSequence actual, int expectedSize)
Asserts that the size of the givenCharSequence
is equal to the expected one.void
assertIsEqualToNormalizingNewlines(AssertionInfo info, CharSequence actual, CharSequence expected)
Verifies that twoCharSequence
s are not equal, normalizing newlines.void
assertIsSubstringOf(AssertionInfo info, CharSequence actual, CharSequence sequence)
void
assertJavaBlank(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequence
isNull
, empty or contains only whitespace according toCharacter.isWhitespace(char)
.void
assertMatches(AssertionInfo info, CharSequence actual, CharSequence regex)
Verifies that the givenCharSequence
matches the given regular expression.void
assertMatches(AssertionInfo info, CharSequence actual, Pattern pattern)
Verifies that the givenCharSequence
matches the given regular expression.void
assertNotBlank(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequence
is notNull
, not empty and contains not only whitespace.void
assertNotEmpty(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequence
is not empty.void
assertNotEqualsIgnoringCase(AssertionInfo info, CharSequence actual, CharSequence expected)
Verifies that twoCharSequence
s are not equal, ignoring case considerations.void
assertNotEqualsIgnoringWhitespace(AssertionInfo info, CharSequence actual, CharSequence expected)
Verifies that twoCharSequence
s are not equal, ignoring any differences in whitespace.void
assertNotEqualsNormalizingWhitespace(AssertionInfo info, CharSequence actual, CharSequence expected)
Verifies that twoCharSequence
s are not equal, after the whitespace of both strings has been normalized.void
assertNotJavaBlank(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequence
is notNull
, not empty or contains not only whitespace according toCharacter.isWhitespace(char)
.void
assertNullOrEmpty(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequence
isnull
or empty.void
assertStartsWith(AssertionInfo info, CharSequence actual, CharSequence prefix)
Verifies that the givenCharSequence
starts with the given prefix.void
assertXmlEqualsTo(AssertionInfo info, CharSequence actualXml, CharSequence expectedXml)
Comparator<?>
getComparator()
static Strings
instance()
Returns the singleton instance of this class based onStandardComparisonStrategy
.
-
-
-
Constructor Detail
-
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 givenCharSequence
isnull
or empty.- Parameters:
info
- contains information about the assertion.actual
- the givenCharSequence
.- Throws:
AssertionError
- if the givenCharSequence
is notnull
*and* it is not empty.
-
assertEmpty
public void assertEmpty(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequence
is empty.- Parameters:
info
- contains information about the assertion.actual
- the givenCharSequence
.- Throws:
AssertionError
- if the givenCharSequence
isnull
.AssertionError
- if the givenCharSequence
is not empty.
-
assertNotEmpty
public void assertNotEmpty(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequence
is not empty.- Parameters:
info
- contains information about the assertion.actual
- the givenCharSequence
.- Throws:
AssertionError
- if the givenCharSequence
isnull
.AssertionError
- if the givenCharSequence
is empty.
-
assertBlank
public void assertBlank(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequence
isNull
, empty or contains only whitespace.- Parameters:
info
- contains information about the assertion.actual
- the givenCharSequence
.- Throws:
AssertionError
- if the givenCharSequence
is not blank.
-
assertNotBlank
public void assertNotBlank(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequence
is notNull
, not empty and contains not only whitespace.- Parameters:
info
- contains information about the assertion.actual
- the givenCharSequence
.- Throws:
AssertionError
- if the givenCharSequence
is blank.
-
assertJavaBlank
public void assertJavaBlank(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequence
isNull
, empty or contains only whitespace according toCharacter.isWhitespace(char)
.- Parameters:
info
- contains information about the assertion.actual
- the givenCharSequence
.- Throws:
AssertionError
- if the givenCharSequence
is not blank.
-
assertNotJavaBlank
public void assertNotJavaBlank(AssertionInfo info, CharSequence actual)
Asserts that the givenCharSequence
is notNull
, not empty or contains not only whitespace according toCharacter.isWhitespace(char)
.- Parameters:
info
- contains information about the assertion.actual
- the givenCharSequence
.- Throws:
AssertionError
- if the givenCharSequence
is blank.
-
assertHasSize
public void assertHasSize(AssertionInfo info, CharSequence actual, int expectedSize)
Asserts that the size of the givenCharSequence
is equal to the expected one.- Parameters:
info
- contains information about the assertion.actual
- the givenCharSequence
.expectedSize
- the expected size ofactual
.- Throws:
AssertionError
- if the givenCharSequence
isnull
.AssertionError
- if the size of the givenCharSequence
is different than the expected one.
-
assertHasLineCount
public void assertHasLineCount(AssertionInfo info, CharSequence actual, int expectedLineCount)
Asserts that the line count of the givenCharSequence
is 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 givenCharSequence
isnull
.AssertionError
- if the line count of the givenCharSequence
is different than the expected one.
-
assertHasSameSizeAs
public void assertHasSameSizeAs(AssertionInfo info, CharSequence actual, Iterable<?> other)
Asserts that the number of entries in the givenCharSequence
has 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 givenCharSequence
isnull
.AssertionError
- if the givenIterable
isnull
.AssertionError
- if the number of entries in the givenCharSequence
does not have the same size.
-
assertHasSameSizeAs
public void assertHasSameSizeAs(AssertionInfo info, CharSequence actual, Object array)
Asserts that the number of entries in the givenCharSequence
has 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 givenCharSequence
isnull
.AssertionError
- if the given array isnull
.AssertionError
- if the number of entries in the givenCharSequence
does 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 givenCharSequence
contains 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 givenCharSequence
isnull
.AssertionError
- if the actualCharSequence
does not contain the given sequence.
-
assertContainsOnlyDigits
public void assertContainsOnlyDigits(AssertionInfo info, CharSequence actual)
Verifies that the givenCharSequence
contains only digits.- Parameters:
info
- contains information about the assertion.actual
- the givenCharSequence
.- Throws:
NullPointerException
- ifactual
isnull
.AssertionError
- ifactual
contains non-digit characters or contains no digits at all.
-
assertContainsIgnoringCase
public void assertContainsIgnoringCase(AssertionInfo info, CharSequence actual, CharSequence sequence)
Verifies that the givenCharSequence
contains 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 givenCharSequence
isnull
.AssertionError
- if the actualCharSequence
does not contain the given sequence.
-
assertDoesNotContain
public void assertDoesNotContain(AssertionInfo info, CharSequence actual, CharSequence sequence)
Verifies that the givenCharSequence
does not contain the given sequence.- 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 givenCharSequence
isnull
.AssertionError
- if the actualCharSequence
contains the given sequence.
-
assertEqualsIgnoringCase
public void assertEqualsIgnoringCase(AssertionInfo info, CharSequence actual, CharSequence expected)
Verifies that twoCharSequence
s are equal, ignoring case considerations.- Parameters:
info
- contains information about the assertion.actual
- the actualCharSequence
.expected
- the expectedCharSequence
.- Throws:
AssertionError
- if the givenCharSequence
s are not equal.
-
assertNotEqualsIgnoringCase
public void assertNotEqualsIgnoringCase(AssertionInfo info, CharSequence actual, CharSequence expected)
Verifies that twoCharSequence
s are not equal, ignoring case considerations.- Parameters:
info
- contains information about the assertion.actual
- the actualCharSequence
.expected
- the expectedCharSequence
.- Throws:
AssertionError
- if the givenCharSequence
s are equal ignoring case considerations.
-
assertIsEqualToNormalizingNewlines
public void assertIsEqualToNormalizingNewlines(AssertionInfo info, CharSequence actual, CharSequence expected)
Verifies that twoCharSequence
s 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 givenCharSequence
s are equal after normalizing newlines.
-
assertEqualsIgnoringWhitespace
public void assertEqualsIgnoringWhitespace(AssertionInfo info, CharSequence actual, CharSequence expected)
Verifies that twoCharSequence
s are equal, ignoring any differences in whitespace.- Parameters:
info
- contains information about the assertion.actual
- the actualCharSequence
.expected
- the expectedCharSequence
.- Throws:
AssertionError
- if the givenCharSequence
s are not equal.
-
assertNotEqualsIgnoringWhitespace
public void assertNotEqualsIgnoringWhitespace(AssertionInfo info, CharSequence actual, CharSequence expected)
Verifies that twoCharSequence
s 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 givenCharSequence
s are equal.
-
assertEqualsNormalizingWhitespace
public void assertEqualsNormalizingWhitespace(AssertionInfo info, CharSequence actual, CharSequence expected)
Verifies that twoCharSequence
s 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 givenCharSequence
s are not equal.- Since:
- 2.8.0 / 3.8.0
-
assertNotEqualsNormalizingWhitespace
public void assertNotEqualsNormalizingWhitespace(AssertionInfo info, CharSequence actual, CharSequence expected)
Verifies that twoCharSequence
s 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 givenCharSequence
s are equal.- Since:
- 2.8.0 / 3.8.0
-
assertContainsOnlyOnce
public void assertContainsOnlyOnce(AssertionInfo info, CharSequence actual, CharSequence sequence)
Verifies that actualCharSequence
s 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 givenCharSequence
isnull
.AssertionError
- if the actualCharSequence
does not contains only once the givenCharSequence
.
-
assertStartsWith
public void assertStartsWith(AssertionInfo info, CharSequence actual, CharSequence prefix)
Verifies that the givenCharSequence
starts 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 givenCharSequence
isnull
.AssertionError
- if the actualCharSequence
does not start with the given prefix.
-
assertDoesNotStartWith
public void assertDoesNotStartWith(AssertionInfo info, CharSequence actual, CharSequence prefix)
Verifies that the givenCharSequence
does 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 givenCharSequence
isnull
.AssertionError
- if the actualCharSequence
starts with the given prefix.
-
assertEndsWith
public void assertEndsWith(AssertionInfo info, CharSequence actual, CharSequence suffix)
Verifies that the givenCharSequence
ends 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 givenCharSequence
isnull
.AssertionError
- if the actualCharSequence
does not end with the given suffix.
-
assertDoesNotEndWith
public void assertDoesNotEndWith(AssertionInfo info, CharSequence actual, CharSequence suffix)
Verifies that the givenCharSequence
does 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 givenCharSequence
isnull
.AssertionError
- if the actualCharSequence
ends with the given suffix.
-
assertMatches
public void assertMatches(AssertionInfo info, CharSequence actual, CharSequence regex)
Verifies that the givenCharSequence
matches the given regular expression.- Parameters:
info
- contains information about the assertion.actual
- the givenCharSequence
.regex
- the regular expression to which the actualCharSequence
is to be matched.- Throws:
NullPointerException
- if the given pattern isnull
.PatternSyntaxException
- if the regular expression's syntax is invalid.AssertionError
- if the givenCharSequence
isnull
.AssertionError
- if the actualCharSequence
does not match the given regular expression.
-
assertDoesNotMatch
public void assertDoesNotMatch(AssertionInfo info, CharSequence actual, CharSequence regex)
Verifies that the givenCharSequence
does not match the given regular expression.- Parameters:
info
- contains information about the assertion.actual
- the givenCharSequence
.regex
- the regular expression to which the actualCharSequence
is to be matched.- Throws:
NullPointerException
- if the given pattern isnull
.PatternSyntaxException
- if the regular expression's syntax is invalid.AssertionError
- if the givenCharSequence
isnull
.AssertionError
- if the actualCharSequence
matches the given regular expression.
-
assertMatches
public void assertMatches(AssertionInfo info, CharSequence actual, Pattern pattern)
Verifies that the givenCharSequence
matches the given regular expression.- Parameters:
info
- contains information about the assertion.actual
- the givenCharSequence
.pattern
- the regular expression to which the actualCharSequence
is to be matched.- Throws:
NullPointerException
- if the given pattern isnull
.AssertionError
- if the givenCharSequence
isnull
.AssertionError
- if the givenCharSequence
does not match the given regular expression.
-
assertDoesNotMatch
public void assertDoesNotMatch(AssertionInfo info, CharSequence actual, Pattern pattern)
Verifies that the givenCharSequence
does not match the given regular expression.- Parameters:
info
- contains information about the assertion.actual
- the givenCharSequence
.pattern
- the regular expression to which the actualCharSequence
is to be matched.- Throws:
NullPointerException
- if the given pattern isnull
.AssertionError
- if the givenCharSequence
matches the given regular expression.
-
assertContainsSequence
public void assertContainsSequence(AssertionInfo info, CharSequence actual, CharSequence[] sequence)
-
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 givenCharSequence
contains 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 givenCharSequence
isnull
.AssertionError
- if the actualCharSequence
does not contain the given regular expression.
-
assertContainsPattern
public void assertContainsPattern(AssertionInfo info, CharSequence actual, Pattern pattern)
Verifies that the givenCharSequence
contains 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 givenCharSequence
isnull
.AssertionError
- if the givenCharSequence
does not contain the given regular expression.
-
assertDoesNotContainPattern
public void assertDoesNotContainPattern(AssertionInfo info, CharSequence actual, CharSequence regex)
Verifies that the givenCharSequence
does 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 givenCharSequence
isnull
.AssertionError
- if the actualCharSequence
contains the given regular expression.
-
assertDoesNotContainPattern
public void assertDoesNotContainPattern(AssertionInfo info, CharSequence actual, Pattern pattern)
Verifies that the givenCharSequence
does 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 givenCharSequence
isnull
.AssertionError
- if the givenCharSequence
contains the given regular expression.
-
-