Top Description Fields Constructors Methods
org.assertj.core.api

public abstract Class AbstractCharSequenceAssert<SELF extends AbstractCharSequenceAssert<SELF, ACTUAL>, ACTUAL extends CharSequence>

extends AbstractAssert<SELF extends AbstractCharSequenceAssert<SELF, ACTUAL>, ACTUAL extends CharSequence>
implements EnumerableAssert<SELF extends AbstractCharSequenceAssert<SELF, ACTUAL>, Character>
Class Inheritance
All Implemented Interfaces
org.assertj.core.api.EnumerableAssert
Known Direct Subclasses
org.assertj.core.api.CharSequenceAssert, org.assertj.core.api.AbstractStringAssert
Type Parameters
<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.
Static Imports
java.lang.Character.isWhitespace, java.util.Arrays.stream, java.util.stream.Collectors.toCollection, org.assertj.core.api.Assertions.contentOf, org.assertj.core.error.ShouldBeASCII.shouldBeASCII, .ShouldBeAlphabetic.shouldBeAlphabetic, .ShouldBeAlphanumeric.shouldBeAlphanumeric, .ShouldBeBlank.shouldBeBlank, .ShouldBeHexadecimal.shouldBeHexadecimal, .ShouldBePrintable.shouldBePrintable, .ShouldBeVisible.shouldBeVisible, .ShouldContainCharSequence.shouldContainIgnoringWhitespaces, .ShouldContainOneOrMoreWhitespaces.shouldContainOneOrMoreWhitespaces, .ShouldContainOnlyWhitespaces.shouldContainOnlyWhitespaces, .ShouldNotBeBlank.shouldNotBeBlank, .ShouldNotContainAnyWhitespaces.shouldNotContainAnyWhitespaces, .ShouldNotContainOnlyWhitespaces.shouldNotContainOnlyWhitespaces, .ShouldNotEndWithWhitespaces.shouldNotEndWithWhitespaces, .ShouldNotStartWithWhitespaces.shouldNotStartWithWhitespaces, org.assertj.core.internal.Strings.doCommonCheckForCharSequence, .Strings.removeAllWhitespaces, org.assertj.core.util.IterableUtil.toArray

Base class for all implementations of assertions for CharSequences.
Authors
Yvonne Wang, David DIDIER, Alex Ruiz, Joel Costigliola, Mikhail Mazursky, Nicolas Francois, Daniel Weber

Field Summary

Modifier and TypeField and Description
pack-priv Strings
Inherited from org.assertj.core.api.AbstractAssert:
actualassertionErrorCreatorconditionscustomRepresentationinfomyselfobjectsprintAssertionsDescriptionthrowUnsupportedExceptionOnEquals

Constructor Summary

AccessConstructor and Description
protected
AbstractCharSequenceAssert(ACTUAL actual, Class<?> selfType)

Method Summary

Modifier and TypeMethod and Description
private void
private void
private void
private void
private void
private void
private void
private void
private void
public SELF

Returns:

this assertion object.
contains
(CharSequence...
the values to look for.
values
)

Verifies that the actual CharSequence contains all the given values.

public SELF

Returns:

this assertion object.
contains
(Iterable<? extends CharSequence>
the values to look for.
values
)

Verifies that the actual CharSequence contains all the CharSequences of the given Iterable.

public SELF

Returns:

this assertion object.
containsAnyOf
(CharSequence...
the values to look for.
values
)

Verifies that the actual CharSequence contains any of the given values.

public SELF

Returns:

this assertion object.
containsIgnoringCase
(CharSequence
the sequence to search for.
sequence
)

Verifies that the actual CharSequence contains the given sequence, ignoring case considerations.

public SELF

Returns:

this assertion object.
containsIgnoringNewLines
(final CharSequence...
the values to look for.
values
)

Verifies that the actual CharSequence contains all the given values ignoring new line differences.

public SELF

Returns:

this assertion object.
containsIgnoringWhitespaces
(CharSequence...
the values to look for.
values
)

Verifies that the actual CharSequence contains all the given values, ignoring whitespace differences.

