public class AbstractStringAssert<SELF extends AbstractStringAssert<SELF>> extends AbstractCharSequenceAssert<SELF,String>
actual, info, myself, throwUnsupportedExceptionOnEquals
Constructor and Description |
---|
AbstractStringAssert(String actual,
Class<?> selfType) |
Modifier and Type | Method and Description |
---|---|
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) . |
SELF |
isEqualTo(String expectedStringTemplate,
Object... args)
Verifies that the actual value is equal to expected build using {@link String#format(String stringTemplate, Object...
|
SELF |
isGreaterThan(String other)
Verifies that the actual value is greater than the given
String according to String.compareTo(String) . |
SELF |
isGreaterThanOrEqualTo(String other)
Verifies that the actual value is greater than or equal to the given
String according to String.compareTo(String) . |
SELF |
isLessThan(String other)
Verifies that the actual value is less than the given
String according to String.compareTo(String) . |
SELF |
isLessThanOrEqualTo(String other)
Verifies that the actual value is less than or equal to the given
String according to String.compareTo(String) . |
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) . |
SELF |
usingComparator(Comparator<? super String> customComparator)
Use the given custom comparator instead of relying on
String natural comparator for the incoming assertions. |
SELF |
usingComparator(Comparator<? super String> customComparator,
String customComparatorDescription)
Use the given custom comparator instead of relying on
String natural comparator for the incoming assertions. |
SELF |
usingDefaultComparator()
Revert to standard comparison for the incoming assertion checks.
|
contains, contains, containsIgnoringCase, containsOnlyDigits, containsOnlyOnce, containsOnlyWhitespaces, containsPattern, containsPattern, containsSequence, containsSequence, containsSubsequence, containsSubsequence, containsWhitespaces, doesNotContain, doesNotContain, doesNotContainAnyWhitespaces, doesNotContainOnlyWhitespaces, doesNotContainPattern, doesNotContainPattern, doesNotEndWith, doesNotMatch, doesNotMatch, doesNotStartWith, endsWith, hasLineCount, hasSameSizeAs, hasSameSizeAs, hasSameSizeAs, hasSize, hasSizeBetween, hasSizeGreaterThan, hasSizeGreaterThanOrEqualTo, hasSizeLessThan, hasSizeLessThanOrEqualTo, inHexadecimal, inUnicode, isBlank, isEmpty, isEqualToIgnoringCase, isEqualToIgnoringNewLines, isEqualToIgnoringWhitespace, isEqualToNormalizingNewlines, isEqualToNormalizingWhitespace, isJavaBlank, isLowerCase, isNotBlank, isNotEmpty, isNotEqualToIgnoringCase, isNotEqualToIgnoringWhitespace, isNotEqualToNormalizingWhitespace, isNotJavaBlank, isNullOrEmpty, isSubstringOf, isUpperCase, isXmlEqualTo, isXmlEqualToContentOf, matches, matches, startsWith, usingDefaultElementComparator, usingElementComparator
as, as, asList, asString, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, inBinary, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isInstanceOfSatisfying, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, newListAssertInstance, overridingErrorMessage, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, setCustomRepresentation, throwAssertionError, withFailMessage, withRepresentation, withThreadDumpOnError
public SELF isLessThan(String other)
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(CASE_INSENSITIVE)
.isLessThan("BCD");
// assertions fail
assertThat("abc").isLessThan("ab");
assertThat("abc").isLessThan("abc");
assertThat("abc").isLessThan("ABC");
other
- the String
to compare the actual value to.this
assertion object.AssertionError
- if the actual value is null
.AssertionError
- if the actual value is greater than or equal to the given one.public SELF isLessThanOrEqualTo(String other)
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(CASE_INSENSITIVE)
.isLessThanOrEqualTo("ABC");
// assertions fail
assertThat("abc").isLessThanOrEqualTo("ab");
assertThat("abc").isLessThanOrEqualTo("ABC");
other
- the String
to compare the actual value to.this
assertion object.AssertionError
- if the actual value is null
.AssertionError
- if the actual value is greater than the given one.public SELF isGreaterThan(String other)
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(CASE_INSENSITIVE)
.isGreaterThan("abc");
// assertions fail
assertThat("xyz").isGreaterThan("xyzz");
assertThat("xyz").isGreaterThan("xyz");
assertThat("xyz").isGreaterThan("z");
other
- the String
to compare the actual value to.this
assertion object.AssertionError
- if the actual value is null
.AssertionError
- if the actual value is less than or equal to the given one.public SELF isGreaterThanOrEqualTo(String other)
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(CASE_INSENSITIVE)
.isGreaterThanOrEqualTo("abc");
// assertions fail
assertThat("xyz").isGreaterThanOrEqualTo("xyzz");
assertThat("xyz").isGreaterThanOrEqualTo("z");
other
- the String
to compare the actual value to.this
assertion object.AssertionError
- if the actual value is null
.AssertionError
- if the actual value is less than the given one.public SELF isBetween(String startInclusive, String endInclusive)
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(CASE_INSENSITIVE)
.isBetween("AA", "AC");
// assertions fail
assertThat("ab").isBetween("ac", "bc");
assertThat("ab").isBetween("abc", "ac");
startInclusive
- the start value (inclusive), expected not to be null.endInclusive
- the end value (inclusive), expected not to be null.AssertionError
- if the actual value is null
.NullPointerException
- if start value is null
.NullPointerException
- if end value is null
.AssertionError
- if the actual value is not in the [start, end] range.public SELF isStrictlyBetween(String startExclusive, String endExclusive)
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(CASE_INSENSITIVE)
.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");
startExclusive
- the start value (exclusive), expected not to be null.endExclusive
- the end value (exclusive), expected not to be null.AssertionError
- if the actual value is null
.NullPointerException
- if start value is null
.NullPointerException
- if end value is null
.AssertionError
- if the actual value is not in ]start, end[ range.public SELF usingComparator(Comparator<? super String> customComparator)
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(CASE_INSENSITIVE)
.isEqualTo("Abc")
.isEqualTo("ABC");
// assertion fails as it relies on String natural comparator
assertThat("abc").isEqualTo("ABC");
usingComparator
in interface Assert<SELF extends AbstractStringAssert<SELF>,String>
usingComparator
in class AbstractCharSequenceAssert<SELF extends AbstractStringAssert<SELF>,String>
customComparator
- the comparator to use for the incoming assertions.this
assertion object.NullPointerException
- if the given comparator is null
.public SELF usingComparator(Comparator<? super String> customComparator, String customComparatorDescription)
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(CASE_INSENSITIVE, "String case insensitive comparator")
.isEqualTo("Abc")
.isEqualTo("ABC");
// assertion fails as it relies on String natural comparator
assertThat("abc").isEqualTo("ABC");
usingComparator
in interface Assert<SELF extends AbstractStringAssert<SELF>,String>
usingComparator
in class AbstractCharSequenceAssert<SELF extends AbstractStringAssert<SELF>,String>
customComparator
- the comparator to use for the incoming assertions.customComparatorDescription
- comparator description to be used in assertion error messagesthis
assertion object.NullPointerException
- if the given comparator is null
.public SELF usingDefaultComparator()
AbstractAssert
This method should be used to disable a custom comparison strategy set by calling usingComparator
.
usingDefaultComparator
in interface Assert<SELF extends AbstractStringAssert<SELF>,String>
usingDefaultComparator
in class AbstractCharSequenceAssert<SELF extends AbstractStringAssert<SELF>,String>
this
assertion object.public SELF isEqualTo(String expectedStringTemplate, Object... args)
String.format(String stringTemplate, Object... args)
.
Note that for this assertion to be called, you must use a format template with parameters otherwise AbstractAssert.isEqualTo(Object)
is callled which
does not perform any formatting. For example, it 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 NullPointerException
assertThat("1,A,2").isEqualTo(null, 1, "A", 2);
// assertion fails with IllegalFormatException
assertThat("1").isEqualTo("%s%s", 1);
expectedStringTemplate
- the format template used to build the expected String.args
- the arguments referenced by the format specifiers in the format string.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.Copyright © 2014–2019 AssertJ. All rights reserved.