SELF
- the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation"
for more details.ACTUAL
- the type of the "actual" value.public abstract class AbstractCharSequenceAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>,ACTUAL extends CharSequence> extends AbstractAssert<SELF,ACTUAL> implements EnumerableAssert<SELF,Character>
CharSequence
s.actual, info, myself
Constructor and Description |
---|
AbstractCharSequenceAssert(ACTUAL actual,
Class<?> selfType) |
Modifier and Type | Method and Description |
---|---|
SELF |
contains(CharSequence... values)
Verifies that the actual
CharSequence contains all the given values. |
SELF |
contains(Iterable<? extends CharSequence> values)
Verifies that the actual
CharSequence contains all the CharSequence s of the given Iterable. |
SELF |
containsIgnoringCase(CharSequence sequence)
Verifies that the actual
CharSequence contains the given sequence, ignoring case considerations. |
SELF |
containsOnlyDigits()
Verifies that the actual
CharSequence contains only digits. |
SELF |
containsOnlyOnce(CharSequence sequence)
Verifies that the actual
CharSequence contains the given sequence only once. |
SELF |
containsOnlyWhitespaces()
Verifies that the actual
CharSequence consists of one or more whitespace characters (according to
Character.isWhitespace(char) ). |
SELF |
containsPattern(CharSequence regex)
Verifies that the actual
CharSequence contains the given regular expression. |
SELF |
containsPattern(Pattern pattern)
Verifies that the actual
CharSequence contains the given regular expression pattern. |
SELF |
containsSequence(CharSequence... values)
Verifies that the actual
CharSequence contains the given sequence of values in the given order without any other values between them. |
SELF |
containsSequence(Iterable<? extends CharSequence> values)
Verifies that the actual
CharSequence contains all the values of the given Iterable in the Iterable
iteration order without any other values between them. |
SELF |
containsSubsequence(CharSequence... values)
Verifies that the actual
CharSequence contains all the given values in the given order
(possibly with other values between them). |
SELF |
containsSubsequence(Iterable<? extends CharSequence> values)
Verifies that the actual
CharSequence contains all the values of the given Iterable in the Iterable
iteration order (possibly with other values between them). |
SELF |
doesNotContain(CharSequence... values)
Verifies that the actual
CharSequence does not contain any of the given values. |
SELF |
doesNotContain(Iterable<? extends CharSequence> values)
Verifies that the actual
CharSequence does not contain any of the given Iterable. |
SELF |
doesNotContainOnlyWhitespaces()
Verifies that the actual
CharSequence is either:
null
empty
contains at least one non-whitespace character (according to Character.isWhitespace(char) ).
|
SELF |
doesNotContainPattern(CharSequence pattern)
Verifies that the actual
CharSequence does not contain the given regular expression. |
SELF |
doesNotContainPattern(Pattern pattern)
Verifies that the actual
CharSequence does not contain the given regular expression. |
SELF |
doesNotEndWith(CharSequence suffix)
Verifies that the actual
CharSequence does not end with the given suffix. |
SELF |
doesNotMatch(CharSequence regex)
Verifies that the actual
CharSequence does not match the given regular expression. |
SELF |
doesNotMatch(Pattern pattern)
Verifies that the actual
CharSequence does not match the given regular expression pattern. |
SELF |
doesNotStartWith(CharSequence prefix)
Verifies that the actual
CharSequence does not start with the given prefix. |
SELF |
endsWith(CharSequence suffix)
Verifies that the actual
CharSequence ends with the given suffix. |
SELF |
hasLineCount(int expectedLineCount)
Verifies that the actual
CharSequence has the expected line count. |
SELF |
hasSameSizeAs(CharSequence other)
Verifies that the actual
CharSequence has a length that's the same as the length of the given
CharSequence . |
SELF |
hasSameSizeAs(Iterable<?> other)
Verifies that the actual
CharSequence has a length that's the same as the number of elements in the given
Iterable. |
SELF |
hasSameSizeAs(Object other)
Verifies that the actual
CharSequence has a length that's the same as the number of elements in the given
array. |
SELF |
hasSize(int expected)
Verifies that the actual
CharSequence has the expected length using the length() method. |
SELF |
inHexadecimal()
Use hexadecimal object representation instead of standard representation in error messages.
|
SELF |
inUnicode()
Use unicode character representation instead of standard representation in error messages.
|
SELF |
isBlank()
Verifies that the actual
CharSequence is blank, i.e. |
void |
isEmpty()
Verifies that the actual
CharSequence is empty, i.e., it has a length of 0 and is not null . |
SELF |
isEqualToIgnoringCase(CharSequence expected)
Verifies that the actual
CharSequence is equal to the given one, ignoring case considerations. |
SELF |
isEqualToIgnoringNewLines(CharSequence expected)
Verifies that the actual
CharSequence is equal to the given one after both strings new lines (\n, \r\n) have been removed. |
SELF |
isEqualToIgnoringWhitespace(CharSequence expected)
Verifies that the actual
CharSequence is equal to the given one, ignoring whitespace differences |
SELF |
isEqualToNormalizingNewlines(CharSequence expected)
Verifies that the actual
CharSequence is equals to another
CharSequence after normalizing new line characters
(i.e. |
SELF |
isEqualToNormalizingWhitespace(CharSequence expected)
Verifies that the actual
CharSequence is equal to the given one, after the whitespace
of both strings has been normalized.To be exact, the following rules are applied: all leading and trailing whitespace of both actual and expected strings are ignored any remaining whitespace, appearing within either string, is collapsed to a single space before comparison |
SELF |
isJavaBlank()
Deprecated.
Use
isBlank() instead. |
SELF |
isNotBlank()
Verifies that the actual
CharSequence is:
not null
not empty
contains at least one non-whitespace character (according to Character.isWhitespace(char) )
|
SELF |
isNotEmpty()
Verifies that the actual
CharSequence is not empty, i.e., is not null and has a length of 1 or
more. |
SELF |
isNotEqualToIgnoringCase(CharSequence expected)
Verifies that the actual
CharSequence is not equal to the given one, ignoring case considerations. |
SELF |
isNotEqualToIgnoringWhitespace(CharSequence expected)
Verifies that the actual
CharSequence is not equal to the given one, ignoring whitespace differences. |
SELF |
isNotEqualToNormalizingWhitespace(CharSequence expected)
Verifies that the actual
CharSequence is not equal to the given one, after the whitespace
of both strings has been normalized.To be exact, the following rules are applied: all leading and trailing whitespace of both actual and expected strings are ignored any remaining whitespace, appearing within either string, is collapsed to a single space before comparison |
SELF |
isNotJavaBlank()
Deprecated.
Use
isNotBlank() instead. |
void |
isNullOrEmpty()
Verifies that the actual
CharSequence is empty, i.e., it has a length of 0, or is null . |
SELF |
isSubstringOf(CharSequence sequence)
Verifies that the actual
CharSequence is a substring of the given one (opposite assertion of contains(CharSequence cs) . |
SELF |
isXmlEqualTo(CharSequence expectedXml)
Verifies that the actual
CharSequence is equal to the given XML CharSequence after both have been
formatted the same way. |
SELF |
isXmlEqualToContentOf(File xmlFile)
Verifies that the actual
CharSequence is equal to the content of the given file. |
SELF |
matches(CharSequence regex)
Verifies that the actual
CharSequence matches the given regular expression. |
SELF |
matches(Pattern pattern)
Verifies that the actual
CharSequence matches the given regular expression pattern. |
SELF |
startsWith(CharSequence prefix)
Verifies that the actual
CharSequence starts with the given prefix. |
SELF |
usingComparator(Comparator<? super ACTUAL> customComparator)
Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
|
SELF |
usingComparator(Comparator<? super ACTUAL> customComparator,
String customComparatorDescription)
Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
|
SELF |
usingDefaultComparator()
Revert to standard comparison for incoming assertion checks.
|
SELF |
usingDefaultElementComparator()
Deprecated.
Custom element Comparator is not supported for CharSequence comparison.
|
SELF |
usingElementComparator(Comparator<? super Character> customComparator)
Deprecated.
Custom element Comparator is not supported for CharSequence comparison.
|
as, as, asList, asString, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, inBinary, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, overridingErrorMessage, setCustomRepresentation, throwAssertionError, withFailMessage, withRepresentation, withThreadDumpOnError
public void isNullOrEmpty()
CharSequence
is empty, i.e., it has a length of 0, or is null
.
If you do not want to accept a null
value, use
isEmpty()
instead.
Both of these assertions will succeed:
String emptyString = ""
assertThat(emptyString).isNullOrEmpty();
String nullString = null;
assertThat(nullString).isNullOrEmpty();
Whereas these assertions will fail:
assertThat("a").isNullOrEmpty();
assertThat(" ").isNullOrEmpty();
isNullOrEmpty
in interface EnumerableAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>,Character>
AssertionError
- if the actual CharSequence
has a non-zero length.public void isEmpty()
CharSequence
is empty, i.e., it has a length of 0 and is not null
.
If you want to accept a null
value as well as a 0 length, use
isNullOrEmpty()
instead.
This assertion will succeed:
String emptyString = ""
assertThat(emptyString).isEmpty();
Whereas these assertions will fail:
String nullString = null;
assertThat(nullString).isEmpty();
assertThat("a").isEmpty();
assertThat(" ").isEmpty();
isEmpty
in interface EnumerableAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>,Character>
AssertionError
- if the actual CharSequence
has a non-zero length or is null.public SELF isNotEmpty()
CharSequence
is not empty, i.e., is not null
and has a length of 1 or
more.
This assertion will succeed:
String bookName = "A Game of Thrones"
assertThat(bookName).isNotEmpty();
Whereas these assertions will fail:
String emptyString = ""
assertThat(emptyString).isNotEmpty();
String nullString = null;
assertThat(nullString).isNotEmpty();
isNotEmpty
in interface EnumerableAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>,Character>
this
assertion object.AssertionError
- if the actual CharSequence
is empty (has a length of 0).public SELF isBlank()
CharSequence
is blank, i.e. is null
, empty or consists of one or more
whitespace characters (according to Character.isWhitespace(char)
).
The definition of this method has changed, the old behaviour is now under containsOnlyWhitespaces()
.
These assertions succeed:
assertThat(" ").isBlank();
assertThat("").isBlank();
assertThat(" ").isBlank();
String nullString = null;
assertThat(nullString).isBlank();
Whereas these assertions fail:
assertThat("a").isBlank();
assertThat(" b").isBlank();
assertThat(" c ").isBlank();
this
assertion object.AssertionError
- if the actual CharSequence
is not blank.public SELF isNotBlank()
CharSequence
is:
null
Character.isWhitespace(char)
)
The definition of this method has changed, the old behaviour is now under doesNotContainOnlyWhitespaces()
.
These assertions succeed:
assertThat("a").isNotBlank();
assertThat(" b").isNotBlank();
assertThat(" c ").isNotBlank();
Whereas these assertions fail:
assertThat(" ").isNotBlank();
assertThat("").isNotBlank();
assertThat(" ").isNotBlank();
String nullString = null;
assertThat(nullString).isNotBlank();
this
assertion object.AssertionError
- if the actual CharSequence
is blank.public SELF containsOnlyWhitespaces()
CharSequence
consists of one or more whitespace characters (according to
Character.isWhitespace(char)
).
These assertions will succeed:
assertThat(" ").containsOnlyWhitespaces();
assertThat(" ").containsOnlyWhitespaces();
Whereas these assertions will fail:
assertThat("a").containsOnlyWhitespaces();
assertThat("").containsOnlyWhitespaces();
assertThat(" b").containsOnlyWhitespaces();
assertThat(" c ").containsOnlyWhitespaces();
String nullString = null;
assertThat(nullString).containsOnlyWhitespaces();
this
assertion object.AssertionError
- if the actual CharSequence
is not blank.public SELF doesNotContainOnlyWhitespaces()
CharSequence
is either:
null
Character.isWhitespace(char)
).
The main difference with isNotBlank()
is that it accepts null or empty CharSequence
.
These assertions will succeed:
assertThat("a").doesNotContainOnlyWhitespaces();
assertThat("").doesNotContainOnlyWhitespaces();
assertThat(" b").doesNotContainOnlyWhitespaces();
assertThat(" c ").doesNotContainOnlyWhitespaces();
String nullString = null;
assertThat(nullString).doesNotContainOnlyWhitespaces();
Whereas these assertions will fail:
assertThat(" ").doesNotContainOnlyWhitespaces();
assertThat(" ").doesNotContainOnlyWhitespaces();
this
assertion object.AssertionError
- if the actual CharSequence
is blank.@Deprecated public SELF isJavaBlank()
isBlank()
instead.CharSequence
is blank, i.e. consists of one or more whitespace characters
(according to Character.isWhitespace(char)
).
These assertions will succeed:
assertThat(" ").isJavaBlank();
assertThat(" ").isJavaBlank();
Whereas these assertions will fail:
assertThat("a").isJavaBlank();
assertThat(" b").isJavaBlank();
assertThat("").isJavaBlank();
String nullString = null;
assertThat(nullString).isJavaBlank();
this
assertion object.AssertionError
- if the actual CharSequence
is not blank.@Deprecated public SELF isNotJavaBlank()
isNotBlank()
instead.CharSequence
is not blank, i.e. either is null
, empty or
contains at least one non-whitespace character (according to Character.isWhitespace(char)
).
These assertions will succeed:
assertThat("a").isNotJavaBlank();
assertThat(" b").isNotJavaBlank();
assertThat(" c ").isNotJavaBlank();
assertThat("").isNotJavaBlank();
String nullString = null;
assertThat(nullString).isNotJavaBlank();
Whereas these assertions will fail:
assertThat(" ").isNotJavaBlank();
assertThat(" ").isNotJavaBlank();
this
assertion object.AssertionError
- if the actual CharSequence
is blank.public SELF hasSize(int expected)
CharSequence
has the expected length using the length()
method.
This assertion will succeed:
String bookName = "A Game of Thrones"
assertThat(bookName).hasSize(17);
Whereas this assertion will fail:
String bookName = "A Clash of Kings"
assertThat(bookName).hasSize(4);
hasSize
in interface EnumerableAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>,Character>
expected
- the expected length of the actual CharSequence
.this
assertion object.AssertionError
- if the actual length is not equal to the expected length.public SELF hasLineCount(int expectedLineCount)
CharSequence
has the expected line count.
A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'),
or a carriage return followed immediately by a linefeed (see LineNumberReader
).
This assertion will succeed:
String multiLine = "First line\n" +
"Last line";
assertThat(multiLine).hasLineCount(2);
Whereas this assertion will fail:
String bookName = "A Clash of Kings";
assertThat(bookName).hasLineCount(3);
expectedLineCount
- the expected line count of the actual CharSequence
.this
assertion object.AssertionError
- if the actual line count is not equal to the expected one.public SELF hasSameSizeAs(CharSequence other)
CharSequence
has a length that's the same as the length of the given
CharSequence
.
Examples :
// assertion will pass
assertThat("C-3PO").hasSameSizeAs("R2-D2");
// assertion will fail as actual and expected sizes differ
assertThat("C-3PO").hasSameSizeAs("B1 battle droid");
other
- the given CharSequence
to be used for size comparison.this
assertion object.AssertionError
- if the actual CharSequence
has a length that's different from the length of the
given CharSequence
.NullPointerException
- if the given CharSequence
is null
.public SELF hasSameSizeAs(Object other)
CharSequence
has a length that's the same as the number of elements in the given
array.
Example:
// assertion will pass
assertThat("12").hasSameSizeAs(new char[] { 'a', 'b' });
// assertion will fail
assertThat("12").hasSameSizeAs(new char[] { 'a', 'b', 'c' });
hasSameSizeAs
in interface EnumerableAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>,Character>
other
- the given array to be used for size comparison.this
assertion object.AssertionError
- if the actual CharSequence
has a length that's different from the number of elements
in the array.NullPointerException
- if the given array is null
.public SELF hasSameSizeAs(Iterable<?> other)
CharSequence
has a length that's the same as the number of elements in the given
Iterable.
Example:
// assertion will pass
assertThat("abc").hasSameSizeAs(Arrays.asList(1, 2, 3));
// assertion will fail
assertThat("ab").hasSameSizeAs(Arrays.asList(1, 2, 3));
hasSameSizeAs
in interface EnumerableAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>,Character>
other
- the given Iterable
to be used for size comparison.this
assertion object.AssertionError
- if the actual CharSequence
has a length that's different from the number of elements
in the Iterable
.NullPointerException
- if the given Iterable
is null
.public SELF isEqualToIgnoringCase(CharSequence expected)
CharSequence
is equal to the given one, ignoring case considerations.
Example :
// assertion will pass
assertThat("Gandalf the grey").isEqualToIgnoringCase("GaNdAlF tHe GREY");
assertThat("Gandalf the grey").isEqualToIgnoringCase("Gandalf the grey");
// assertion will fail
assertThat("Gandalf the grey").isEqualToIgnoringCase("Gandalf the white");
expected
- the given CharSequence
to compare the actual CharSequence
to.this
assertion object.AssertionError
- if the actual CharSequence
is not equal to the given one.public SELF isNotEqualToIgnoringCase(CharSequence expected)
CharSequence
is not equal to the given one, ignoring case considerations.
Example :
// assertions will pass
assertThat("Gandalf").isNotEqualToIgnoringCase("Hobbit");
assertThat("Gandalf").isNotEqualToIgnoringCase("HOBit");
assertThat((String) null).isNotEqualToIgnoringCase("Gandalf");
assertThat("Gandalf").isNotEqualToIgnoringCase(null);
// assertions will fail
assertThat("Gandalf").isNotEqualToIgnoringCase("Gandalf");
assertThat("Gandalf").isNotEqualToIgnoringCase("GaNDalf");
assertThat((String) null).isNotEqualToIgnoringCase(null);
expected
- the given CharSequence
to compare the actual CharSequence
to.this
assertion object.AssertionError
- if the actual CharSequence
is not equal to the given one.public SELF containsOnlyDigits()
CharSequence
contains only digits. It fails if it contains non-digit
characters or is empty.
This assertion succeeds:
assertThat("10").containsOnlyDigits();
Whereas these assertions fail:
assertThat("10$").containsOnlyDigits();
assertThat("").containsOnlyDigits();
this
assertion object.AssertionError
- if the actual CharSequence
contains non-digit characters or is null
.public SELF containsOnlyOnce(CharSequence sequence)
CharSequence
contains the given sequence only once.
Example :
// assertion will pass
assertThat("Frodo").containsOnlyOnce("do");
// assertions will fail
assertThat("Frodo").containsOnlyOnce("o");
assertThat("Frodo").containsOnlyOnce("y");
sequence
- the sequence to search for.this
assertion object.AssertionError
- if the actual CharSequence
either does not contain the given one at all, or contains
it more than once.public SELF contains(CharSequence... values)
CharSequence
contains all the given values.
You can use one or several CharSequence
s as in this example:
assertThat("Gandalf the grey").contains("alf");
assertThat("Gandalf the grey").contains("alf", "grey");
values
- the Strings to look for.this
assertion object.NullPointerException
- if the given list of values is null
.IllegalArgumentException
- if the list of given values is empty.AssertionError
- if the actual CharSequence
is null
.AssertionError
- if the actual CharSequence
does not contain all the given strings.public SELF contains(Iterable<? extends CharSequence> values)
CharSequence
contains all the CharSequence
s of the given Iterable.
Examples:
assertThat("Gandalf the grey").contains(Arrays.asList("alf"));
assertThat("Gandalf the grey").contains(Arrays.asList("alf", "grey"));
values
- the Strings to look for.this
assertion object.NullPointerException
- if the given list of values is null
.IllegalArgumentException
- if the list of given values is empty.AssertionError
- if the actual CharSequence
is null
.AssertionError
- if the actual CharSequence
does not contain all the given values.public SELF containsSequence(CharSequence... values)
CharSequence
contains the given sequence of values in the given order without any other values between them.
Breaking change since 2.9.0: in previous versions this assertion behaved like containsSubsequence
and allowed other values between the sequence values.
Example:
String book = "{ 'title':'A Game of Thrones', 'author':'George Martin'}";
// this assertion succeeds
assertThat(book).containsSequence("'title'", ":", "'A Game of Thrones'");
// this assertion will fail because there are values between the expected sequence (e.g "'title':'")
assertThat(book).containsSequence("{", "A Game of Thrones", "George Martin", "}");
// this one fails as ":" must come after "'title'"
assertThat(book).containsSequence(":", "'title'", "'A Game of Thrones'");
values
- the sequence of charSequence to look for, in order.this
assertion object.NullPointerException
- if the given sequence of charSequence is null
.IllegalArgumentException
- if the given sequence of charSequence is empty.AssertionError
- if the given CharSequence
is null
.AssertionError
- if the given CharSequence
does not contain the given sequence of values in the given order without any other values between them.public SELF containsSequence(Iterable<? extends CharSequence> values)
CharSequence
contains all the values of the given Iterable in the Iterable
iteration order without any other values between them.
Breaking change since 2.9.0: in previous versions this assertion behaved like containsSubsequence
and allowed other values between the sequence values.
Example:
String book = "{ 'title':'A Game of Thrones', 'author':'George Martin'}";
// this assertion succeeds
assertThat(book).containsSequence(asList("'title'", ":", "'A Game of Thrones'"));
// this assertion will fail because there are values between the expected sequence (e.g "'title':'")
assertThat(book).containsSequence(asList("{", "A Game of Thrones", "George Martin", "}"));
// this one fails as "author" must come after "A Game of Thrones"
assertThat(book).containsSequence(asList("author", "A Game of Thrones"));
values
- the sequence of charSequence to look for, in order.this
assertion object.NullPointerException
- if the given sequence of charSequence is null
.IllegalArgumentException
- if the given sequence of charSequence is empty.AssertionError
- if the given CharSequence
is null
.AssertionError
- if the given CharSequence
does not contain the given sequence of values in the given order without any other charvalues between them.public SELF containsSubsequence(CharSequence... values)
CharSequence
contains all the given values in the given order
(possibly with other values between them).
Example:
String book = "{ 'title':'A Game of Thrones', 'author':'George Martin'}";
// this assertion succeeds
assertThat(book).containsSubsequence("'title'", ":", "'A Game of Thrones'");
// these ones succeed even if there are values between the given values
assertThat(book).containsSubsequence("{", "A Game of Thrones", "George Martin", "}");
assertThat(book).containsSubsequence("A", "Game", "of", "George");
// this one fails as "author" must come after "A Game of Thrones"
assertThat(book).containsSubsequence("{", "author", "A Game of Thrones", "}");
values
- the Strings to look for, in order.this
assertion object.NullPointerException
- if the given values is null
.IllegalArgumentException
- if the given values is empty.AssertionError
- if the actual CharSequence
is null
.AssertionError
- if the actual CharSequence
does not contain all the given values in the given order.public SELF containsSubsequence(Iterable<? extends CharSequence> values)
CharSequence
contains all the values of the given Iterable in the Iterable
iteration order (possibly with other values between them).
Example:
String book = "{ 'title':'A Game of Thrones', 'author':'George Martin'}";
// this assertion succeeds
assertThat(book).containsSubsequence(asList("'title'", ":", "'A Game of Thrones'"));
// these ones succeed even if there are values between the given values
assertThat(book).containsSubsequence(asList("{", "A Game of Thrones", "George Martin", "}"));
assertThat(book).containsSubsequence(asList("A", "Game", "of", "George"));
// but this one fails as "author" must come after "A Game of Thrones"
assertThat(book).containsSubsequence(asList("{", "author", "A Game of Thrones", "}"));
values
- the Strings to look for, in order.this
assertion object.NullPointerException
- if the given values is null
.IllegalArgumentException
- if the given values is empty.AssertionError
- if the actual CharSequence
is null
.AssertionError
- if the actual CharSequence
does not contain all the given values in the given order.public SELF containsIgnoringCase(CharSequence sequence)
CharSequence
contains the given sequence, ignoring case considerations.
Example :
// assertion will pass
assertThat("Gandalf the grey").containsIgnoringCase("gandalf");
// assertion will fail
assertThat("Gandalf the grey").containsIgnoringCase("white");
sequence
- the sequence to search for.this
assertion object.NullPointerException
- if the given sequence is null
.AssertionError
- if the actual CharSequence
is null
.AssertionError
- if the actual CharSequence
does not contain the given one.public SELF doesNotContain(CharSequence... values)
CharSequence
does not contain any of the given values.
Example :
// assertion will pass
assertThat("Frodo").doesNotContain("pippin")
.doesNotContain("fro", "sam");
// assertion will fail
assertThat("Frodo").doesNotContain("Fro", "Gimli", "Legolas");
values
- the CharSequences to search for.this
assertion object.NullPointerException
- if the given list of values is null
.IllegalArgumentException
- if the list of given values is empty.AssertionError
- if the actual CharSequence
is null
.AssertionError
- if the actual CharSequence
contains any of the given values.public SELF doesNotContain(Iterable<? extends CharSequence> values)
CharSequence
does not contain any of the given Iterable.
Example :
// assertion will pass
assertThat("Frodo").doesNotContain(Arrays.asList(""))
.doesNotContain(Arrays.asList("fro", "sam"));
// assertion will fail
assertThat("Frodo").doesNotContain(Arrays.asList("Fro", "Gimli", "Legolas"));
values
- the CharSequences to search for.this
assertion object.NullPointerException
- if the given list of values is null
.IllegalArgumentException
- if the list of given values is empty.AssertionError
- if the actual CharSequence
is null
.AssertionError
- if the actual CharSequence
contains any of the given values.public SELF doesNotContainPattern(CharSequence pattern)
CharSequence
does not contain the given regular expression.
Example :
// assertion will pass
assertThat("Frodo").doesNotContainPattern("Fr.ud");
// assertion will fail
assertThat("Freud").doesNotContainPattern("Fr.ud");
pattern
- the regular expression to find in the actual CharSequence
.this
assertion object.NullPointerException
- if the given pattern is null
.PatternSyntaxException
- if the regular expression's syntax is invalid.AssertionError
- if the actual CharSequence
is null
.AssertionError
- if the given regular expression can be found in the actual CharSequence
.public SELF doesNotContainPattern(Pattern pattern)
CharSequence
does not contain the given regular expression.
Example :
// assertion will pass
assertThat("Frodo").doesNotContainPattern(Pattern.compile("Fr.ud"));
// assertion will fail
assertThat("Freud").doesNotContainPattern(Pattern.compile("Fr.ud"));
pattern
- the regular expression to find in the actual CharSequence
.this
assertion object.NullPointerException
- if the given pattern is null
.AssertionError
- if the actual CharSequence
is null
.AssertionError
- if the given regular expression can be found in the actual CharSequence
.public SELF startsWith(CharSequence prefix)
CharSequence
starts with the given prefix.
Example :
// assertions will pass
assertThat("Frodo").startsWith("Fro");
assertThat("Gandalf the grey").startsWith("Gandalf");
// assertions will fail
assertThat("Frodo").startsWith("fro");
assertThat("Gandalf the grey").startsWith("grey");
prefix
- the given prefix.this
assertion object.NullPointerException
- if the given prefix is null
.AssertionError
- if the actual CharSequence
is null
.AssertionError
- if the actual CharSequence
does not start with the given prefix.public SELF doesNotStartWith(CharSequence prefix)
CharSequence
does not start with the given prefix.
Example:
// assertions will pass
assertThat("Frodo").doesNotStartWith("fro");
assertThat("Gandalf the grey").doesNotStartWith("grey");
// assertions will fail
assertThat("Gandalf the grey").doesNotStartWith("Gandalf");
assertThat("Frodo").doesNotStartWith("");
prefix
- the given prefix.this
assertion object.NullPointerException
- if the given prefix is null
.AssertionError
- if the actual CharSequence
is null
.AssertionError
- if the actual CharSequence
starts with the given prefix.public SELF endsWith(CharSequence suffix)
CharSequence
ends with the given suffix.
Example :
// assertion will pass
assertThat("Frodo").endsWith("do");
// assertion will fail
assertThat("Frodo").endsWith("Fro");
suffix
- the given suffix.this
assertion object.NullPointerException
- if the given suffix is null
.AssertionError
- if the actual CharSequence
is null
.AssertionError
- if the actual CharSequence
does not end with the given suffix.public SELF doesNotEndWith(CharSequence suffix)
CharSequence
does not end with the given suffix.
Example:
// assertion will pass
assertThat("Frodo").doesNotEndWith("Fro");
// assertions will fail
assertThat("Frodo").doesNotEndWith("do");
assertThat("Frodo").doesNotEndWith("");
suffix
- the given suffix.this
assertion object.NullPointerException
- if the given suffix is null
.AssertionError
- if the actual CharSequence
is null
.AssertionError
- if the actual CharSequence
ends with the given suffix.public SELF matches(CharSequence regex)
CharSequence
matches the given regular expression.
Example :
// assertion will pass
assertThat("Frodo").matches("..o.o");
// assertion will fail
assertThat("Frodo").matches(".*d");
regex
- the regular expression to which the actual CharSequence
is to be matched.this
assertion object.NullPointerException
- if the given pattern is null
.PatternSyntaxException
- if the regular expression's syntax is invalid.AssertionError
- if the actual CharSequence
is null
.AssertionError
- if the actual CharSequence
does not match the given regular expression.public SELF doesNotMatch(CharSequence regex)
CharSequence
does not match the given regular expression.
Example :
// assertion will pass
assertThat("Frodo").doesNotMatch(".*d");
// assertion will fail
assertThat("Frodo").doesNotMatch("..o.o");
regex
- the regular expression to which the actual CharSequence
is to be matched.this
assertion object.NullPointerException
- if the given pattern is null
.PatternSyntaxException
- if the regular expression's syntax is invalid.AssertionError
- if the actual CharSequence
is null
.AssertionError
- if the actual CharSequence
matches the given regular expression.public SELF matches(Pattern pattern)
CharSequence
matches the given regular expression pattern.
Example :
// assertion will pass
assertThat("Frodo").matches(Pattern.compile("..o.o"));
// assertion will fail
assertThat("Frodo").matches(Pattern.compile(".*d"));
pattern
- the regular expression to which the actual CharSequence
is to be matched.this
assertion object.NullPointerException
- if the given pattern is null
.AssertionError
- if the actual CharSequence
is null
.AssertionError
- if the actual CharSequence
does not match the given regular expression.public SELF doesNotMatch(Pattern pattern)
CharSequence
does not match the given regular expression pattern.
Example :
// assertion will pass
assertThat("Frodo").doesNotMatch(Pattern.compile(".*d"));
// assertion will fail
assertThat("Frodo").doesNotMatch(Pattern.compile("..o.o"));
pattern
- the regular expression to which the actual CharSequence
is to be matched.this
assertion object.NullPointerException
- if the given pattern is null
.AssertionError
- if the actual CharSequence
does not match the given regular expression.public SELF isXmlEqualTo(CharSequence expectedXml)
CharSequence
is equal to the given XML CharSequence
after both have been
formatted the same way.
Example :
String expectedXml =
"<rings>\n" +
" <bearer>\n" +
" <name>Frodo</name>\n" +
" <ring>\n" +
" <name>one ring</name>\n" +
" <createdBy>Sauron</createdBy>\n" +
" </ring>\n" +
" </bearer>\n" +
"</rings>";
// No matter how your xml string is formated, isXmlEqualTo is able to compare it's content with another xml String.
String oneLineXml = "<rings><bearer><name>Frodo</name><ring><name>one ring</name><createdBy>Sauron</createdBy></ring></bearer></rings>";
assertThat(oneLineXml).isXmlEqualTo(expectedXml);
String xmlWithNewLine =
"<rings>\n" +
"<bearer> \n" +
" <name>Frodo</name>\n" +
" <ring>\n" +
" <name>one ring</name>\n" +
" <createdBy>Sauron</createdBy>\n" +
" </ring>\n" +
"</bearer>\n" +
"</rings>";
assertThat(xmlWithNewLine).isXmlEqualTo(expectedXml);
// You can compare it with oneLineXml
assertThat(xmlWithNewLine).isXmlEqualTo(oneLineXml);
// Tip : use isXmlEqualToContentOf assertion to compare your XML String with the content of an XML file :
assertThat(oneLineXml).isXmlEqualToContentOf(new File("src/test/resources/formatted.xml"));
expectedXml
- the XML CharSequence
to which the actual CharSequence
is to be compared to.this
assertion object to chain other assertions.NullPointerException
- if the given CharSequence
is null
.AssertionError
- if the actual CharSequence
is null
or is not the same XML as the given XML
CharSequence
.public SELF isXmlEqualToContentOf(File xmlFile)
CharSequence
is equal to the content of the given file.
This is an handy shortcut that calls : isXmlEqualTo(contentOf(xmlFile))
// You can easily compare your XML String to the content of an XML file, whatever how formatted they are.
String oneLineXml = "<rings><bearer><name>Frodo</name><ring><name>one ring</name><createdBy>Sauron</createdBy></ring></bearer></rings>";
assertThat(oneLineXml).isXmlEqualToContentOf(new File("src/test/resources/formatted.xml"));
xmlFile
- the file to read the expected XML String to compare with actual CharSequence
this
assertion object to chain other assertions.NullPointerException
- if the given File
is null
.AssertionError
- if the actual CharSequence
is null
or is not the same XML as the content of
given File
.@Deprecated public final SELF usingElementComparator(Comparator<? super Character> customComparator)
usingElementComparator
in interface EnumerableAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>,Character>
customComparator
- the comparator to use for incoming assertion checks.this
assertion object.UnsupportedOperationException
- if this method is called.@Deprecated public final SELF usingDefaultElementComparator()
usingDefaultElementComparator
in interface EnumerableAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>,Character>
this
assertion object.UnsupportedOperationException
- if this method is called.public SELF usingComparator(Comparator<? super ACTUAL> customComparator)
AbstractAssert
Custom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default comparison strategy. Examples :
// frodo and sam are instances of Character with Hobbit race (obviously :).
// raceComparator implements Comparator<Character>
assertThat(frodo).usingComparator(raceComparator).isEqualTo(sam);
usingComparator
in interface Assert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>,ACTUAL extends CharSequence>
usingComparator
in class AbstractAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>,ACTUAL extends CharSequence>
customComparator
- the comparator to use for incoming assertion checks.this
assertion object.public SELF usingComparator(Comparator<? super ACTUAL> customComparator, String customComparatorDescription)
AbstractAssert
Custom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default comparison strategy. Examples :
// frodo and sam are instances of Character with Hobbit race (obviously :).
// raceComparator implements Comparator<Character>
assertThat(frodo).usingComparator(raceComparator, "Hobbit Race Comparator").isEqualTo(sam);
usingComparator
in interface Assert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>,ACTUAL extends CharSequence>
usingComparator
in class AbstractAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>,ACTUAL extends CharSequence>
customComparator
- the comparator to use for incoming assertion checks.customComparatorDescription
- comparator description to be used in assertion messagesthis
assertion object.public SELF usingDefaultComparator()
AbstractAssert
This method should be used to disable a custom comparison strategy set by calling
Assert.usingComparator(Comparator)
.
usingDefaultComparator
in interface Assert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>,ACTUAL extends CharSequence>
usingDefaultComparator
in class AbstractAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>,ACTUAL extends CharSequence>
this
assertion object.public SELF inHexadecimal()
AbstractAssert
It can be useful when comparing UNICODE characters - many unicode chars have duplicate characters assigned, it is thus impossible to find differences from the standard error message:
With standard message:
assertThat("µµµ").contains("μμμ");
java.lang.AssertionError:
Expecting:
<"µµµ">
to contain:
<"μμμ">
With Hexadecimal message:
assertThat("µµµ").inHexadecimal().contains("μμμ");
java.lang.AssertionError:
Expecting:
<"['00B5', '00B5', '00B5']">
to contain:
<"['03BC', '03BC', '03BC']">
inHexadecimal
in class AbstractAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>,ACTUAL extends CharSequence>
this
assertion object.public SELF inUnicode()
It can be useful when comparing UNICODE characters - many unicode chars have duplicate characters assigned, it is thus impossible to find differences from the standard error message:
With standard message:
assertThat("µµµ").contains("μμμ");
java.lang.AssertionError:
Expecting:
<"µµµ">
to contain:
<"μμμ">
With Hexadecimal message:
assertThat("µµµ").inUnicode().contains("μμμ");
java.lang.AssertionError:
Expecting:
<µµµ>
to contain:
<μμμ>
this
assertion object.public SELF isEqualToIgnoringWhitespace(CharSequence expected)
CharSequence
is equal to the given one, ignoring whitespace differences
Examples :
// assertions will pass
assertThat("Game of Thrones").isEqualToIgnoringWhitespace("Game of Thrones")
.isEqualToIgnoringWhitespace(" Game of Thrones ")
.isEqualToIgnoringWhitespace(" Game of Thrones ")
.isEqualToIgnoringWhitespace("Gameof Thrones")
.isEqualToIgnoringWhitespace("Game of\tThrones")
.isEqualToIgnoringWhitespace("GameofThrones");
// assertion will fail
assertThat("Game of Thrones").isEqualToIgnoringWhitespace("Game OF Thrones");
This assertion behavior has changed in 2.8.0 to really ignore all whitespaces,
the old behaviour has been kept in the better named isEqualToNormalizingWhitespace(CharSequence)
.
expected
- the given CharSequence
to compare the actual CharSequence
to.this
assertion object.AssertionError
- if the actual CharSequence
is not equal ignoring whitespace differences to the given
one.public SELF isNotEqualToIgnoringWhitespace(CharSequence expected)
CharSequence
is not equal to the given one, ignoring whitespace differences.
Example :
// assertions will pass
assertThat(" my\tfoo bar ").isNotEqualToIgnoringWhitespace("myfoo");
assertThat(" my\tfoo").isNotEqualToIgnoringWhitespace(" my bar");
// assertions will fail
assertThat("my foo bar").isNotEqualToIgnoringWhitespace("my foo bar");
assertThat(" my foo bar ").isNotEqualToIgnoringWhitespace("my foo bar");
assertThat(" my foo bar ").isNotEqualToIgnoringWhitespace("my foo bar");
assertThat(" my\tfoo bar ").isNotEqualToIgnoringWhitespace(" my foo bar");
assertThat("my foo bar").isNotEqualToIgnoringWhitespace(" my foo bar ");
expected
- the given CharSequence
to compare the actual CharSequence
to.this
assertion object.AssertionError
- if the actual CharSequence
is equal ignoring whitespace differences to the given
one.public SELF isEqualToNormalizingWhitespace(CharSequence expected)
CharSequence
is equal to the given one, after the whitespace
of both strings has been normalized.Example :
// assertions will pass
assertThat("Game of Thrones").isEqualToNormalizingWhitespace("Game of Thrones")
.isEqualToNormalizingWhitespace("Game of Thrones")
.isEqualToNormalizingWhitespace("Game of Thrones")
.isEqualToNormalizingWhitespace(" Game of Thrones ")
.isEqualToNormalizingWhitespace(" Game of Thrones ")
.isEqualToNormalizingWhitespace("Game of\tThrones")
.isEqualToNormalizingWhitespace("Game of Thrones");
// assertions will fail
assertThat("Game of Thrones").isEqualToNormalizingWhitespace("Game ofThrones");
assertThat("Game of Thrones").isEqualToNormalizingWhitespace("Gameo fThrones");
assertThat("Game of Thrones").isEqualToNormalizingWhitespace("Gameof Thrones");
expected
- the given CharSequence
to compare the actual CharSequence
to.this
assertion object.AssertionError
- if the actual CharSequence
is not equal to the given one
after whitespace has been normalized.public SELF isNotEqualToNormalizingWhitespace(CharSequence expected)
CharSequence
is not equal to the given one, after the whitespace
of both strings has been normalized.Example :
// assertions will pass
assertThat(" my\tfoo").isNotEqualToNormalizingWhitespace(" my bar");
assertThat(" my\tfoo bar ").isNotEqualToNormalizingWhitespace(" my foobar");
// assertions will fail
assertThat("my foo bar").isNotEqualToNormalizingWhitespace("my foo bar");
assertThat(" my foo bar ").isNotEqualToNormalizingWhitespace("my foo bar");
assertThat(" my foo bar ").isNotEqualToNormalizingWhitespace("my foo bar");
assertThat(" my\tfoo bar ").isNotEqualToNormalizingWhitespace(" my foo bar");
assertThat("my foo bar").isNotEqualToNormalizingWhitespace(" my foo bar ");
expected
- the given CharSequence
to compare the actual CharSequence
to.this
assertion object.AssertionError
- if the actual CharSequence
is equal to the given one
after whitespace has been normalized.public SELF isSubstringOf(CharSequence sequence)
CharSequence
is a substring of the given one (opposite assertion of contains(CharSequence cs)
.
Example :
// assertions will pass
assertThat("Lego").isSubstringOf("Legolas");
assertThat("Legolas").isSubstringOf("Legolas");
// assertion will fail
assertThat("Frodo").isSubstringOf("Frod");
sequence
- the sequence that is expected to contain actual.this
assertion object.AssertionError
- if the actual CharSequence
is not a substring of the given parameter.public SELF containsPattern(CharSequence regex)
CharSequence
contains the given regular expression.
Example :
// assertion will pass
assertThat("Frodo").containsPattern("Fr.d");
// assertion will fail
assertThat("Frodo").containsPattern("Frodod");
regex
- the regular expression to find in the actual CharSequence
.this
assertion object.NullPointerException
- if the given pattern is null
.PatternSyntaxException
- if the regular expression's syntax is invalid.AssertionError
- if the actual CharSequence
is null
.AssertionError
- if the given regular expression cannot be found in the actual CharSequence
.public SELF containsPattern(Pattern pattern)
CharSequence
contains the given regular expression pattern.
Example :
// assertion will pass
assertThat("Frodo").containsPattern(Pattern.compile("Fr.d"));
// assertion will fail
assertThat("Frodo").containsPattern(Pattern.compile("Frodod"));
pattern
- the regular expression to find in the actual CharSequence
.this
assertion object.NullPointerException
- if the given pattern is null
.AssertionError
- if the actual CharSequence
is null
.AssertionError
- if the given regular expression cannot be found in the actual CharSequence
.public SELF isEqualToNormalizingNewlines(CharSequence expected)
CharSequence
is equals to another
CharSequence
after normalizing new line characters
(i.e. '\r\n' == '\n').
This assertion will succeed:
String bookName = "Lord of the Rings\r\n";
assertThat(bookName).isEqualToNormalizingNewlines("Lord of the Rings\n");
Whereas this assertion will fail:
String singleLine = "\n";
assertThat(singleLine).isEqualToNormalizingNewlines("");
expected
- the given CharSequence
to compare the actual CharSequence
to.this
assertion object.AssertionError
- if the actual CharSequence
and the given CharSequence
are different
after new lines are normalized.public SELF isEqualToIgnoringNewLines(CharSequence expected)
CharSequence
is equal to the given one after both strings new lines (\n, \r\n) have been removed.
Example :
// assertions will pass
assertThat("Some textWith new lines").isEqualToIgnoringNewLines("Some text\nWith new lines")
.isEqualToIgnoringNewLines("Some text\r\nWith new lines")
.isEqualToIgnoringNewLines("Some text\n\nWith new lines");
assertThat("Some text\nWith new lines").isEqualToIgnoringNewLines("Some text\nWith new lines")
.isEqualToIgnoringNewLines("Some text\r\nWith new lines")
.isEqualToIgnoringNewLines("Some text\n\nWith new lines");
// assertions will fail
assertThat("Some text\nWith new lines").isEqualToIgnoringNewLines("Some text With new lines");
assertThat("Some text\r\nWith new lines").isEqualToIgnoringNewLines("Some text With new lines");
expected
- the given CharSequence
to compare the actual CharSequence
to.this
assertion object.AssertionError
- if the actual CharSequence
is not equal to the given one after new lines have been removed.Copyright © 2013–2018 AssertJ. All rights reserved.