private static boolean
public SELF

Returns:

this assertion object.
containsOnlyDigits
()

Verifies that the actual CharSequence contains only digits.

public SELF

Returns:

this assertion object.
containsOnlyOnce
(CharSequence
the sequence to search for.
sequence
)

Verifies that the actual CharSequence contains the given sequence only once.

public SELF

Returns:

this assertion object.
containsOnlyWhitespaces
()

Verifies that the actual CharSequence consists of one or more whitespace characters (according to Character#isWhitespace(char)).

private static boolean
public SELF

Returns:

this assertion object.
containsPattern
(CharSequence
the regular expression to find in the actual CharSequence.
regex
)

Verifies that the actual CharSequence contains the given regular expression.

public SELF

Returns:

this assertion object.
containsPattern
(Pattern
the regular expression to find in the actual CharSequence.
pattern
)

Verifies that the actual CharSequence contains the given regular expression pattern.

public SELF

Returns:

this assertion object.
containsPatternSatisfying
(CharSequence
the regular expression to find in the actual CharSequence.
regex
,
Consumer<Matcher>
a consumer for further verifying the Matcher.
matchSatisfies
)

Verifies that the actual CharSequence contains the given regular expression pattern, then accepts the given Consumer<Matcher> for further verification on the matcher.

public SELF

Returns:

this assertion object.
containsPatternSatisfying
(Pattern
the regular expression to find in the actual CharSequence.
pattern
,
Consumer<Matcher>
a consumer for further verifying the Matcher.
matchSatisfies
)

Verifies that the actual CharSequence contains the given regular expression pattern, then accepts the given Consumer<Matcher> for further verification on the matcher.

public SELF

Returns:

this assertion object.
containsSequence
(CharSequence...
the sequence of charSequence to look for, in order.
values
)

Verifies that the actual CharSequence contains the given sequence of values in the given order without any other values between them.

public SELF

Returns:

this assertion object.
containsSequence
(Iterable<? extends CharSequence>
the sequence of charSequence to look for, in order.
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.

public SELF

Returns:

this assertion object.
containsSubsequence
(CharSequence...
the Strings to look for, in order.
values
)

Verifies that the actual CharSequence contains all the given values in the given order, possibly with other values between them.

public SELF

Returns:

this assertion object.
containsSubsequence
(Iterable<? extends CharSequence>
the Strings to look for, in order.
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).

public SELF

Returns:

this assertion object.
containsWhitespaces
()

Verifies that the actual CharSequence contains one or more whitespace characters (according to Character#isWhitespace(char)).

private static boolean
public SELF

Returns:

this assertion object.
doesNotContain
(CharSequence...
the CharSequences to search for.
values
)

Verifies that the actual CharSequence does not contain any of the given values.

public SELF

Returns:

this assertion object.
doesNotContain
(Iterable<? extends CharSequence>
the CharSequences to search for.
values
)

Verifies that the actual CharSequence does not contain any of the given Iterable.

public SELF

Returns:

this assertion object.
doesNotContainAnyWhitespaces
()

Verifies that the actual CharSequence is either null, empty or does not contain any whitespace characters (according to Character#isWhitespace(char)).

public SELF

Returns:

this assertion object.
doesNotContainIgnoringCase
(CharSequence...
the CharSequences to search for.
values
)

Verifies that the actual CharSequence does not contain any of the given values, ignoring case considerations.

public SELF

Returns:

this assertion object.
doesNotContainOnlyWhitespaces
()

Verifies that the actual CharSequence is either:

public SELF

Returns:

this assertion object.
doesNotContainPattern
(CharSequence
the regular expression to find in the actual CharSequence.
pattern
)

Verifies that the actual CharSequence does not contain the given regular expression.

public SELF

Returns:

this assertion object.
doesNotContainPattern
(Pattern
the regular expression to find in the actual CharSequence.
pattern
)

Verifies that the actual CharSequence does not contain the given regular expression.

public SELF

Returns:

this assertion object.
doesNotEndWith
(CharSequence
the given suffix.
suffix
)

Verifies that the actual CharSequence does not end with the given suffix.

public SELF

Returns:

this assertion object.
doesNotEndWithIgnoringCase
(CharSequence
the given suffix.
suffix
)

Verifies that the actual CharSequence does not end with the given suffix, ignoring case considerations.

public SELF

Returns:

this assertion object.
doesNotEndWithWhitespaces
()

Verifies that the actual CharSequence does not end with whitespaces (as per Character#isWhitespace(int) definition), it also checks it is not null as a prerequisite.

public SELF

Returns:

this assertion object.
doesNotMatch
(CharSequence
the regular expression to which the actual CharSequence is to be matched.
regex
)

Verifies that the actual CharSequence does not match the given regular expression.

public SELF

Returns:

this assertion object.
doesNotMatch
(Pattern
the regular expression to which the actual CharSequence is to be matched.
pattern
)

Verifies that the actual CharSequence does not match the given regular expression pattern.

public SELF

Returns:

this assertion object.
doesNotStartWith
(CharSequence
the given prefix.
prefix
)

Verifies that the actual CharSequence does not start with the given prefix.

public SELF

Returns:

this assertion object.
doesNotStartWithIgnoringCase
(CharSequence
the given prefix.
prefix
)

Verifies that the actual CharSequence does not start with the given prefix, ignoring case considerations.

public SELF

Returns:

this assertion object.
doesNotStartWithWhitespaces
()

Verifies that the actual CharSequence does not start with whitespaces (as per Character#isWhitespace(int) definition), it also checks it is not null as a prerequisite.

public SELF

Returns:

this assertion object.
endsWith
(CharSequence
the given suffix.
suffix
)

Verifies that the actual CharSequence ends with the given suffix, ignoring case considerations.

public SELF

Returns:

this assertion object.
endsWithIgnoringCase
(CharSequence
the given suffix.
suffix
)

Verifies that the actual CharSequence ends with the given suffix, ignoring case considerations.

public SELF

Returns:

this assertion object.
hasLineCount
(int
the expected line count of the actual CharSequence.
expectedLineCount
)

Verifies that the actual CharSequence has the expected line count.

public SELF

Returns:

this assertion object.
hasSameSizeAs
(CharSequence
the given CharSequence to be used for size comparison.
other
)

Verifies that the actual CharSequence has a length that's the same as the length of the given CharSequence.

public SELF

Returns:

this assertion object.
hasSameSizeAs
(Object
the given array to be used for size comparison.
other
)

Implements org.assertj.core.api.EnumerableAssert.hasSameSizeAs.

Verifies that the actual CharSequence has a length that's the same as the number of elements in the given array.
public SELF

Returns:

this assertion object.
hasSameSizeAs
(Iterable<?>
the given Iterable to be used for size comparison.
other
)

Implements org.assertj.core.api.EnumerableAssert.hasSameSizeAs.

Verifies that the actual CharSequence has a length that's the same as the number of elements in the given Iterable.
public SELF

Returns:

this assertion object.
hasSize
(int
the expected length of the actual CharSequence.
expected
)

Implements org.assertj.core.api.EnumerableAssert.hasSize.

Verifies that the actual CharSequence has the expected length using the length() method.
public SELF

Returns:

this assertion object.
hasSizeBetween
(int
the lower boundary compared to which actual length should be greater than or equal to.
lowerBoundary
,
int
the higher boundary compared to which actual length should be less than or equal to.
higherBoundary
)

Implements org.assertj.core.api.EnumerableAssert.hasSizeBetween.

Verifies that the actual CharSequence has length between the given boundaries (inclusive) using the length() method.
public SELF

Returns:

this assertion object.
hasSizeGreaterThan
(int
the expected minimum length of the actual CharSequence.
expected
)

Implements org.assertj.core.api.EnumerableAssert.hasSizeGreaterThan.

Verifies that the actual CharSequence has a length greater than the given value using the length() method.
public SELF

Returns:

this assertion object.
hasSizeGreaterThanOrEqualTo
(int
the expected minimum length of the actual CharSequence.
expected
)

Implements org.assertj.core.api.EnumerableAssert.hasSizeGreaterThanOrEqualTo.

Verifies that the actual CharSequence has a length greater than or equal to the given value using the length() method.
public SELF

Returns:

this assertion object.
hasSizeLessThan
(int
the expected maximum length of the actual CharSequence.
expected
)

Implements org.assertj.core.api.EnumerableAssert.hasSizeLessThan.

Verifies that the actual CharSequence has has a length less than the given value using the length() method.
public SELF

Returns:

this assertion object.
hasSizeLessThanOrEqualTo
(int
the expected maximum length of the actual CharSequence.
expected
)

Implements org.assertj.core.api.EnumerableAssert.hasSizeLessThanOrEqualTo.

Verifies that the actual CharSequence has a length less than or equal to the given value using the length() method.
public SELF
inHexadecimal()

Overrides org.assertj.core.api.AbstractAssert.inHexadecimal.

Use hexadecimal object representation instead of standard representation in error messages.
private SELF
private SELF
public SELF

Returns:

this assertion object.
inUnicode
()

Use unicode character representation instead of standard representation in error messages.

public SELF

Returns:

this assertion object.
isAlphabetic
()

Verifies that the actual CharSequence is alphabetic by checking it against the \p{Alpha}+ regex pattern POSIX character classes (US-ASCII only).

public SELF

Returns:

this assertion object.
isAlphanumeric
()

Verifies that the actual CharSequence is alphanumeric by checking it against the \p{Alnum}+ regex pattern POSIX character classes (US-ASCII only).

public SELF

Returns:

this assertion object.
isASCII
()

Verifies that the actual CharSequence is ASCII by checking it against the \p{ASCII}+ regex pattern POSIX character classes (US-ASCII only).

public SELF

Returns:

this assertion object.
isBlank
()

Verifies that the actual CharSequence is blank, i.e. is null, empty or consists of one or more whitespace characters (according to Character#isWhitespace(char)).

private static boolean
public void
isEmpty()

Implements org.assertj.core.api.EnumerableAssert.isEmpty.

Verifies that the actual CharSequence is empty, i.e., it has a length of 0 and is not null.
public SELF

Returns:

this assertion object.
isEqualToIgnoringCase
(CharSequence
the given CharSequence to compare the actual CharSequence to.
expected
)

Verifies that the actual CharSequence is equal to the given one, ignoring case considerations.

public SELF

Returns:

this assertion object.
isEqualToIgnoringNewLines
(CharSequence
the given CharSequence to compare the actual CharSequence to.
expected
)

Verifies that the actual CharSequence is equal to the given one after both strings new lines (\n, \r\n) have been removed.

public SELF

Returns:

this assertion object.
isEqualToIgnoringWhitespace
(CharSequence
the given CharSequence to compare the actual CharSequence to.
expected
)

Verifies that the actual 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");
public SELF

Returns:

this assertion object.
isEqualToNormalizingNewlines
(CharSequence
the given CharSequence to compare the actual CharSequence to.
expected
)

Verifies that the actual CharSequence is equals to another CharSequence after normalizing new line characters (i.e. '\r\n' == '\n').

public SELF

Returns:

this assertion object.
isEqualToNormalizingPunctuationAndWhitespace
(CharSequence
the given CharSequence to compare the actual CharSequence to.
expected
)

Verifies that the actual CharSequence is equal to the given one, after the punctuation of both strings has been normalized.

public SELF

Returns:

this assertion object.
isEqualToNormalizingUnicode
(CharSequence
the given CharSequence to compare the actual CharSequence to.
expected
)

Verifies that the actual CharSequence is equal to the given one after they have been normalized according to the Normalizer.Form#NFC form, which is a canonical decomposition followed by canonical composition.

public SELF

Returns:

this assertion object.
isEqualToNormalizingWhitespace
(CharSequence
the given CharSequence to compare the actual CharSequence to.
expected
)

Verifies that the actual CharSequence is equal to the given one, after the whitespace of both strings has been normalized.

public SELF

Returns:

this assertion object.
isHexadecimal
()

Verifies that the actual CharSequence is hexadecimal by checking it against the \p{XDigit}+ regex pattern POSIX character classes (US-ASCII only).

public SELF

Returns:

this assertion object.
isJavaBlank
()

Deprecated Use isBlank() instead.
Verifies that the actual CharSequence is blank, i.e. consists of one or more whitespace characters (according to Character#isWhitespace(char)).
public SELF

Returns:

this assertion object.
isLowerCase
()

Verifies that the actual CharSequence is a lowercase CharSequence by comparing it to a lowercase actual built with String#toLowerCase().

public SELF

Returns:

this assertion object.
isMixedCase
()

Verifies that the actual CharSequence is a mixed case CharSequence, i.e., neither uppercase nor lowercase.

public SELF

Returns:

this assertion object.
isNotBlank
()

Verifies that the actual CharSequence is:

public SELF

Returns:

this assertion object.
isNotEmpty
()

Implements org.assertj.core.api.EnumerableAssert.isNotEmpty.

Verifies that the actual CharSequence is not empty, i.e., is not null and has a length of 1 or more.
public SELF

Returns:

this assertion object.
isNotEqualToIgnoringCase
(CharSequence
the given CharSequence to compare the actual CharSequence to.
expected
)

Verifies that the actual CharSequence is not equal to the given one, ignoring case considerations.

public SELF

Returns:

this assertion object.
isNotEqualToIgnoringWhitespace
(CharSequence
the given CharSequence to compare the actual CharSequence to.
expected
)

Verifies that the actual CharSequence is not equal to the given one, ignoring whitespace differences.

public SELF

Returns:

this assertion object.
isNotEqualToNormalizingWhitespace
(CharSequence
the given CharSequence to compare the actual CharSequence to.
expected
)

Verifies that the actual CharSequence is not equal to the given one, after the whitespace of both strings has been normalized.

public SELF

Returns:

this assertion object.
isNotJavaBlank
()

Deprecated Use isNotBlank() instead.
Verifies that the actual CharSequence is not blank, i.e. either is null, empty or contains at least one non-whitespace character (according to Character#isWhitespace(char)).
public void
isNullOrEmpty()

Implements org.assertj.core.api.EnumerableAssert.isNullOrEmpty.

Verifies that the actual CharSequence is empty, i.e., it has a length of 0, or is null.
private static boolean
public SELF

Returns:

this assertion object.
isPrintable
()

Verifies that the actual CharSequence is printable by checking it against the \p{Print}+ regex pattern POSIX character classes (US-ASCII only).

public SELF

Returns:

this assertion object.
isSubstringOf
(CharSequence
the sequence that is expected to contain actual.
sequence
)

Verifies that the actual CharSequence is a substring of the given one (opposite assertion of contains(CharSequence cs).

public SELF

Returns:

this assertion object.
isUpperCase
()

Verifies that the actual CharSequence is an uppercase CharSequence by comparing it to an uppercase actual built with String#toUpperCase().

public SELF

Returns:

this assertion object.
isVisible
()

Verifies that the actual CharSequence is visible by checking it against the \p{Graph}+ regex pattern POSIX character classes (US-ASCII only).

public SELF

Returns:

this assertion object to chain other assertions.
isXmlEqualTo
(CharSequence
the XML CharSequence to which the actual CharSequence is to be compared to.
expectedXml
)

Deprecated This assertion has some limitations, for example it does not handle tab vs space and would fail if elements are the same but in a different order.
public SELF

Returns:

this assertion object to chain other assertions.
isXmlEqualToContentOf
(File
the file to read the expected XML String to compare with actual CharSequence
xmlFile
)

Deprecated
Verifies that the actual CharSequence is equal to the content of the given file.
public SELF

Returns:

this assertion object.
matches
(CharSequence
the regular expression to which the actual CharSequence is to be matched.
regex
)

Verifies that the actual CharSequence matches the given regular expression.

public SELF

Returns:

this assertion object.
matches
(Pattern
the regular expression to which the actual CharSequence is to be matched.
pattern
)

Verifies that the actual CharSequence matches the given regular expression pattern.

public SELF

Returns:

this assertion object.
matchesSatisfying
(CharSequence
the regular expression to which the actual CharSequence is to be matched.
regex
,
Consumer<Matcher>
a consumer of the found match to do further verification
matchSatisfies
)

Verifies that the actual CharSequence matches the given regular expression pattern, then accepts the given Consumer<Matcher> to do further verification on the matcher.

public SELF

Returns:

this assertion object.
matchesSatisfying
(Pattern
the regular expression to which the actual CharSequence is to be matched.
pattern
,
Consumer<Matcher>
a consumer of the found match to do further verification
matchSatisfies
)

Verifies that the actual CharSequence matches the given regular expression pattern, then accepts the given Consumer<Matcher> to do further verification on the matcher.

public SELF

Returns:

this assertion object.
startsWith
(CharSequence
the given prefix.
prefix
)

Verifies that the actual CharSequence starts with the given prefix.

public SELF

Returns:

this assertion object.
startsWithIgnoringCase
(CharSequence
the given prefix.
prefix
)

Verifies that the actual CharSequence starts with the given prefix, ignoring case considerations.

private static boolean
public SELF
usingComparator(Comparator<? super ACTUAL>
the comparator to use for the incoming assertion checks.
customComparator
)

Overrides org.assertj.core.api.AbstractAssert.usingComparator.

Implements org.assertj.core.api.Assert.usingComparator.

Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
public SELF
usingComparator(Comparator<? super ACTUAL>
the comparator to use for the incoming assertion checks.
customComparator
,
String
comparator description to be used in assertion error messages
customComparatorDescription
)

Overrides org.assertj.core.api.AbstractAssert.usingComparator.

Implements org.assertj.core.api.Assert.usingComparator.

Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
public SELF
usingDefaultComparator()

Overrides org.assertj.core.api.AbstractAssert.usingDefaultComparator.

Implements org.assertj.core.api.Assert.usingDefaultComparator.

Revert to standard comparison for the incoming assertion checks.
public final SELF
usingDefaultElementComparator()

Implements org.assertj.core.api.EnumerableAssert.usingDefaultElementComparator.

Deprecated Custom element Comparator is not supported for CharSequence comparison.
Do not use this method.
public final SELF
usingElementComparator(Comparator<? super Character>
the comparator to use for incoming assertion checks.
customComparator
)

Implements org.assertj.core.api.EnumerableAssert.usingElementComparator.

Deprecated Custom element Comparator is not supported for CharSequence comparison.
Do not use this method.
Inherited from org.assertj.core.api.AbstractAssert:
areEqualasInstanceOfasListassertionErrorasStringdescribedAsdescriptionTextdoesNotHavedoesNotHaveSameClassAsdoesNotHaveSameHashCodeAsdoesNotHaveToStringdoesNotHaveToStringequalsextractingextractingfailurefailureWithActualExpectedfailWithActualExpectedAndMessagefailWithMessagegetWritableAssertionInfohashashCodehasSameClassAshasSameHashCodeAshasToStringhasToStringinBinaryisisElementOfCustomAssertisEqualToisExactlyInstanceOfisInisInisInstanceOfisInstanceOfAnyisInstanceOfSatisfyingisNotisNotEqualToisNotExactlyInstanceOfisNotInisNotInisNotInstanceOfisNotInstanceOfAnyisNotNullisNotOfAnyClassInisNotSameAsisNullisOfAnyClassInisSameAsmatchesmatchesnewListAssertInstanceoverridingErrorMessageoverridingErrorMessagesatisfiessatisfiessatisfiessatisfiesAnyOfsatisfiesAnyOfsatisfiesAnyOfForProxysatisfiesForProxysetCustomRepresentationsetDescriptionConsumersetPrintAssertionsDescriptionthrowAssertionErrorusingRecursiveAssertionusingRecursiveAssertionusingRecursiveComparisonusingRecursiveComparisonwithAssertionStatewithFailMessagewithFailMessagewithRepresentationwithThreadDumpOnError