Class AbstractCharSequenceAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>,ACTUAL extends CharSequence>
- 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.
- All Implemented Interfaces:
Assert<SELF,,ACTUAL> Descriptable<SELF>,EnumerableAssert<SELF,,Character> ExtensionPoints<SELF,ACTUAL>
- Direct Known Subclasses:
AbstractStringAssert,CharSequenceAssert
CharSequences.- Author:
- Yvonne Wang, David DIDIER, Alex Ruiz, Joel Costigliola, Mikhail Mazursky, Nicolas Francois, Daniel Weber
-
Field Summary
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself, objects, throwUnsupportedExceptionOnEquals -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractCharSequenceAssert(ACTUAL actual, Class<?> selfType) -
Method Summary
Modifier and TypeMethodDescriptioncontains(CharSequence... values) Verifies that the actualCharSequencecontains all the given values.contains(Iterable<? extends CharSequence> values) Verifies that the actualCharSequencecontains all theCharSequences of the given Iterable.containsAnyOf(CharSequence... values) Verifies that the actualCharSequencecontains any of the given values.containsIgnoringCase(CharSequence sequence) Verifies that the actualCharSequencecontains the given sequence, ignoring case considerations.containsIgnoringNewLines(CharSequence... values) Verifies that the actualCharSequencecontains all the given values ignoring new line differences.containsIgnoringWhitespaces(CharSequence... values) Verifies that the actualCharSequencecontains all the given values, ignoring whitespace differences.Verifies that the actualCharSequencecontains only digits.containsOnlyOnce(CharSequence sequence) Verifies that the actualCharSequencecontains the given sequence only once.Verifies that the actualCharSequenceconsists of one or more whitespace characters (according toCharacter.isWhitespace(char)).containsPattern(CharSequence regex) Verifies that the actualCharSequencecontains the given regular expression.containsPattern(Pattern pattern) Verifies that the actualCharSequencecontains the given regular expression pattern.containsPatternSatisfying(CharSequence regex, Consumer<Matcher> matchSatisfies) Verifies that the actualCharSequencecontains the given regular expression pattern, then accepts the givenConsumer<Matcher>for further verification on the matcher.containsPatternSatisfying(Pattern pattern, Consumer<Matcher> matchSatisfies) Verifies that the actualCharSequencecontains the given regular expression pattern, then accepts the givenConsumer<Matcher>for further verification on the matcher.containsSequence(CharSequence... values) Verifies that the actualCharSequencecontains the given sequence of values in the given order without any other values between them.containsSequence(Iterable<? extends CharSequence> values) Verifies that the actualCharSequencecontains all the values of the given Iterable in the Iterable iteration order without any other values between them.containsSubsequence(CharSequence... values) Verifies that the actualCharSequencecontains all the given values in the given order, possibly with other values between them.containsSubsequence(Iterable<? extends CharSequence> values) Verifies that the actualCharSequencecontains all the values of the given Iterable in the Iterable iteration order (possibly with other values between them).Verifies that the actualCharSequencecontains one or more whitespace characters (according toCharacter.isWhitespace(char)).doesNotContain(CharSequence... values) Verifies that the actualCharSequencedoes not contain any of the given values.doesNotContain(Iterable<? extends CharSequence> values) Verifies that the actualCharSequencedoes not contain any of the given Iterable.Verifies that the actualCharSequenceis eithernull, empty or does not contain any whitespace characters (according toCharacter.isWhitespace(char)).doesNotContainIgnoringCase(CharSequence... values) Verifies that the actualCharSequencedoes not contain any of the given values, ignoring case considerations.Verifies that the actualCharSequenceis either:nullempty contains at least one non-whitespace character (according toCharacter.isWhitespace(char)).doesNotContainPattern(CharSequence pattern) Verifies that the actualCharSequencedoes not contain the given regular expression.doesNotContainPattern(Pattern pattern) Verifies that the actualCharSequencedoes not contain the given regular expression.doesNotEndWith(CharSequence suffix) Verifies that the actualCharSequencedoes not end with the given suffix.Verifies that the actualCharSequencedoes not end with the given suffix, ignoring case considerations.doesNotMatch(CharSequence regex) Verifies that the actualCharSequencedoes not match the given regular expression.doesNotMatch(Pattern pattern) Verifies that the actualCharSequencedoes not match the given regular expression pattern.doesNotStartWith(CharSequence prefix) Verifies that the actualCharSequencedoes not start with the given prefix.Verifies that the actualCharSequencedoes not start with the given prefix, ignoring case considerations.endsWith(CharSequence suffix) Verifies that the actualCharSequenceends with the given suffix, ignoring case considerations.endsWithIgnoringCase(CharSequence suffix) Verifies that the actualCharSequenceends with the given suffix, ignoring case considerations.hasLineCount(int expectedLineCount) Verifies that the actualCharSequencehas the expected line count.hasSameSizeAs(CharSequence other) Verifies that the actualCharSequencehas a length that's the same as the length of the givenCharSequence.hasSameSizeAs(Iterable<?> other) Verifies that the actualCharSequencehas a length that's the same as the number of elements in the given Iterable.hasSameSizeAs(Object other) Verifies that the actualCharSequencehas a length that's the same as the number of elements in the given array.hasSize(int expected) Verifies that the actualCharSequencehas the expected length using thelength()method.hasSizeBetween(int lowerBoundary, int higherBoundary) Verifies that the actualCharSequencehas length between the given boundaries (inclusive) using thelength()method.hasSizeGreaterThan(int expected) Verifies that the actualCharSequencehas a length greater than the given value using thelength()method.hasSizeGreaterThanOrEqualTo(int expected) Verifies that the actualCharSequencehas a length greater than or equal to the given value using thelength()method.hasSizeLessThan(int expected) Verifies that the actualCharSequencehas has a length less than the given value using thelength()method.hasSizeLessThanOrEqualTo(int expected) Verifies that the actualCharSequencehas a length less than or equal to the given value using thelength()method.Use hexadecimal object representation instead of standard representation in error messages.Use unicode character representation instead of standard representation in error messages.Verifies that the actualCharSequenceis alphabetic by checking it against the\p{Alpha}+regex pattern POSIX character classes (US-ASCII only).Verifies that the actualCharSequenceis alphanumeric by checking it against the\p{Alnum}+regex pattern POSIX character classes (US-ASCII only).isASCII()Verifies that the actualCharSequenceis ASCII by checking it against the\p{ASCII}+regex pattern POSIX character classes (US-ASCII only).isBlank()Verifies that the actualCharSequenceis blank, i.e.voidisEmpty()Verifies that the actualCharSequenceis empty, i.e., it has a length of 0 and is notnull.isEqualToIgnoringCase(CharSequence expected) Verifies that the actualCharSequenceis equal to the given one, ignoring case considerations.isEqualToIgnoringNewLines(CharSequence expected) Verifies that the actualCharSequenceis equal to the given one after both strings new lines (\n, \r\n) have been removed.isEqualToIgnoringWhitespace(CharSequence expected) Verifies that the actualCharSequenceis equal to the given one, ignoring whitespace differencesisEqualToNormalizingNewlines(CharSequence expected) Verifies that the actualCharSequenceis equals to anotherCharSequenceafter normalizing new line characters (i.e.Verifies that the actualCharSequenceis equal to the given one, after the punctuation of both strings have been normalized.isEqualToNormalizingUnicode(CharSequence expected) Verifies that the actualCharSequenceis equal to the given one after they have been normalized according to theNormalizer.Form.NFCform, which is a canonical decomposition followed by canonical composition.isEqualToNormalizingWhitespace(CharSequence expected) Verifies that the actualCharSequenceis 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 comparisonVerifies that the actualCharSequenceis hexadecimal by checking it against the\p{XDigit}+regex pattern POSIX character classes (US-ASCII only).Deprecated.Verifies that the actualCharSequenceis a lowercaseCharSequenceby comparing it to a lowercaseactualbuilt withString.toLowerCase().Verifies that the actualCharSequenceis a mixed caseCharSequence, i.e., neither uppercase nor lowercase.Verifies that the actualCharSequenceis: notnullnot empty contains at least one non-whitespace character (according toCharacter.isWhitespace(char))Verifies that the actualCharSequenceis not empty, i.e., is notnulland has a length of 1 or more.isNotEqualToIgnoringCase(CharSequence expected) Verifies that the actualCharSequenceis not equal to the given one, ignoring case considerations.isNotEqualToIgnoringWhitespace(CharSequence expected) Verifies that the actualCharSequenceis not equal to the given one, ignoring whitespace differences.Verifies that the actualCharSequenceis 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 comparisonDeprecated.UseisNotBlank()instead.voidVerifies that the actualCharSequenceis empty, i.e., it has a length of 0, or isnull.Verifies that the actualCharSequenceis printable by checking it against the\p{Print}+regex pattern POSIX character classes (US-ASCII only).isSubstringOf(CharSequence sequence) Verifies that the actualCharSequenceis a substring of the given one (opposite assertion ofcontains(CharSequence cs).Verifies that the actualCharSequenceis an uppercaseCharSequenceby comparing it to an uppercaseactualbuilt withString.toUpperCase().Verifies that the actualCharSequenceis visible by checking it against the\p{Graph}+regex pattern POSIX character classes (US-ASCII only).isXmlEqualTo(CharSequence 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.
The recommended approach is XML Unit which is able to deal with these limitations and provides many more features like XPath support and schema validation.isXmlEqualToContentOf(File xmlFile) Deprecated.matches(CharSequence regex) Verifies that the actualCharSequencematches the given regular expression.Verifies that the actualCharSequencematches the given regular expression pattern.matchesSatisfying(CharSequence regex, Consumer<Matcher> matchSatisfies) Verifies that the actualCharSequencematches the given regular expression pattern, then accepts the givenConsumer<Matcher>to do further verification on the matcher.matchesSatisfying(Pattern pattern, Consumer<Matcher> matchSatisfies) Verifies that the actualCharSequencematches the given regular expression pattern, then accepts the givenConsumer<Matcher>to do further verification on the matcher.startsWith(CharSequence prefix) Verifies that the actualCharSequencestarts with the given prefix.startsWithIgnoringCase(CharSequence prefix) Verifies that the actualCharSequencestarts with the given prefix, ignoring case considerations.usingComparator(Comparator<? super ACTUAL> customComparator) Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.usingComparator(Comparator<? super ACTUAL> customComparator, String customComparatorDescription) Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.Revert to standard comparison for the incoming assertion checks.final SELFDeprecated.Custom element Comparator is not supported for CharSequence comparison.final SELFusingElementComparator(Comparator<? super Character> customComparator) Deprecated.Custom element Comparator is not supported for CharSequence comparison.Methods inherited from class org.assertj.core.api.AbstractAssert
areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, inBinary, is, isElementOfCustomAssert, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, overridingErrorMessage, satisfies, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOfForProxy, satisfiesForProxy, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparison, withFailMessage, withFailMessage, withRepresentation, withThreadDumpOnErrorMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.assertj.core.api.Descriptable
as, as, as, describedAs
-
Constructor Details
-
AbstractCharSequenceAssert
-
-
Method Details
-
isNullOrEmpty
public void isNullOrEmpty()Verifies that the actualCharSequenceis empty, i.e., it has a length of 0, or isnull.If you do not want to accept a
nullvalue, useisEmpty()instead.Both of these assertions will succeed:
Whereas these assertions will fail:String emptyString = "" assertThat(emptyString).isNullOrEmpty(); String nullString = null; assertThat(nullString).isNullOrEmpty();assertThat("a").isNullOrEmpty(); assertThat(" ").isNullOrEmpty();- Specified by:
isNullOrEmptyin interfaceEnumerableAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>, ACTUAL extends CharSequence> - Throws:
AssertionError- if the actualCharSequencehas a non-zero length.
-
isEmpty
public void isEmpty()Verifies that the actualCharSequenceis empty, i.e., it has a length of 0 and is notnull.If you want to accept a
nullvalue as well as a 0 length, useisNullOrEmpty()instead.This assertion will succeed:
Whereas these assertions will fail:String emptyString = "" assertThat(emptyString).isEmpty();String nullString = null; assertThat(nullString).isEmpty(); assertThat("a").isEmpty(); assertThat(" ").isEmpty();- Specified by:
isEmptyin interfaceEnumerableAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>, ACTUAL extends CharSequence> - Throws:
AssertionError- if the actualCharSequencehas a non-zero length or is null.
-
isNotEmpty
Verifies that the actualCharSequenceis not empty, i.e., is notnulland has a length of 1 or more.This assertion will succeed:
Whereas these assertions will fail:String bookName = "A Game of Thrones" assertThat(bookName).isNotEmpty();String emptyString = "" assertThat(emptyString).isNotEmpty(); String nullString = null; assertThat(nullString).isNotEmpty();- Specified by:
isNotEmptyin interfaceEnumerableAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>, ACTUAL extends CharSequence> - Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis empty (has a length of 0).
-
isBlank
Verifies that the actualCharSequenceis blank, i.e. isnull, empty or consists of one or more whitespace characters (according toCharacter.isWhitespace(char)).The definition of this method has changed, the old behaviour is now under
containsOnlyWhitespaces().These assertions succeed:
Whereas these assertions fail:assertThat(" ").isBlank(); assertThat("").isBlank(); assertThat(" ").isBlank(); String nullString = null; assertThat(nullString).isBlank();assertThat("a").isBlank(); assertThat(" b").isBlank(); assertThat(" c ").isBlank();- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis not blank.- Since:
- 2.6.0 / 3.6.0
-
isNotBlank
Verifies that the actualCharSequenceis:- not
null - not empty
- contains at least one non-whitespace character (according to
Character.isWhitespace(char))
The definition of this method has changed, the old behaviour is now under
doesNotContainOnlyWhitespaces().These assertions succeed:
Whereas these assertions fail:assertThat("a").isNotBlank(); assertThat(" b").isNotBlank(); assertThat(" c ").isNotBlank();assertThat(" ").isNotBlank(); assertThat("").isNotBlank(); assertThat(" ").isNotBlank(); String nullString = null; assertThat(nullString).isNotBlank();- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis blank.- Since:
- 2.6.0 / 3.6.0
- not
-
containsWhitespaces
Verifies that the actualCharSequencecontains one or more whitespace characters (according toCharacter.isWhitespace(char)).These assertions will succeed:
Whereas these assertions will fail:assertThat(" ").containsWhitespaces(); assertThat("a b").containsWhitespaces(); assertThat(" c ").containsWhitespaces();assertThat("").containsWhitespaces(); assertThat("a").containsWhitespaces(); String nullString = null; assertThat(nullString).containsWhitespaces();- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequencedoes not contain any whitespace characters.- Since:
- 3.11.0
-
containsOnlyWhitespaces
Verifies that the actualCharSequenceconsists of one or more whitespace characters (according toCharacter.isWhitespace(char)).These assertions will succeed:
Whereas these assertions will fail:assertThat(" ").containsOnlyWhitespaces(); assertThat(" ").containsOnlyWhitespaces();assertThat("a").containsOnlyWhitespaces(); assertThat("").containsOnlyWhitespaces(); assertThat(" b").containsOnlyWhitespaces(); assertThat(" c ").containsOnlyWhitespaces(); String nullString = null; assertThat(nullString).containsOnlyWhitespaces();- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis not blank.- Since:
- 2.9.0 / 3.9.0
-
doesNotContainAnyWhitespaces
Verifies that the actualCharSequenceis eithernull, empty or does not contain any whitespace characters (according toCharacter.isWhitespace(char)).These assertions will succeed:
Whereas these assertions will fail:assertThat("a").doesNotContainAnyWhitespaces(); assertThat("").doesNotContainAnyWhitespaces(); assertThat("ab").doesNotContainAnyWhitespaces(); String nullString = null; assertThat(nullString).doesNotContainAnyWhitespaces();assertThat(" ").doesNotContainAnyWhitespaces(); assertThat(" a").doesNotContainAnyWhitespaces();- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequencecontains one or more whitespace characters.- Since:
- 3.11.0
-
doesNotContainOnlyWhitespaces
Verifies that the actualCharSequenceis either:null- empty
- contains at least one non-whitespace character (according to
Character.isWhitespace(char)).
The main difference with
isNotBlank()is that it accepts null or emptyCharSequence.These assertions will succeed:
Whereas these assertions will fail:assertThat("a").doesNotContainOnlyWhitespaces(); assertThat("").doesNotContainOnlyWhitespaces(); assertThat(" b").doesNotContainOnlyWhitespaces(); assertThat(" c ").doesNotContainOnlyWhitespaces(); String nullString = null; assertThat(nullString).doesNotContainOnlyWhitespaces();assertThat(" ").doesNotContainOnlyWhitespaces(); assertThat(" ").doesNotContainOnlyWhitespaces();- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis blank.- Since:
- 2.9.0 / 3.9.0
-
isJavaBlank
Deprecated.UseisBlank()instead.Verifies that the actualCharSequenceis blank, i.e. consists of one or more whitespace characters (according toCharacter.isWhitespace(char)).These assertions will succeed:
Whereas these assertions will fail:assertThat(" ").isJavaBlank(); assertThat(" ").isJavaBlank();assertThat("a").isJavaBlank(); assertThat(" b").isJavaBlank(); assertThat("").isJavaBlank(); String nullString = null; assertThat(nullString).isJavaBlank();- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis not blank.- Since:
- 2.6.0 / 3.6.0
-
isNotJavaBlank
Deprecated.UseisNotBlank()instead.Verifies that the actualCharSequenceis not blank, i.e. either isnull, empty or contains at least one non-whitespace character (according toCharacter.isWhitespace(char)).These assertions will succeed:
Whereas these assertions will fail:assertThat("a").isNotJavaBlank(); assertThat(" b").isNotJavaBlank(); assertThat(" c ").isNotJavaBlank(); assertThat("").isNotJavaBlank(); String nullString = null; assertThat(nullString).isNotJavaBlank();assertThat(" ").isNotJavaBlank(); assertThat(" ").isNotJavaBlank();- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis blank.- Since:
- 2.6.0 / 3.6.0
-
hasSize
Verifies that the actualCharSequencehas the expected length using thelength()method.This assertion will succeed:
Whereas this assertion will fail:String bookName = "A Game of Thrones" assertThat(bookName).hasSize(17);String bookName = "A Clash of Kings" assertThat(bookName).hasSize(4);- Specified by:
hasSizein interfaceEnumerableAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>, ACTUAL extends CharSequence> - Parameters:
expected- the expected length of the actualCharSequence.- Returns:
thisassertion object.- Throws:
AssertionError- if the actual length is not equal to the expected length.
-
hasSizeLessThan
Verifies that the actualCharSequencehas has a length less than the given value using thelength()method.This assertion will succeed:
Whereas this assertion will fail:assertThat("abc").hasSizeLessThan(4);assertThat("abc").hasSizeLessThan(3);- Specified by:
hasSizeLessThanin interfaceEnumerableAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>, ACTUAL extends CharSequence> - Parameters:
expected- the expected maximum length of the actualCharSequence.- Returns:
thisassertion object.- Throws:
AssertionError- if the actual length is equal or greater than the expected length.- Since:
- 3.12.0
-
hasSizeLessThanOrEqualTo
Verifies that the actualCharSequencehas a length less than or equal to the given value using thelength()method.This assertion will succeed:
Whereas this assertion will fail:assertThat("abc").hasSizeLessThanOrEqualTo(3);assertThat("abc").hasSizeLessThanOrEqualTo(2);- Specified by:
hasSizeLessThanOrEqualToin interfaceEnumerableAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>, ACTUAL extends CharSequence> - Parameters:
expected- the expected maximum length of the actualCharSequence.- Returns:
thisassertion object.- Throws:
AssertionError- if the actual length is greater than the expected length.- Since:
- 3.12.0
-
hasSizeGreaterThan
Verifies that the actualCharSequencehas a length greater than the given value using thelength()method.This assertion will succeed:
Whereas this assertion will fail:assertThat("abcs").hasSizeGreaterThan(2);assertThat("abc").hasSizeGreaterThan(3);- Specified by:
hasSizeGreaterThanin interfaceEnumerableAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>, ACTUAL extends CharSequence> - Parameters:
expected- the expected minimum length of the actualCharSequence.- Returns:
thisassertion object.- Throws:
AssertionError- if the actual length is equal or less than the expected length.- Since:
- 3.12.0
-
hasSizeGreaterThanOrEqualTo
Verifies that the actualCharSequencehas a length greater than or equal to the given value using thelength()method.This assertion will succeed:
Whereas this assertion will fail:assertThat("abc").hasSizeGreaterThanOrEqualTo(3);assertThat("abc").hasSizeGreaterThanOrEqualTo(3);- Specified by:
hasSizeGreaterThanOrEqualToin interfaceEnumerableAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>, ACTUAL extends CharSequence> - Parameters:
expected- the expected minimum length of the actualCharSequence.- Returns:
thisassertion object.- Throws:
AssertionError- if the actual length is less than the expected length.- Since:
- 3.12.0
-
hasSizeBetween
Verifies that the actualCharSequencehas length between the given boundaries (inclusive) using thelength()method.This assertion will succeed:
Whereas this assertion will fail:String bookName = "A Game of Thrones" assertThat(bookName).hasSizeBetween(5, 25); assertThat(bookName).hasSizeBetween(16, 17);String bookName = "A Clash of Kings" assertThat(bookName).hasSizeBetween(2, 5);- Specified by:
hasSizeBetweenin interfaceEnumerableAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>, ACTUAL extends CharSequence> - Parameters:
lowerBoundary- the lower boundary compared to which actual length should be greater than or equal to.higherBoundary- the higher boundary compared to which actual length should be less than or equal to.- Returns:
thisassertion object.- Throws:
AssertionError- if the actual length is not between the boundaries.- Since:
- 3.12.0
-
hasLineCount
Verifies that the actualCharSequencehas 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 (seeLineNumberReader).This assertion will succeed:
Whereas this assertion will fail:String multiLine = "First line\n" + "Last line"; assertThat(multiLine).hasLineCount(2);String bookName = "A Clash of Kings"; assertThat(bookName).hasLineCount(3);- Parameters:
expectedLineCount- the expected line count of the actualCharSequence.- Returns:
thisassertion object.- Throws:
AssertionError- if the actual line count is not equal to the expected one.
-
hasSameSizeAs
Verifies that the actualCharSequencehas a length that's the same as the length of the givenCharSequence.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");- Parameters:
other- the givenCharSequenceto be used for size comparison.- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequencehas a length that's different from the length of the givenCharSequence.NullPointerException- if the givenCharSequenceisnull.
-
hasSameSizeAs
Verifies that the actualCharSequencehas 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' });- Specified by:
hasSameSizeAsin interfaceEnumerableAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>, ACTUAL extends CharSequence> - Parameters:
other- the given array to be used for size comparison.- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequencehas a length that's different from the number of elements in the array.NullPointerException- if the given array isnull.
-
hasSameSizeAs
Verifies that the actualCharSequencehas 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));- Specified by:
hasSameSizeAsin interfaceEnumerableAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>, ACTUAL extends CharSequence> - Parameters:
other- the givenIterableto be used for size comparison.- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequencehas a length that's different from the number of elements in theIterable.NullPointerException- if the givenIterableisnull.
-
isEqualToIgnoringCase
Verifies that the actualCharSequenceis 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");- Parameters:
expected- the givenCharSequenceto compare the actualCharSequenceto.- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis not equal to the given one.
-
isNotEqualToIgnoringCase
Verifies that the actualCharSequenceis 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);- Parameters:
expected- the givenCharSequenceto compare the actualCharSequenceto.- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis not equal to the given one.
-
containsOnlyDigits
Verifies that the actualCharSequencecontains only digits. It fails if it contains non-digit characters or is empty.This assertion succeeds:
Whereas these assertions fail:assertThat("10").containsOnlyDigits();assertThat("10$").containsOnlyDigits(); assertThat("").containsOnlyDigits();- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequencecontains non-digit characters or isnull.
-
containsOnlyOnce
Verifies that the actualCharSequencecontains the given sequence only once.Example:
// assertion will pass assertThat("Frodo").containsOnlyOnce("do"); // assertions will fail assertThat("Frodo").containsOnlyOnce("o"); assertThat("Frodo").containsOnlyOnce("y");- Parameters:
sequence- the sequence to search for.- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceeither does not contain the given one at all, or contains it more than once.
-
contains
Verifies that the actualCharSequencecontains all the given values.You can use one or several
CharSequences as in this example:assertThat("Gandalf the grey").contains("alf"); assertThat("Gandalf the grey").contains("alf", "grey");- Parameters:
values- the values to look for.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given list of values isnull.IllegalArgumentException- if the list of given values is empty.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencedoes not contain all the given values.
-
containsAnyOf
Verifies that the actualCharSequencecontains any of the given values.Example:
// assertion succeeds assertThat("Gandalf the grey").containsAnyOf("grey", "black"); // assertion fails assertThat("Gandalf the grey").containsAnyOf("white", "black");- Parameters:
values- the values to look for.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given list of values isnull.IllegalArgumentException- if the list of given values is empty.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencedoes not contain any of the given values.- Since:
- 3.21.0
-
contains
Verifies that the actualCharSequencecontains all theCharSequences of the given Iterable.Examples:
assertThat("Gandalf the grey").contains(Arrays.asList("alf")); assertThat("Gandalf the grey").contains(Arrays.asList("alf", "grey"));- Parameters:
values- the values to look for.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given list of values isnull.IllegalArgumentException- if the list of given values is empty.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencedoes not contain all the given values.
-
containsSequence
Verifies that the actualCharSequencecontains 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
containsSubsequenceand 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'");- Parameters:
values- the sequence of charSequence to look for, in order.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given sequence of charSequence isnull.IllegalArgumentException- if the given sequence of charSequence is empty.AssertionError- if the givenCharSequenceisnull.AssertionError- if the givenCharSequencedoes not contain the given sequence of values in the given order without any other values between them.
-
containsSequence
Verifies that the actualCharSequencecontains 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
containsSubsequenceand 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"));- Parameters:
values- the sequence of charSequence to look for, in order.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given sequence of charSequence isnull.IllegalArgumentException- if the given sequence of charSequence is empty.AssertionError- if the givenCharSequenceisnull.AssertionError- if the givenCharSequencedoes not contain the given sequence of values in the given order without any other charvalues between them.
-
containsSubsequence
Verifies that the actualCharSequencecontains 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", "}");- Parameters:
values- the Strings to look for, in order.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given values isnull.IllegalArgumentException- if the given values is empty.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencedoes not contain all the given values in the given order.
-
containsSubsequence
Verifies that the actualCharSequencecontains 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", "}"));- Parameters:
values- the Strings to look for, in order.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given values isnull.IllegalArgumentException- if the given values is empty.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencedoes not contain all the given values in the given order.
-
containsIgnoringCase
Verifies that the actualCharSequencecontains 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");- Parameters:
sequence- the sequence to search for.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given sequence isnull.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencedoes not contain the given one.
-
containsIgnoringWhitespaces
Verifies that the actualCharSequencecontains all the given values, ignoring whitespace differences.You can use one or several
CharSequences as in this example:// assertions succeed: assertThat("Gandalf the grey").containsIgnoringWhitespaces("alf") .containsIgnoringWhitespaces("alf", "grey") .containsIgnoringWhitespaces("thegrey") .containsIgnoringWhitespaces("thegr ey") .containsIgnoringWhitespaces("t h e g r\t\r\n ey"); // assertion fails: assertThat("Gandalf the grey").containsIgnoringWhitespaces("alF")- Parameters:
values- the values to look for.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given list of values isnull.IllegalArgumentException- if the list of given values is empty.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencedoes not contain all the given values.
-
containsIgnoringNewLines
Verifies that the actualCharSequencecontains all the given values ignoring new line differences.You can use one or several
CharSequences as in this example:// assertions succeed: assertThat("Gandalf\nthe\ngrey").containsIgnoringNewLines("alf") .containsIgnoringNewLines("alf", "grey") .containsIgnoringNewLines("thegrey") .containsIgnoringNewLines("thegr\ney") .containsIgnoringNewLines("t\nh\ne\ng\nr\ney"); // assertions fail: assertThat("Gandalf\nthe\ngrey").containsIgnoringNewLines("alF") assertThat("Gandalf\nthe\ngrey").containsIgnoringNewLines("t\nh\ne\ng\nr\t\r\ney")- Parameters:
values- the values to look for.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given list of values isnull.IllegalArgumentException- if the list of given values is empty.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencedoes not contain all the given values.
-
doesNotContain
Verifies that the actualCharSequencedoes 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");- Parameters:
values- the CharSequences to search for.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given list of values isnull.IllegalArgumentException- if the list of given values is empty.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencecontains any of the given values.
-
doesNotContain
Verifies that the actualCharSequencedoes 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"));- Parameters:
values- the CharSequences to search for.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given list of values isnull.IllegalArgumentException- if the list of given values is empty.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencecontains any of the given values.
-
doesNotContainIgnoringCase
Verifies that the actualCharSequencedoes not contain any of the given values, ignoring case considerations.Example:
// assertions will pass assertThat("Frodo").doesNotContainIgnoringCase("pippin") .doesNotContainIgnoringCase("Merry", "sam"); // assertions will fail assertThat("Frodo").doesNotContainIgnoringCase("Fro", "Gimli", "Legolas"); assertThat("Frodo").doesNotContainIgnoringCase("fro");- Parameters:
values- the CharSequences to search for.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given list of values isnull.NullPointerException- if any one of the given values isnull.IllegalArgumentException- if the list of given values is empty.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencecontains any one of the given values, ignoring case considerations.- Since:
- 3.17.0
-
doesNotContainPattern
Verifies that the actualCharSequencedoes not contain the given regular expression.Example:
// assertion will pass assertThat("Frodo").doesNotContainPattern("Fr.ud"); // assertion will fail assertThat("Freud").doesNotContainPattern("Fr.ud");- Parameters:
pattern- the regular expression to find in the actualCharSequence.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given pattern isnull.PatternSyntaxException- if the regular expression's syntax is invalid.AssertionError- if the actualCharSequenceisnull.AssertionError- if the given regular expression can be found in the actualCharSequence.- Since:
- 2.7.0 / 3.7.0
-
doesNotContainPattern
Verifies that the actualCharSequencedoes 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"));- Parameters:
pattern- the regular expression to find in the actualCharSequence.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given pattern isnull.AssertionError- if the actualCharSequenceisnull.AssertionError- if the given regular expression can be found in the actualCharSequence.- Since:
- 2.7.0 / 3.7.0
-
startsWith
Verifies that the actualCharSequencestarts 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");- Parameters:
prefix- the given prefix.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given prefix isnull.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencedoes not start with the given prefix.
-
startsWithIgnoringCase
Verifies that the actualCharSequencestarts with the given prefix, ignoring case considerations.Example:
// assertions will pass assertThat("Gandalf the grey").startsWithIgnoringCase("Gandalf"); assertThat("Gandalf the grey").startsWithIgnoringCase("gandalf"); // assertion will fail assertThat("Gandalf the grey").startsWithIgnoringCase("grey");- Parameters:
prefix- the given prefix.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given prefix isnull.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencedoes not start with the given prefix, ignoring case.- Since:
- 3.23.0
-
doesNotStartWith
Verifies that the actualCharSequencedoes 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("");- Parameters:
prefix- the given prefix.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given prefix isnull.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencestarts with the given prefix.
-
doesNotStartWithIgnoringCase
Verifies that the actualCharSequencedoes not start with the given prefix, ignoring case considerations.Example:
// assertions will pass assertThat("Gandalf the grey").doesNotStartWithIgnoringCase("fro"); assertThat("Gandalf the grey").doesNotStartWithIgnoringCase("grey"); // assertions will fail assertThat("Gandalf the grey").doesNotStartWithIgnoringCase("Gandalf"); assertThat("Gandalf the grey").doesNotStartWithIgnoringCase("gandalf");- Parameters:
prefix- the given prefix.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given prefix isnull.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencestarts with the given prefix, ignoring case.- Since:
- 3.23.0
-
endsWith
Verifies that the actualCharSequenceends with the given suffix, ignoring case considerations.Example:
// assertion will pass assertThat("Frodo").endsWith("do"); // assertion will fail assertThat("Frodo").endsWith("Fro");- Parameters:
suffix- the given suffix.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given suffix isnull.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencedoes not end with the given suffix.
-
endsWithIgnoringCase
Verifies that the actualCharSequenceends with the given suffix, ignoring case considerations.Example:
// assertions will pass assertThat("Frodo").endsWithIgnoringCase("do"); assertThat("Frodo").endsWithIgnoringCase("DO"); // assertion will fail assertThat("Frodo").endsWithIgnoringCase("Fro");- Parameters:
suffix- the given suffix.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given suffix isnull.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencedoes not end with the given suffix, ignoring case.- Since:
- 3.23.0
-
doesNotEndWith
Verifies that the actualCharSequencedoes not end with the given suffix.Example:
// assertion will pass assertThat("Frodo").doesNotEndWith("Fro"); // assertions will fail assertThat("Frodo").doesNotEndWith("do"); assertThat("Frodo").doesNotEndWith("");- Parameters:
suffix- the given suffix.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given suffix isnull.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequenceends with the given suffix.
-
doesNotEndWithIgnoringCase
Verifies that the actualCharSequencedoes not end with the given suffix, ignoring case considerations.Example:
// assertion will pass assertThat("Frodo").doesNotEndWithIgnoringCase("Fro"); // assertions will fail assertThat("Frodo").doesNotEndWithIgnoringCase("do"); assertThat("Frodo").doesNotEndWithIgnoringCase("DO");- Parameters:
suffix- the given suffix.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given suffix isnull.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequenceends with the given suffix, ignoring case.- Since:
- 3.23.0
-
matches
Verifies that the actualCharSequencematches the given regular expression.Example:
// assertion will pass assertThat("Frodo").matches("..o.o"); // assertion will fail assertThat("Frodo").matches(".*d");- Parameters:
regex- the regular expression to which the actualCharSequenceis to be matched.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given pattern isnull.PatternSyntaxException- if the regular expression's syntax is invalid.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencedoes not match the given regular expression.
-
matchesSatisfying
Verifies that the actualCharSequencematches the given regular expression pattern, then accepts the givenConsumer<Matcher>to do further verification on the matcher.Example:
// assertion succeeds: assertThat("Frodo").matchesSatisfying("..(o.o)", matcher -> assertThat(matcher.group(1)).isEqualTo("odo"));- Parameters:
regex- the regular expression to which the actualCharSequenceis to be matched.matchSatisfies- a consumer of the found match to do further verification- Returns:
thisassertion object.- Throws:
NullPointerException- if the given pattern isnull.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencedoes not match the given regular expression.
-
doesNotMatch
Verifies that the actualCharSequencedoes not match the given regular expression.Example:
// assertion will pass assertThat("Frodo").doesNotMatch(".*d"); // assertion will fail assertThat("Frodo").doesNotMatch("..o.o");- Parameters:
regex- the regular expression to which the actualCharSequenceis to be matched.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given pattern isnull.PatternSyntaxException- if the regular expression's syntax is invalid.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencematches the given regular expression.
-
matches
Verifies that the actualCharSequencematches 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"));- Parameters:
pattern- the regular expression to which the actualCharSequenceis to be matched.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given pattern isnull.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencedoes not match the given regular expression.
-
matchesSatisfying
Verifies that the actualCharSequencematches the given regular expression pattern, then accepts the givenConsumer<Matcher>to do further verification on the matcher.Example:
Pattern pattern = Pattern.compile("..(o.o)"); // assertion succeeds: assertThat("Frodo").matchesSatisfying(pattern, matcher -> assertThat(matcher.group(1)).isEqualTo("odo"));- Parameters:
pattern- the regular expression to which the actualCharSequenceis to be matched.matchSatisfies- a consumer of the found match to do further verification- Returns:
thisassertion object.- Throws:
NullPointerException- if the given pattern isnull.AssertionError- if the actualCharSequenceisnull.AssertionError- if the actualCharSequencedoes not match the given regular expression.
-
doesNotMatch
Verifies that the actualCharSequencedoes 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"));- Parameters:
pattern- the regular expression to which the actualCharSequenceis to be matched.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given pattern isnull.AssertionError- if the actualCharSequencedoes not match the given regular expression.
-
isXmlEqualTo
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.
The recommended approach is XML Unit which is able to deal with these limitations and provides many more features like XPath support and schema validation.Original javadoc:
Verifies that the actual
CharSequenceis equal to the given XMLCharSequenceafter 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 formatted, 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"));- Parameters:
expectedXml- the XMLCharSequenceto which the actualCharSequenceis to be compared to.- Returns:
thisassertion object to chain other assertions.- Throws:
NullPointerException- if the givenCharSequenceisnull.AssertionError- if the actualCharSequenceisnullor is not the same XML as the given XMLCharSequence.- See Also:
-
isXmlEqualToContentOf
Deprecated.Verifies that the actualCharSequenceis equal to the content of the given file.This is an handy shortcut that calls :
Example: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"));- Parameters:
xmlFile- the file to read the expected XML String to compare with actualCharSequence- Returns:
thisassertion object to chain other assertions.- Throws:
NullPointerException- if the givenFileisnull.AssertionError- if the actualCharSequenceisnullor is not the same XML as the content of givenFile.
-
usingElementComparator
@Deprecated public final SELF usingElementComparator(Comparator<? super Character> customComparator) Deprecated.Custom element Comparator is not supported for CharSequence comparison.Do not use this method.- Specified by:
usingElementComparatorin interfaceEnumerableAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>, ACTUAL extends CharSequence> - Parameters:
customComparator- the comparator to use for incoming assertion checks.- Returns:
thisassertion object.- Throws:
UnsupportedOperationException- if this method is called.
-
usingDefaultElementComparator
Deprecated.Custom element Comparator is not supported for CharSequence comparison.Do not use this method.- Specified by:
usingDefaultElementComparatorin interfaceEnumerableAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>, ACTUAL extends CharSequence> - Returns:
thisassertion object.- Throws:
UnsupportedOperationException- if this method is called.
-
usingComparator
Description copied from class:AbstractAssertUse the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.The custom comparator is bound to assertion instance, meaning that if a new assertion instance is created, the default comparison strategy will be used.
Examples :
// frodo and sam are instances of Character with Hobbit race (obviously :). // raceComparator implements Comparator<Character> assertThat(frodo).usingComparator(raceComparator).isEqualTo(sam);- Specified by:
usingComparatorin interfaceAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>, ACTUAL extends CharSequence> - Overrides:
usingComparatorin classAbstractAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>, ACTUAL extends CharSequence> - Parameters:
customComparator- the comparator to use for the incoming assertion checks.- Returns:
thisassertion object.
-
usingComparator
public SELF usingComparator(Comparator<? super ACTUAL> customComparator, String customComparatorDescription) Description copied from class:AbstractAssertUse the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.The custom comparator is bound to assertion instance, meaning that if a new assertion instance is created, the default comparison strategy will be used.
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);- Specified by:
usingComparatorin interfaceAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>, ACTUAL extends CharSequence> - Overrides:
usingComparatorin classAbstractAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>, ACTUAL extends CharSequence> - Parameters:
customComparator- the comparator to use for the incoming assertion checks.customComparatorDescription- comparator description to be used in assertion error messages- Returns:
thisassertion object.
-
usingDefaultComparator
Description copied from class:AbstractAssertRevert to standard comparison for the incoming assertion checks.This method should be used to disable a custom comparison strategy set by calling
usingComparator.- Specified by:
usingDefaultComparatorin interfaceAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>, ACTUAL extends CharSequence> - Overrides:
usingDefaultComparatorin classAbstractAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>, ACTUAL extends CharSequence> - Returns:
thisassertion object.
-
inHexadecimal
Description copied from class:AbstractAssertUse hexadecimal object representation instead of standard representation in error messages.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:
With Hexadecimal message:assertThat("µµµ").contains("μμμ"); java.lang.AssertionError: Expecting: <"µµµ"> to contain: <"μμμ">assertThat("µµµ").inHexadecimal().contains("μμμ"); java.lang.AssertionError: Expecting: <"['00B5', '00B5', '00B5']"> to contain: <"['03BC', '03BC', '03BC']">- Overrides:
inHexadecimalin classAbstractAssert<SELF extends AbstractCharSequenceAssert<SELF,ACTUAL>, ACTUAL extends CharSequence> - Returns:
thisassertion object.
-
inUnicode
Use unicode character representation instead of standard representation in error messages.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:
With Hexadecimal message:assertThat("µµµ").contains("μμμ"); java.lang.AssertionError: Expecting: <"µµµ"> to contain: <"μμμ">assertThat("µµµ").inUnicode().contains("μμμ"); java.lang.AssertionError: Expecting: <µµµ> to contain: <μμμ>- Returns:
thisassertion object.
-
isEqualToIgnoringWhitespace
Verifies that the actualCharSequenceis equal to the given one, ignoring whitespace differencesExamples :
// 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).- Parameters:
expected- the givenCharSequenceto compare the actualCharSequenceto.- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis not equal ignoring whitespace differences to the given one.
-
isNotEqualToIgnoringWhitespace
Verifies that the actualCharSequenceis 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 ");- Parameters:
expected- the givenCharSequenceto compare the actualCharSequenceto.- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis equal ignoring whitespace differences to the given one.
-
isEqualToNormalizingWhitespace
Verifies that the actualCharSequenceis 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
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");- Parameters:
expected- the givenCharSequenceto compare the actualCharSequenceto.- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis not equal to the given one after whitespace has been normalized.- Since:
- 2.8.0 / 3.8.0
-
isNotEqualToNormalizingWhitespace
Verifies that the actualCharSequenceis 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
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 ");- Parameters:
expected- the givenCharSequenceto compare the actualCharSequenceto.- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis equal to the given one after whitespace has been normalized.- Since:
- 2.8.0 / 3.8.0
-
isEqualToNormalizingPunctuationAndWhitespace
Verifies that the actualCharSequenceis equal to the given one, after the punctuation of both strings have been normalized.To be exact, the following rules are applied:
- All punctuation of actual and expected strings are ignored and whitespaces are normalized
- Punctuation is any of the following character
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
Example:
// assertions will pass assertThat("Game'of'Thrones").isEqualToNormalizingPunctuationAndWhitespace("GameofThrones") assertThat("Game of Throne's").isEqualToNormalizingPunctuationAndWhitespace("Game of Thrones") assertThat(":Game of Thrones:").isEqualToNormalizingPunctuationAndWhitespace("Game of Thrones") assertThat(":Game-of-Thrones:").isEqualToNormalizingPunctuationAndWhitespace("Game of Thrones") assertThat("Game of Thrones?").isEqualToNormalizingPunctuationAndWhitespace("Game of Thrones") assertThat("Game of Thrones!!!").isEqualToNormalizingPunctuationAndWhitespace("Game of Thrones") assertThat("Game of {{(!)}} Thrones!!!").isEqualToNormalizingPunctuationAndWhitespace("Game of Thrones") assertThat("{(Game)-(of)-(Thrones)!!!}").isEqualToNormalizingPunctuationAndWhitespace("GameofThrones"); // assertions will fail assertThat("Game-of-Thrones").isEqualToNormalizingPunctuationAndWhitespace("Game of Thrones"); assertThat("{Game:of:Thrones}").isEqualToNormalizingPunctuationAndWhitespace("Game of Thrones"); assertThat("{(Game)-(of)-(Thrones)!!!}").isEqualToNormalizingPunctuationAndWhitespace("Game of Thrones");- Parameters:
expected- the givenCharSequenceto compare the actualCharSequenceto.- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis not equal to the given one after punctuation have been normalized.- Since:
- 3.16.0
-
isSubstringOf
Verifies that the actualCharSequenceis a substring of the given one (opposite assertion ofcontains(CharSequence cs).Example:
// assertions will pass assertThat("Lego").isSubstringOf("Legolas"); assertThat("Legolas").isSubstringOf("Legolas"); // assertion will fail assertThat("Frodo").isSubstringOf("Frod");- Parameters:
sequence- the sequence that is expected to contain actual.- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis not a substring of the given parameter.
-
containsPattern
Verifies that the actualCharSequencecontains the given regular expression.Example:
// assertion will pass assertThat("Frodo").containsPattern("Fr.d"); // assertion will fail assertThat("Frodo").containsPattern("Frodod");- Parameters:
regex- the regular expression to find in the actualCharSequence.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given pattern isnull.PatternSyntaxException- if the regular expression's syntax is invalid.AssertionError- if the actualCharSequenceisnull.AssertionError- if the given regular expression cannot be found in the actualCharSequence.
-
containsPatternSatisfying
Verifies that the actualCharSequencecontains the given regular expression pattern, then accepts the givenConsumer<Matcher>for further verification on the matcher.Example :
// assertion succeeds: assertThat("Frodo").containsPatternSatisfying(".o(.o)", matcher -> assertThat(matcher.group(1)).isEqualTo("do"));- Parameters:
regex- the regular expression to find in the actualCharSequence.matchSatisfies- a consumer for further verifying the Matcher.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given pattern isnull.PatternSyntaxException- if the regular expression's syntax is invalid.AssertionError- if the actualCharSequenceisnull.AssertionError- if the given regular expression cannot be found in the actualCharSequence.
-
containsPattern
Verifies that the actualCharSequencecontains 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"));- Parameters:
pattern- the regular expression to find in the actualCharSequence.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given pattern isnull.AssertionError- if the actualCharSequenceisnull.AssertionError- if the given regular expression cannot be found in the actualCharSequence.
-
containsPatternSatisfying
Verifies that the actualCharSequencecontains the given regular expression pattern, then accepts the givenConsumer<Matcher>for further verification on the matcher.Example :
Pattern pattern = Pattern.compile(".o(.o)"); // assertion succeeds: assertThat("Frodo").containsPatternSatisfying(pattern, matcher -> assertThat(matcher.group(1)).isEqualTo("do"));- Parameters:
pattern- the regular expression to find in the actualCharSequence.matchSatisfies- a consumer for further verifying the Matcher.- Returns:
thisassertion object.- Throws:
NullPointerException- if the given pattern isnull.AssertionError- if the actualCharSequenceisnull.AssertionError- if the given regular expression cannot be found in the actualCharSequence.
-
isEqualToNormalizingNewlines
Verifies that the actualCharSequenceis equals to anotherCharSequenceafter normalizing new line characters (i.e. '\r\n' == '\n').This assertion will succeed:
Whereas this assertion will fail:String bookName = "Lord of the Rings\r\n"; assertThat(bookName).isEqualToNormalizingNewlines("Lord of the Rings\n");String singleLine = "\n"; assertThat(singleLine).isEqualToNormalizingNewlines("");- Parameters:
expected- the givenCharSequenceto compare the actualCharSequenceto.- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceand the givenCharSequenceare different after new lines are normalized.- Since:
- 2.7.0 / 3.7.0
-
isEqualToIgnoringNewLines
Verifies that the actualCharSequenceis 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");- Parameters:
expected- the givenCharSequenceto compare the actualCharSequenceto.- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis not equal to the given one after new lines have been removed.
-
isLowerCase
Verifies that the actualCharSequenceis a lowercaseCharSequenceby comparing it to a lowercaseactualbuilt withString.toLowerCase().Example:
// assertions will pass assertThat("lego").isLowerCase(); assertThat("").isLowerCase(); assertThat(" ").isLowerCase(); assertThat(".").isLowerCase(); assertThat("7").isLowerCase(); assertThat("a.7").isLowerCase(); // assertions will fail assertThat("Lego").isLowerCase(); assertThat("LEGO").isLowerCase();- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis not lowercase.- See Also:
-
isMixedCase
Verifies that the actualCharSequenceis a mixed caseCharSequence, i.e., neither uppercase nor lowercase.If actual is empty or contains only case-independent characters, the assertion will pass.
Example:
// assertions will pass assertThat("Capitalized").isMixedCase(); assertThat("camelCase").isMixedCase(); assertThat("rAndOMcAse1234").isMixedCase(); assertThat("1@3$567").isMixedCase(); assertThat("").isMixedCase(); // assertions will fail assertThat("I AM GROOT!").isMixedCase(); assertThat("please be quiet").isMixedCase();- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis not mixed case.- Since:
- 3.21.0
- See Also:
-
isUpperCase
Verifies that the actualCharSequenceis an uppercaseCharSequenceby comparing it to an uppercaseactualbuilt withString.toUpperCase().Example:
// assertions will pass assertThat("LEGO").isUpperCase(); assertThat("").isUpperCase(); assertThat(" ").isUpperCase(); assertThat(".").isUpperCase(); assertThat("7").isUpperCase(); assertThat("A.7").isUpperCase(); // assertions will fail assertThat("Lego").isUpperCase(); assertThat("lego").isUpperCase();- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis not uppercase.- See Also:
-
isEqualToNormalizingUnicode
Verifies that the actualCharSequenceis equal to the given one after they have been normalized according to theNormalizer.Form.NFCform, which is a canonical decomposition followed by canonical composition.Example:
// assertions succeed: // Ä = \u00C4 - Ä = \u0041\u0308 assertThat("Ä").isEqualToNormalizingUnicode("Ä"); assertThat("\u00C4").isEqualToNormalizingUnicode("\u0041\u0308"); // Amélie = u0041\u006d\u00e9\u006c\u0069\u0065 - Amélie = \u0041\u006d\u0065\u0301\u006c\u0069\u0065 assertThat("Amélie").isEqualToNormalizingUnicode("Amélie"); // assertions fail: assertThat("ñ").isEqualToNormalizingUnicode("n"); assertThat("Ä").isEqualToNormalizingUnicode("b");- Parameters:
expected- the givenCharSequenceto compare the actualCharSequenceto.- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis not equal to the given one after both strings have been normalized to according to theNormalizer.Form.NFCform .NullPointerException- if the actualCharSequenceis not null and the given is.- Since:
- 3.19.0
-
isAlphabetic
Verifies that the actualCharSequenceis alphabetic by checking it against the\p{Alpha}+regex pattern POSIX character classes (US-ASCII only).Example:
// assertions will pass assertThat("lego").isAlphabetic(); assertThat("a").isAlphabetic(); assertThat("Lego").isAlphabetic(); // assertions will fail assertThat("1").isAlphabetic(); assertThat(" ").isAlphabetic(); assertThat("").isAlphabetic(); assertThat("L3go").isAlphabetic();- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis not alphabetic.- See Also:
-
isAlphanumeric
Verifies that the actualCharSequenceis alphanumeric by checking it against the\p{Alnum}+regex pattern POSIX character classes (US-ASCII only).Example:
// assertions will pass assertThat("lego").isAlphanumeric(); assertThat("a1").isAlphanumeric(); assertThat("L3go").isAlphanumeric(); // assertions will fail assertThat("!").isAlphanumeric(); assertThat("").isAlphanumeric(); assertThat(" ").isAlphanumeric(); assertThat("L3go!").isAlphanumeric();- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis not alphanumeric.- See Also:
-
isASCII
Verifies that the actualCharSequenceis ASCII by checking it against the\p{ASCII}+regex pattern POSIX character classes (US-ASCII only).Example:
// assertions will pass assertThat("lego").isASCII(); assertThat("a1").isASCII(); assertThat("L3go").isASCII(); // assertions will fail assertThat("").isASCII(); assertThat("♪").isASCII(); assertThat("⌃").isASCII(); assertThat("L3go123⌃00abc").isASCII();- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis not ASCII.- See Also:
-
isHexadecimal
Verifies that the actualCharSequenceis hexadecimal by checking it against the\p{XDigit}+regex pattern POSIX character classes (US-ASCII only).Example:
// assertions will pass assertThat("A").isHexadecimal(); assertThat("2").isHexadecimal(); // assertions will fail assertThat("!").isHexadecimal(); assertThat("").isHexadecimal(); assertThat(" ").isHexadecimal(); assertThat("Z").isHexadecimal(); assertThat("L3go!").isHexadecimal();- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis not hexadecimal.- See Also:
-
isPrintable
Verifies that the actualCharSequenceis printable by checking it against the\p{Print}+regex pattern POSIX character classes (US-ASCII only).Example:
// assertions will pass assertThat("2").isPrintable(); assertThat("a").isPrintable(); assertThat("~").isPrintable(); assertThat("").isPrintable(); // assertions will fail assertThat("\t").isPrintable(); assertThat("§").isPrintable(); assertThat("©").isPrintable(); assertThat("\n").isPrintable();- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis not printable.- See Also:
-
isVisible
Verifies that the actualCharSequenceis visible by checking it against the\p{Graph}+regex pattern POSIX character classes (US-ASCII only).Example:
// assertions will pass assertThat("2").isVisible(); assertThat("a").isVisible(); assertThat(".").isVisible(); // assertions will fail assertThat("\t").isVisible(); assertThat("\n").isVisible(); assertThat("").isVisible(); assertThat(" ").isVisible();- Returns:
thisassertion object.- Throws:
AssertionError- if the actualCharSequenceis not visible.- See Also:
-
isBlank()instead.