Top Fields Constructors Methods
org.assertj.core.api

public Class AbstractStringAssert<SELF extends AbstractStringAssert<SELF>>

extends AbstractCharSequenceAssert<SELF extends AbstractStringAssert<SELF>, String>
Class Inheritance
Known Direct Subclasses
org.assertj.core.api.StringAssert
Static Imports
java.lang.String.format, java.util.Objects.requireNonNull, org.assertj.core.error.ShouldBeNumeric.shouldBeNumeric, .ShouldBeNumeric.NumericType.BYTE, .ShouldBeNumeric.NumericType.DOUBLE, .ShouldBeNumeric.NumericType.FLOAT, .ShouldBeNumeric.NumericType.INTEGER, .ShouldBeNumeric.NumericType.LONG, .ShouldBeNumeric.NumericType.SHORT

Field Summary

Modifier and TypeField and Description
pack-priv Comparables
pack-priv Failures
Inherited from org.assertj.core.api.AbstractCharSequenceAssert:
strings

Constructor Summary

AccessConstructor and Description
protected
AbstractStringAssert(String actual, Class<?> selfType)

Method Summary

Modifier and TypeMethod and Description
public AbstractByteArrayAssert<?>

Returns:

a new ByteArrayAssert instance whose array under test is the result of the decoding.
asBase64Decoded
()

Decodes the actual value as a Base64 encoded string, the decoded bytes becoming the new array under test.

public AbstractBooleanAssert<?>

Returns:

a new BooleanAssert instance whose value under test is the result of the parse.
asBoolean
()

Parses the actual value as boolean, the parsed boolean becoming the new value under test.

public AbstractByteAssert<?>

Returns:

a new ByteAssert instance whose value under test is the result of the parse.
asByte
()

Parses the actual value as byte, using radix 10, the parsed byte becoming the new value under test.

public AbstractDoubleAssert<?>

Returns:

a new DoubleAssert instance whose value under test is the result of the parse.
asDouble
()

Parses the actual value as double, the parsed double becoming the new value under test.

public AbstractFloatAssert<?>

Returns:

a new FloatAssert instance whose value under test is the result of the parse.
asFloat
()

Parses the actual value as float, the parsed float becoming the new value under test.

public AbstractIntegerAssert<?>

Returns:

a new IntegerAssert instance whose value under test is the result of the parse.
asInt
()

Parses the actual value as integer, using radix 10, the parsed integer becoming the new value under test.

public AbstractLongAssert<?>

Returns:

a new LongAssert instance whose value under test is the result of the parse.
asLong
()

Parses the actual value as long, using radix 10, the parsed long becoming the new value under test.

public AbstractShortAssert<?>

Returns:

a new ShortAssert instance whose value under test is the result of the parse.
asShort
()

Parses the actual value as short, using radix 10, the parsed short becoming the new value under test.

public AbstractByteArrayAssert<?>

Returns:

a new AbstractByteArrayAssert instance whose value under test is the result of parsing the string.
bytes
()

Encodes the actual value as byte array using the platform's default charset, the encoded byte array becoming the new value under test.

public AbstractByteArrayAssert<?>

Returns:

a new AbstractByteArrayAssert instance whose value under test is the result of parsing the string.
bytes
(Charset
the Charset to be used to encode the string.
charset
)

Encodes the actual value as byte array using a specific Charset, the encoded byte array becoming the new value under test.

public AbstractByteArrayAssert<?>

Returns:

a new AbstractByteArrayAssert instance whose value under test is the result of parsing the string.
bytes
(String
the Charset to be used to encode the string.
charsetName
)

Encodes the actual value as byte array using a specific Charset, the encoded byte array becoming the new value under test.

public AbstractByteArrayAssert<?>

Returns:

a new ByteArrayAssert instance whose array under test is the result of the decoding.
decodedAsBase64
()

Deprecated use asBase64Decoded() instead.
public SELF

Returns:

this assertion object.
isBase64
()

Verifies that the actual value is a valid Base64 encoded string.

public SELF

Returns:

this assertion object.
isBetween
(String
the start value (inclusive), expected not to be null.
startInclusive
,
String
the end value (inclusive), expected not to be null.
endInclusive
)

Verifies that the actual value is in [start, end] range (start included, end included) according to String#compareTo(String).

public SELF

Returns:

this assertion object.
isEqualTo
(String
the format template used to build the expected String.
expectedStringTemplate
,
Object...
the arguments referenced by the format specifiers in the format string.
args
)

