public class Strings
extends java.lang.Object
CharSequence
s.Modifier and Type | Field and Description |
---|---|
private ComparisonStrategy |
comparisonStrategy |
(package private) Failures |
failures |
private static Strings |
INSTANCE |
Constructor and Description |
---|
Strings() |
Strings(ComparisonStrategy comparisonStrategy) |
Modifier and Type | Method and Description |
---|---|
private boolean |
areEqualIgnoringCase(java.lang.CharSequence actual,
java.lang.CharSequence expected) |
private boolean |
areEqualIgnoringWhitespace(java.lang.CharSequence actual,
java.lang.CharSequence expected) |
void |
assertContains(AssertionInfo info,
java.lang.CharSequence actual,
java.lang.CharSequence... values)
Verifies that the given
CharSequence contains the given strings. |
void |
assertContainsIgnoringCase(AssertionInfo info,
java.lang.CharSequence actual,
java.lang.CharSequence sequence)
Verifies that the given
CharSequence contains the given sequence, ignoring case considerations. |
void |
assertContainsOnlyDigits(AssertionInfo info,
java.lang.CharSequence actual)
Verifies that the given
CharSequence contains only digits. |
void |
assertContainsOnlyOnce(AssertionInfo info,
java.lang.CharSequence actual,
java.lang.CharSequence sequence)
Verifies that actual
CharSequence s contains only once the given sequence. |
void |
assertContainsSequence(AssertionInfo info,
java.lang.CharSequence actual,
java.lang.CharSequence[] values) |
void |
assertDoesNotContain(AssertionInfo info,
java.lang.CharSequence actual,
java.lang.CharSequence sequence)
Verifies that the given
CharSequence does not contain the given sequence. |
void |
assertDoesNotEndWith(AssertionInfo info,
java.lang.CharSequence actual,
java.lang.CharSequence suffix)
Verifies that the given
CharSequence does not end with the given suffix. |
void |
assertDoesNotMatch(AssertionInfo info,
java.lang.CharSequence actual,
java.lang.CharSequence regex)
Verifies that the given
CharSequence does not match the given regular expression. |
void |
assertDoesNotMatch(AssertionInfo info,
java.lang.CharSequence actual,
java.util.regex.Pattern pattern)
Verifies that the given
CharSequence does not match the given regular expression. |
void |
assertDoesNotStartWith(AssertionInfo info,
java.lang.CharSequence actual,
java.lang.CharSequence prefix)
Verifies that the given
CharSequence does not start with the given prefix. |
void |
assertEmpty(AssertionInfo info,
java.lang.CharSequence actual)
Asserts that the given
CharSequence is empty. |
void |
assertEndsWith(AssertionInfo info,
java.lang.CharSequence actual,
java.lang.CharSequence suffix)
Verifies that the given
CharSequence ends with the given suffix. |
void |
assertEqualsIgnoringCase(AssertionInfo info,
java.lang.CharSequence actual,
java.lang.CharSequence expected)
Verifies that two
CharSequence s are equal, ignoring case considerations. |
void |
assertEqualsIgnoringWhitespace(AssertionInfo info,
java.lang.CharSequence actual,
java.lang.CharSequence expected)
Verifies that two
CharSequence s are equal, ignoring any changes in whitespace. |
void |
assertHasLineCount(AssertionInfo info,
java.lang.CharSequence actual,
int expectedLineCount)
Asserts that the line count of the given
CharSequence is equal to the expected one. |
void |
assertHasSameSizeAs(AssertionInfo info,
java.lang.CharSequence actual,
java.lang.CharSequence other) |
void |
assertHasSameSizeAs(AssertionInfo info,
java.lang.CharSequence actual,
java.lang.Iterable<?> other)
Asserts that the number of entries in the given
CharSequence has the same size as the other
Iterable . |
void |
assertHasSameSizeAs(AssertionInfo info,
java.lang.CharSequence actual,
java.lang.Object array)
Asserts that the number of entries in the given
CharSequence has the same size as the other array. |
void |
assertHasSize(AssertionInfo info,
java.lang.CharSequence actual,
int expectedSize)
Asserts that the size of the given
CharSequence is equal to the expected one. |
void |
assertIsSubstringOf(AssertionInfo info,
java.lang.CharSequence actual,
java.lang.CharSequence sequence) |
void |
assertMatches(AssertionInfo info,
java.lang.CharSequence actual,
java.lang.CharSequence regex)
Verifies that the given
CharSequence matches the given regular expression. |
void |
assertMatches(AssertionInfo info,
java.lang.CharSequence actual,
java.util.regex.Pattern pattern)
Verifies that the given
CharSequence matches the given regular expression. |
void |
assertNotEmpty(AssertionInfo info,
java.lang.CharSequence actual)
Asserts that the given
CharSequence is not empty. |
void |
assertNotEqualsIgnoringCase(AssertionInfo info,
java.lang.CharSequence actual,
java.lang.CharSequence expected)
Verifies that two
CharSequence s are not equal, ignoring case considerations. |
private void |
assertNotNull(AssertionInfo info,
java.lang.CharSequence actual) |
void |
assertNullOrEmpty(AssertionInfo info,
java.lang.CharSequence actual)
Asserts that the given
CharSequence is null or empty. |
void |
assertStartsWith(AssertionInfo info,
java.lang.CharSequence actual,
java.lang.CharSequence prefix)
Verifies that the given
CharSequence starts with the given prefix. |
void |
assertXmlEqualsTo(AssertionInfo info,
java.lang.CharSequence actualXml,
java.lang.CharSequence expectedXml) |
private void |
checkCharSequenceIsNotNull(java.lang.CharSequence sequence) |
private void |
checkIsNotEmpty(java.lang.CharSequence... values) |
private void |
checkIsNotNull(java.lang.CharSequence... values) |
private void |
checkIsNotNull(java.util.regex.Pattern pattern) |
private void |
checkRegexIsNotNull(java.lang.CharSequence regex) |
private int |
countOccurences(java.lang.CharSequence sequenceToSearch,
java.lang.CharSequence actual)
Count occurrences of sequenceToSearch in actual
CharSequence . |
private static void |
failIfPrefixIsNull(java.lang.CharSequence prefix) |
private static void |
failIfSuffixIsNull(java.lang.CharSequence suffix) |
java.util.Comparator<?> |
getComparator() |
private static boolean |
hasContent(java.lang.CharSequence s) |
static Strings |
instance()
Returns the singleton instance of this class based on
StandardComparisonStrategy . |
private java.lang.NullPointerException |
patternToMatchIsNull() |
private java.lang.String |
removeAllWhitespaces(java.lang.CharSequence toBeStripped) |
private boolean |
stringContains(java.lang.CharSequence actual,
java.lang.CharSequence sequence)
Delegates to
ComparisonStrategy.stringContains(String, String) |
private static final Strings INSTANCE
private final ComparisonStrategy comparisonStrategy
Failures failures
Strings()
public Strings(ComparisonStrategy comparisonStrategy)
public static Strings instance()
StandardComparisonStrategy
.StandardComparisonStrategy
.public java.util.Comparator<?> getComparator()
public void assertNullOrEmpty(AssertionInfo info, java.lang.CharSequence actual)
CharSequence
is null
or empty.info
- contains information about the assertion.actual
- the given CharSequence
.java.lang.AssertionError
- if the given CharSequence
is not null
*and* it is not empty.public void assertEmpty(AssertionInfo info, java.lang.CharSequence actual)
CharSequence
is empty.info
- contains information about the assertion.actual
- the given CharSequence
.java.lang.AssertionError
- if the given CharSequence
is null
.java.lang.AssertionError
- if the given CharSequence
is not empty.public void assertNotEmpty(AssertionInfo info, java.lang.CharSequence actual)
CharSequence
is not empty.info
- contains information about the assertion.actual
- the given CharSequence
.java.lang.AssertionError
- if the given CharSequence
is null
.java.lang.AssertionError
- if the given CharSequence
is empty.private static boolean hasContent(java.lang.CharSequence s)
public void assertHasSize(AssertionInfo info, java.lang.CharSequence actual, int expectedSize)
CharSequence
is equal to the expected one.info
- contains information about the assertion.actual
- the given CharSequence
.expectedSize
- the expected size of actual
.java.lang.AssertionError
- if the given CharSequence
is null
.java.lang.AssertionError
- if the size of the given CharSequence
is different than the expected one.public void assertHasLineCount(AssertionInfo info, java.lang.CharSequence actual, int expectedLineCount)
CharSequence
is equal to the expected one.info
- contains information about the assertion.actual
- the given CharSequence
.expectedLineCount
- the expected line count of actual
.java.lang.AssertionError
- if the given CharSequence
is null
.java.lang.AssertionError
- if the line count of the given CharSequence
is different than the expected one.public void assertHasSameSizeAs(AssertionInfo info, java.lang.CharSequence actual, java.lang.Iterable<?> other)
CharSequence
has the same size as the other
Iterable
.info
- contains information about the assertion.actual
- the given CharSequence
.other
- the group to comparejava.lang.AssertionError
- if the given CharSequence
is null
.java.lang.AssertionError
- if the given Iterable
is null
.java.lang.AssertionError
- if the number of entries in the given CharSequence
does not have the same size.public void assertHasSameSizeAs(AssertionInfo info, java.lang.CharSequence actual, java.lang.Object array)
CharSequence
has the same size as the other array.info
- contains information about the assertion.actual
- the given CharSequence
.array
- the array to comparejava.lang.AssertionError
- if the given CharSequence
is null
.java.lang.AssertionError
- if the given array is null
.java.lang.AssertionError
- if the number of entries in the given CharSequence
does not have the same size.public void assertHasSameSizeAs(AssertionInfo info, java.lang.CharSequence actual, java.lang.CharSequence other)
public void assertContains(AssertionInfo info, java.lang.CharSequence actual, java.lang.CharSequence... values)
CharSequence
contains the given strings.info
- contains information about the assertion.actual
- the actual CharSequence
.values
- the values to look for.java.lang.NullPointerException
- if the given sequence is null
.java.lang.IllegalArgumentException
- if the given values is empty.java.lang.AssertionError
- if the given CharSequence
is null
.java.lang.AssertionError
- if the actual CharSequence
does not contain the given sequence.public void assertContainsOnlyDigits(AssertionInfo info, java.lang.CharSequence actual)
CharSequence
contains only digits.info
- contains information about the assertion.actual
- the given CharSequence
.java.lang.NullPointerException
- if actual
is null
.java.lang.AssertionError
- if actual
contains non-digit characters or contains no digits at all.private void checkIsNotNull(java.lang.CharSequence... values)
private void checkIsNotEmpty(java.lang.CharSequence... values)
private boolean stringContains(java.lang.CharSequence actual, java.lang.CharSequence sequence)
ComparisonStrategy.stringContains(String, String)
public void assertContainsIgnoringCase(AssertionInfo info, java.lang.CharSequence actual, java.lang.CharSequence sequence)
CharSequence
contains the given sequence, ignoring case considerations.info
- contains information about the assertion.actual
- the actual CharSequence
.sequence
- the sequence to search for.java.lang.NullPointerException
- if the given sequence is null
.java.lang.AssertionError
- if the given CharSequence
is null
.java.lang.AssertionError
- if the actual CharSequence
does not contain the given sequence.public void assertDoesNotContain(AssertionInfo info, java.lang.CharSequence actual, java.lang.CharSequence sequence)
CharSequence
does not contain the given sequence.info
- contains information about the assertion.actual
- the actual CharSequence
.sequence
- the sequence to search for.java.lang.NullPointerException
- if the given sequence is null
.java.lang.AssertionError
- if the given CharSequence
is null
.java.lang.AssertionError
- if the actual CharSequence
contains the given sequence.private void checkCharSequenceIsNotNull(java.lang.CharSequence sequence)
public void assertEqualsIgnoringCase(AssertionInfo info, java.lang.CharSequence actual, java.lang.CharSequence expected)
CharSequence
s are equal, ignoring case considerations.info
- contains information about the assertion.actual
- the actual CharSequence
.expected
- the expected CharSequence
.java.lang.AssertionError
- if the given CharSequence
s are not equal.public void assertNotEqualsIgnoringCase(AssertionInfo info, java.lang.CharSequence actual, java.lang.CharSequence expected)
CharSequence
s are not equal, ignoring case considerations.info
- contains information about the assertion.actual
- the actual CharSequence
.expected
- the expected CharSequence
.java.lang.AssertionError
- if the given CharSequence
s are equal ignoring case considerations.private boolean areEqualIgnoringCase(java.lang.CharSequence actual, java.lang.CharSequence expected)
public void assertEqualsIgnoringWhitespace(AssertionInfo info, java.lang.CharSequence actual, java.lang.CharSequence expected)
CharSequence
s are equal, ignoring any changes in whitespace.info
- contains information about the assertion.actual
- the actual CharSequence
.expected
- the expected CharSequence
.java.lang.AssertionError
- if the given CharSequence
s are not equal.private boolean areEqualIgnoringWhitespace(java.lang.CharSequence actual, java.lang.CharSequence expected)
private java.lang.String removeAllWhitespaces(java.lang.CharSequence toBeStripped)
public void assertContainsOnlyOnce(AssertionInfo info, java.lang.CharSequence actual, java.lang.CharSequence sequence)
CharSequence
s contains only once the given sequence.info
- contains information about the assertion.actual
- the actual CharSequence
.sequence
- the given CharSequence
.java.lang.NullPointerException
- if the given sequence is null
.java.lang.AssertionError
- if the given CharSequence
is null
.java.lang.AssertionError
- if the actual CharSequence
does not contains only once the given
CharSequence
.private int countOccurences(java.lang.CharSequence sequenceToSearch, java.lang.CharSequence actual)
CharSequence
.sequenceToSearch
- the sequence to search in in actual CharSequence
.actual
- the CharSequence
to search occurrences in.CharSequence
.public void assertStartsWith(AssertionInfo info, java.lang.CharSequence actual, java.lang.CharSequence prefix)
CharSequence
starts with the given prefix.info
- contains information about the assertion.actual
- the actual CharSequence
.prefix
- the given prefix.java.lang.NullPointerException
- if the given sequence is null
.java.lang.AssertionError
- if the given CharSequence
is null
.java.lang.AssertionError
- if the actual CharSequence
does not start with the given prefix.public void assertDoesNotStartWith(AssertionInfo info, java.lang.CharSequence actual, java.lang.CharSequence prefix)
CharSequence
does not start with the given prefix.info
- contains information about the assertion.actual
- the actual CharSequence
.prefix
- the given prefix.java.lang.NullPointerException
- if the given sequence is null
.java.lang.AssertionError
- if the given CharSequence
is null
.java.lang.AssertionError
- if the actual CharSequence
starts with the given prefix.private static void failIfPrefixIsNull(java.lang.CharSequence prefix)
public void assertEndsWith(AssertionInfo info, java.lang.CharSequence actual, java.lang.CharSequence suffix)
CharSequence
ends with the given suffix.info
- contains information about the assertion.actual
- the actual CharSequence
.suffix
- the given suffix.java.lang.NullPointerException
- if the given sequence is null
.java.lang.AssertionError
- if the given CharSequence
is null
.java.lang.AssertionError
- if the actual CharSequence
does not end with the given suffix.public void assertDoesNotEndWith(AssertionInfo info, java.lang.CharSequence actual, java.lang.CharSequence suffix)
CharSequence
does not end with the given suffix.info
- contains information about the assertion.actual
- the actual CharSequence
.suffix
- the given suffix.java.lang.NullPointerException
- if the given sequence is null
.java.lang.AssertionError
- if the given CharSequence
is null
.java.lang.AssertionError
- if the actual CharSequence
ends with the given suffix.private static void failIfSuffixIsNull(java.lang.CharSequence suffix)
public void assertMatches(AssertionInfo info, java.lang.CharSequence actual, java.lang.CharSequence regex)
CharSequence
matches the given regular expression.info
- contains information about the assertion.actual
- the given CharSequence
.regex
- the regular expression to which the actual CharSequence
is to be matched.java.lang.NullPointerException
- if the given pattern is null
.java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalid.java.lang.AssertionError
- if the given CharSequence
is null
.java.lang.AssertionError
- if the actual CharSequence
does not match the given regular expression.public void assertDoesNotMatch(AssertionInfo info, java.lang.CharSequence actual, java.lang.CharSequence regex)
CharSequence
does not match the given regular expression.info
- contains information about the assertion.actual
- the given CharSequence
.regex
- the regular expression to which the actual CharSequence
is to be matched.java.lang.NullPointerException
- if the given pattern is null
.java.util.regex.PatternSyntaxException
- if the regular expression's syntax is invalid.java.lang.AssertionError
- if the given CharSequence
is null
.java.lang.AssertionError
- if the actual CharSequence
matches the given regular expression.private void checkRegexIsNotNull(java.lang.CharSequence regex)
public void assertMatches(AssertionInfo info, java.lang.CharSequence actual, java.util.regex.Pattern pattern)
CharSequence
matches the given regular expression.info
- contains information about the assertion.actual
- the given CharSequence
.pattern
- the regular expression to which the actual CharSequence
is to be matched.java.lang.NullPointerException
- if the given pattern is null
.java.lang.AssertionError
- if the given CharSequence
is null
.java.lang.AssertionError
- if the given CharSequence
does not match the given regular expression.public void assertDoesNotMatch(AssertionInfo info, java.lang.CharSequence actual, java.util.regex.Pattern pattern)
CharSequence
does not match the given regular expression.info
- contains information about the assertion.actual
- the given CharSequence
.pattern
- the regular expression to which the actual CharSequence
is to be matched.java.lang.NullPointerException
- if the given pattern is null
.java.lang.AssertionError
- if the given CharSequence
matches the given regular expression.private void checkIsNotNull(java.util.regex.Pattern pattern)
private java.lang.NullPointerException patternToMatchIsNull()
private void assertNotNull(AssertionInfo info, java.lang.CharSequence actual)
public void assertContainsSequence(AssertionInfo info, java.lang.CharSequence actual, java.lang.CharSequence[] values)
public void assertXmlEqualsTo(AssertionInfo info, java.lang.CharSequence actualXml, java.lang.CharSequence expectedXml)
public void assertIsSubstringOf(AssertionInfo info, java.lang.CharSequence actual, java.lang.CharSequence sequence)