Verifies that the actual value is equal to expected build using String#format(String stringTemplate, Object... args).

public SELF

Returns:

this assertion object.
isEqualTo
(String
the given String to compare the actual to.
expected
)

Verifies that the actual value is equal to expected.

public SELF

Returns:

this assertion object.
isGreaterThan
(String
the String to compare the actual value to.
other
)

Verifies that the actual value is greater than the given String according to String#compareTo(String).

public SELF

Returns:

this assertion object.
isGreaterThanOrEqualTo
(String
the String to compare the actual value to.
other
)

Verifies that the actual value is greater than or equal to the given String according to String#compareTo(String).

public SELF

Returns:

this assertion object.
isLessThan
(String
the String to compare the actual value to.
other
)

Verifies that the actual value is less than the given String according to String#compareTo(String).

public SELF

Returns:

this assertion object.
isLessThanOrEqualTo
(String
the String to compare the actual value to.
other
)

Verifies that the actual value is less than or equal to the given String according to String#compareTo(String).

public SELF

Returns:

this assertion object.
isStrictlyBetween
(String
the start value (exclusive), expected not to be null.
startExclusive
,
String
the end value (exclusive), expected not to be null.
endExclusive
)

Verifies that the actual value is strictly in ]start, end[ range (start excluded, end excluded) according to String#compareTo(String).

public SELF

Returns:

this assertion object.
usingComparator
(Comparator<? super String>
the comparator to use for the incoming assertions.
customComparator
)

Overrides org.assertj.core.api.AbstractCharSequenceAssert.usingComparator.

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

Use the given custom comparator instead of relying on String natural comparator for the incoming assertions.
public SELF

Returns:

this assertion object.
usingComparator
(Comparator<? super String>
the comparator to use for the incoming assertions.
customComparator
,
String
comparator description to be used in assertion error messages
customComparatorDescription
)

Overrides org.assertj.core.api.AbstractCharSequenceAssert.usingComparator.

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

Use the given custom comparator instead of relying on String natural comparator for the incoming assertions.
public SELF
Inherited from org.assertj.core.api.AbstractCharSequenceAssert:
containscontainscontainsAnyOfcontainsIgnoringCasecontainsIgnoringNewLinescontainsIgnoringWhitespacescontainsOnlyDigitscontainsOnlyOncecontainsOnlyWhitespacescontainsPatterncontainsPatterncontainsPatternSatisfyingcontainsPatternSatisfyingcontainsSequencecontainsSequencecontainsSubsequencecontainsSubsequencecontainsWhitespacesdoesNotContaindoesNotContaindoesNotContainAnyWhitespacesdoesNotContainIgnoringCasedoesNotContainOnlyWhitespacesdoesNotContainPatterndoesNotContainPatterndoesNotEndWithdoesNotEndWithIgnoringCasedoesNotEndWithWhitespacesdoesNotMatchdoesNotMatchdoesNotStartWithdoesNotStartWithIgnoringCasedoesNotStartWithWhitespacesendsWithendsWithIgnoringCasehasLineCounthasSameSizeAshasSameSizeAshasSameSizeAshasSizehasSizeBetweenhasSizeGreaterThanhasSizeGreaterThanOrEqualTohasSizeLessThanhasSizeLessThanOrEqualToinHexadecimalinUnicodeisAlphabeticisAlphanumericisASCIIisBlankisEmptyisEqualToIgnoringCaseisEqualToIgnoringNewLinesisEqualToIgnoringWhitespaceisEqualToNormalizingNewlinesisEqualToNormalizingPunctuationAndWhitespaceisEqualToNormalizingUnicodeisEqualToNormalizingWhitespaceisHexadecimalisJavaBlankisLowerCaseisMixedCaseisNotBlankisNotEmptyisNotEqualToIgnoringCaseisNotEqualToIgnoringWhitespaceisNotEqualToNormalizingWhitespaceisNotJavaBlankisNullOrEmptyisPrintableisSubstringOfisUpperCaseisVisibleisXmlEqualToisXmlEqualToContentOfmatchesmatchesmatchesSatisfyingmatchesSatisfyingstartsWithstartsWithIgnoringCaseusingDefaultElementComparatorusingElementComparator

Field Detail

comparablesback to summary
pack-priv Comparables comparables
Annotations
@VisibleForTesting
failuresback to summary
pack-priv Failures failures
Annotations
@VisibleForTesting

Constructor Detail

AbstractStringAssertback to summary
protected AbstractStringAssert(String actual, Class<?> selfType)

Method Detail

asBase64Decodedback to summary
public AbstractByteArrayAssert<?> asBase64Decoded()

Decodes the actual value as a Base64 encoded string, the decoded bytes becoming the new array under test.

Examples:

 // assertion succeeds
assertThat("QXNzZXJ0Sg==").asBase64Decoded().containsExactly("AssertJ".getBytes());

// assertion succeeds even without padding as it is optional by specification
assertThat("QXNzZXJ0Sg").asBase64Decoded().containsExactly("AssertJ".getBytes());

// assertion fails as it has invalid Base64 characters
assertThat("inv@lid").asBase64Decoded();
Returns:AbstractByteArrayAssert<?>

a new ByteArrayAssert instance whose array under test is the result of the decoding.

Annotations
@CheckReturnValue
Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is not a valid Base64 encoded string.
Since
3.22.0
asBooleanback to summary
public AbstractBooleanAssert<?> asBoolean()

Parses the actual value as boolean, the parsed boolean becoming the new value under test.

Note that only when the string is equal to the string "true", ignoring case, and can have leading and trailing space, the parsed value will be true. Otherwise, the value will be false.

Examples:

 assertThat("truE").asBoolean().isTrue();
assertThat("false").asBoolean().isFalse();
assertThat("foo bar").asBoolean().isFalse();
assertThat((String) null).asBoolean().isFalse(); 
Returns:AbstractBooleanAssert<?>

a new BooleanAssert instance whose value under test is the result of the parse.

Since
3.25.0
asByteback to summary
public AbstractByteAssert<?> asByte()

Parses the actual value as byte, using radix 10, the parsed byte becoming the new value under test.

Examples:


// assertion succeeds:
assertThat("127").asByte().isEqualTo((byte) 127);

// assertions fail as the actual value is null or not a valid byte
assertThat((String) null).asByte();
assertThat("1L").asByte(); 
Returns:AbstractByteAssert<?>

a new ByteAssert instance whose value under test is the result of the parse.

Exceptions
AssertionError:
if the actual value is null or not a valid byte.
Since
3.25.0
asDoubleback to summary
public AbstractDoubleAssert<?> asDouble()

Parses the actual value as double, the parsed double becoming the new value under test.

Examples:


// assertion succeeds:
assertThat("1.2e308").asDouble().isCloseTo(1.2e308, withinPercentage(0.001));

// assertions fail as the actual value is null or not a double:
assertThat((String) null).asDouble();
assertThat("foo").asDouble(); 
Returns:AbstractDoubleAssert<?>

a new DoubleAssert instance whose value under test is the result of the parse.

Exceptions
AssertionError:
if the actual value is null or not a parseable double.
Since
3.25.0
asFloatback to summary
public AbstractFloatAssert<?> asFloat()

Parses the actual value as float, the parsed float becoming the new value under test.

Examples:


// assertion succeeds:
assertThat("1.2f").asFloat().isCloseTo(1.2f, withinPercentage(0.01));

// assertions fail as the actual value is null or not a float:
assertThat((String) null).asFloat();
assertThat("foo").asFloat();
Returns:AbstractFloatAssert<?>

a new FloatAssert instance whose value under test is the result of the parse.

Exceptions
AssertionError:
if the actual value is null or not a parseable float.
Since
3.25.0
asIntback to summary
public AbstractIntegerAssert<?> asInt()

Parses the actual value as integer, using radix 10, the parsed integer becoming the new value under test.

Examples:


// assertion succeeds:
assertThat("2147483647").asInt().isEqualTo(2147483647);

// assertions fail as the actual value is null or not a valid int:
assertThat((String) null).asInt();
assertThat("1e100").asInt();
Returns:AbstractIntegerAssert<?>

a new IntegerAssert instance whose value under test is the result of the parse.

Exceptions
AssertionError:
if the actual value is null or not a valid int.
Since
3.25.0
asLongback to summary
public AbstractLongAssert<?> asLong()

Parses the actual value as long, using radix 10, the parsed long becoming the new value under test.

Examples:


// assertion succeeds:
assertThat("1").asLong().isEqualTo(1L);

// assertions fail as the actual value is null or not a long:
assertThat((String) null).asLong();
assertThat("1e100").asLong();
Returns:AbstractLongAssert<?>

a new LongAssert instance whose value under test is the result of the parse.

Exceptions
AssertionError:
if the actual value is null or not a valid long.
Since
3.25.0
asShortback to summary
public AbstractShortAssert<?> asShort()

Parses the actual value as short, using radix 10, the parsed short becoming the new value under test.

Examples:


// assertion succeeds:
assertThat("32767").asShort().isEqualTo((short) 32767);

// assertions fail as the actual value is null or not a valid short:
assertThat((String) null).asShort();
assertThat("-32769").asShort(); 
Returns:AbstractShortAssert<?>

a new ShortAssert instance whose value under test is the result of the parse.

Exceptions
AssertionError:
if the actual value is null or not a valid short.
Since
3.25.0
bytesback to summary
public AbstractByteArrayAssert<?> bytes()

Encodes the actual value as byte array using the platform's default charset, the encoded byte array becoming the new value under test.

Examples:

 assertThat("abc").bytes()
                 .isEqualTo(new byte[] {'a', 'b', 'c'});

assertThat("").bytes()
              .isEmpty(); 
Returns:AbstractByteArrayAssert<?>

a new AbstractByteArrayAssert instance whose value under test is the result of parsing the string.

Exceptions
AssertionError:
if the actual string is null.
Since
3.26.0
bytesback to summary
public AbstractByteArrayAssert<?> bytes(Charset charset)

Encodes the actual value as byte array using a specific Charset, the encoded byte array becoming the new value under test.

Examples:

 assertThat("abc").bytes(StandardCharsets.US_ASCII)
                 .isEqualTo("abc".getBytes(StandardCharsets.US_ASCII));

assertThat("").bytes(StandardCharsets.US_ASCII)
              .isEmpty(); 
Parameters
charset:Charset

the Charset to be used to encode the string.

Returns:AbstractByteArrayAssert<?>

a new AbstractByteArrayAssert instance whose value under test is the result of parsing the string.

Exceptions
NullPointerException:
if charset parameter is null.
AssertionError:
if the actual string is null.
Since
3.26.0
bytesback to summary
public AbstractByteArrayAssert<?> bytes(String charsetName)

Encodes the actual value as byte array using a specific Charset, the encoded byte array becoming the new value under test.

Examples:

 assertThat("abc").bytes(StandardCharsets.US_ASCII)
                 .isEqualTo("abc".getBytes(StandardCharsets.US_ASCII));

assertThat("").bytes(StandardCharsets.US_ASCII)
              .isEmpty(); 
Parameters
charsetName:String

the Charset to be used to encode the string.

Returns:AbstractByteArrayAssert<?>

a new AbstractByteArrayAssert instance whose value under test is the result of parsing the string.

Exceptions
NullPointerException:
if named charset parameter is null.
AssertionError:
if the actual string is null or if the named charset parameter is not supported.
Since
3.26.0
decodedAsBase64back to summary
public AbstractByteArrayAssert<?> decodedAsBase64()

Deprecated

use asBase64Decoded() instead.

Decodes the actual value as a Base64 encoded string, the decoded bytes becoming the new array under test.

Examples:

 // assertion succeeds
assertThat("QXNzZXJ0Sg==").decodedAsBase64().containsExactly("AssertJ".getBytes());

// assertion succeeds even without padding as it is optional by specification
assertThat("QXNzZXJ0Sg").decodedAsBase64().containsExactly("AssertJ".getBytes());

// assertion fails as it has invalid Base64 characters
assertThat("inv@lid").decodedAsBase64();
Returns:AbstractByteArrayAssert<?>

a new ByteArrayAssert instance whose array under test is the result of the decoding.

Annotations
@Deprecated
@CheckReturnValue
Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is not a valid Base64 encoded string.
Since
3.16.0
isBase64back to summary
public SELF isBase64()

Verifies that the actual value is a valid Base64 encoded string.

Examples:

 // assertion succeeds
assertThat("QXNzZXJ0Sg==").isBase64();

// assertion succeeds even without padding as it is optional by specification
assertThat("QXNzZXJ0Sg").isBase64();

// assertion fails as it has invalid Base64 characters
assertThat("inv@lid").isBase64();
Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is not a valid Base64 encoded string.
Since
3.16.0
isBetweenback to summary
public SELF isBetween(String startInclusive, String endInclusive)

Verifies that the actual value is in [start, end] range (start included, end included) according to String#compareTo(String).

Note that it is possible to change the comparison strategy with usingComparator.

Examples:

 // assertions succeed
assertThat("ab").isBetween("aa", "ac")
                .isBetween("ab", "ac")
                .isBetween("aa", "ab")
                .isBetween("ab", "ab")
                .isBetween("a", "c")
                .usingComparator(String.CASE_INSENSITIVE_ORDER)
                .isBetween("AA", "AC");

// assertions fail
assertThat("ab").isBetween("ac", "bc");
assertThat("ab").isBetween("abc", "ac");
Parameters
startInclusive:String

the start value (inclusive), expected not to be null.

endInclusive:String

the end value (inclusive), expected not to be null.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is not in the [start, end] range.
NullPointerException:
  • if start value is null.
  • if end value is null.
Since
3.11.0
isEqualToback to summary
public SELF isEqualTo(String expectedStringTemplate, Object... args)

Verifies that the actual value is equal to expected build using String#format(String stringTemplate, Object... args).

Note that for this assertion to be called, you must use a format template with parameters otherwise isEqualTo(Object) is called which does not perform any formatting. For example, if you only use %n in the template they won't be replaced.

Examples:

 // assertion succeeds
assertThat("R2D2").isEqualTo("%d%s%d%s", "R", 2, "D", 2);

// assertion fails
assertThat("C6PO").isEqualTo("%d%s%d%s", "R", 2, "D", 2);

// assertion fails with java.lang.NullPointerException
assertThat("1,A,2").isEqualTo(null, 1, "A", 2);

// assertion fails with java.util.IllegalFormatException
assertThat("1").isEqualTo("%s%s", 1); 
Parameters
expectedStringTemplate:String

the format template used to build the expected String.

args:Object[]

the arguments referenced by the format specifiers in the format string.

Returns:SELF

this assertion object.

Exceptions
NullPointerException:
if stringTemplate parameter is null.
AssertionError:
if the actual value is null as the template you provide must not be null.
IllegalFormatException:
as in String#format(String, Object...), see Details section of the formatter class specification.
Since
3.12.0
isEqualToback to summary
public SELF isEqualTo(String expected)

Verifies that the actual value is equal to expected.

This method needs to be overridden because otherwise isEqualTo(String, Object...) is called from tests in Kotlin without args which breaks whenever the is % in the string.

Parameters
expected:String

the given String to compare the actual to.

Returns:SELF

this assertion object.

Since
3.13.0
See Also
Assert#isEqualTo(java.lang.Object)
isGreaterThanback to summary
public SELF isGreaterThan(String other)

Verifies that the actual value is greater than the given String according to String#compareTo(String).

Note that it is possible to change the comparison strategy with usingComparator.

Examples:

 // assertions succeed
assertThat("xyz").isGreaterThan("abc")
                 .isGreaterThan("xy")
                 .isGreaterThan("ABC");
assertThat("XYZ").usingComparator(String.CASE_INSENSITIVE_ORDER)
                 .isGreaterThan("abc");

// assertions fail
assertThat("xyz").isGreaterThan("xyzz");
assertThat("xyz").isGreaterThan("xyz");
assertThat("xyz").isGreaterThan("z");
Parameters
other:String

the String to compare the actual value to.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is less than or equal to the given one.
Since
3.11.0
isGreaterThanOrEqualToback to summary
public SELF isGreaterThanOrEqualTo(String other)

Verifies that the actual value is greater than or equal to the given String according to String#compareTo(String).

Note that it is possible to change the comparison strategy with usingComparator.

Examples:

 // assertions succeed
assertThat("xyz").isGreaterThanOrEqualTo("abc")
                 .isGreaterThanOrEqualTo("xyz")
                 .isGreaterThanOrEqualTo("xy")
                 .isGreaterThanOrEqualTo("ABC");
assertThat("XYZ").usingComparator(String.CASE_INSENSITIVE_ORDER)
                 .isGreaterThanOrEqualTo("abc");

// assertions fail
assertThat("xyz").isGreaterThanOrEqualTo("xyzz");
assertThat("xyz").isGreaterThanOrEqualTo("z");
Parameters
other:String

the String to compare the actual value to.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is less than the given one.
Since
3.11.0
isLessThanback to summary
public SELF isLessThan(String other)

Verifies that the actual value is less than the given String according to String#compareTo(String).

Note that it is possible to change the comparison strategy with usingComparator.

Examples:

 // assertions succeed
assertThat("abc").isLessThan("bcd")
                 .isLessThan("b")
                 .isLessThan("abca")
                 .usingComparator(String.CASE_INSENSITIVE_ORDER)
                 .isLessThan("BCD");

// assertions fail
assertThat("abc").isLessThan("ab");
assertThat("abc").isLessThan("abc");
assertThat("abc").isLessThan("ABC");
Parameters
other:String

the String to compare the actual value to.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is greater than or equal to the given one.
Since
3.11.0
isLessThanOrEqualToback to summary
public SELF isLessThanOrEqualTo(String other)

Verifies that the actual value is less than or equal to the given String according to String#compareTo(String).

Note that it is possible to change the comparison strategy with usingComparator.

Examples:

 // assertions succeed
assertThat("abc").isLessThanOrEqualTo("bcd")
                 .isLessThanOrEqualTo("abc")
                 .isLessThanOrEqualTo("b")
                 .isLessThanOrEqualTo("abca")
                 .usingComparator(String.CASE_INSENSITIVE_ORDER)
                 .isLessThanOrEqualTo("ABC");

// assertions fail
assertThat("abc").isLessThanOrEqualTo("ab");
assertThat("abc").isLessThanOrEqualTo("ABC");
Parameters
other:String

the String to compare the actual value to.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is greater than the given one.
Since
3.11.0
isStrictlyBetweenback to summary
public SELF isStrictlyBetween(String startExclusive, String endExclusive)

Verifies that the actual value is strictly in ]start, end[ range (start excluded, end excluded) according to String#compareTo(String).

Note that it is possible to change the comparison strategy with usingComparator.

Examples:

 // assertions succeed
assertThat("ab").isStrictlyBetween("aa", "ac")
                .isStrictlyBetween("a", "c")
                .usingComparator(String.CASE_INSENSITIVE_ORDER)
                .isStrictlyBetween("AA", "AC");

// assertions fail
assertThat("ab").isStrictlyBetween("ac", "bc");
assertThat("ab").isStrictlyBetween("ab", "ac");
assertThat("ab").isStrictlyBetween("aa", "ab");
assertThat("ab").isStrictlyBetween("abc", "ac");
Parameters
startExclusive:String

the start value (exclusive), expected not to be null.

endExclusive:String

the end value (exclusive), expected not to be null.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is not in ]start, end[ range.
NullPointerException:
  • if start value is null.
  • if end value is null.
Since
3.11.0
usingComparatorback to summary
public SELF usingComparator(Comparator<? super String> customComparator)

Overrides org.assertj.core.api.AbstractCharSequenceAssert.usingComparator.

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

Use the given custom comparator instead of relying on String natural comparator for the incoming assertions.

The custom comparator is bound to an assertion instance, meaning that if a new assertion instance is created it is forgotten and the default (String natural comparator) is used.

Examples :

 // assertions succeed
assertThat("abc").usingComparator(String.CASE_INSENSITIVE_ORDER)
                 .isEqualTo("Abc")
                 .isEqualTo("ABC");

// assertion fails as it relies on String natural comparator
assertThat("abc").isEqualTo("ABC");
Parameters
customComparator:Comparator<? super String>

the comparator to use for the incoming assertions.

Returns:SELF

this assertion object.

Annotations
@Override
@CheckReturnValue
Exceptions
NullPointerException:
if the given comparator is null.
usingComparatorback to summary
public SELF usingComparator(Comparator<? super String> customComparator, String customComparatorDescription)

Overrides org.assertj.core.api.AbstractCharSequenceAssert.usingComparator.

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

Use the given custom comparator instead of relying on String natural comparator for the incoming assertions.

The custom comparator is bound to an assertion instance, meaning that if a new assertion instance is created it is forgotten and the default (String natural comparator) is used.

Examples :

 // assertions succeed
assertThat("abc").usingComparator(String.CASE_INSENSITIVE_ORDER, "String case insensitive comparator")
                 .isEqualTo("Abc")
                 .isEqualTo("ABC");

// assertion fails as it relies on String natural comparator
assertThat("abc").isEqualTo("ABC");
Parameters
customComparator:Comparator<? super String>

the comparator to use for the incoming assertions.

customComparatorDescription:String

comparator description to be used in assertion error messages

Returns:SELF

this assertion object.

Annotations
@Override
@CheckReturnValue
Exceptions
NullPointerException:
if the given comparator is null.
usingDefaultComparatorback to summary
public SELF usingDefaultComparator()

Overrides org.assertj.core.api.AbstractCharSequenceAssert.usingDefaultComparator.

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

Doc from org.assertj.core.api.AbstractAssert.usingDefaultComparator.

Revert to standard comparison for the incoming assertion checks.

This method should be used to disable a custom comparison strategy set by calling usingComparator.

Returns:SELF

Doc from org.assertj.core.api.Assert.usingDefaultComparator.

this assertion object.

Annotations
@Override
@CheckReturnValue