Comparable assertions.
This class offers better compatibility than ComparableAssert and related implementations, currently limited
due to the upper bound of ComparableAssert's type parameters.
Let's take an example with a class Name implementing Comparable<Name>.
Comparable<Name> name1 = new Name("abc");
The following does not compile or work as expected:
// does not compile as assertThat(name1) resolves to Object assertions
assertThat(name1).isLessThanOrEqualTo(name1);
// compiles fine but requires a raw Comparable cast (assertThat resolves to AbstractComparableAssert)
assertThat((Comparable)name1).isLessThanOrEqualTo(name1);
// does not compile: Cannot infer type arguments for GenericComparableAssert<>
new GenericComparableAssert<>(name1).isLessThanOrEqualTo(name3);
// compiles fine with the concrete type (assertThat resolves to AbstractComparableAssert)
Name name = name1;
assertThat(name).isEqualByComparingTo(name);
This class aims to allow writing
// assertThatComparable resolves to AbstractUniversalComparableAssert
assertThatComparable(name1).isLessThanOrEqualTo(name1);
// it works with the concrete type too
assertThatComparable(name).isEqualByComparingTo(name);
Assertions#assertThatComparable(Comparable)
| Modifier and Type | Field and Description |
|---|---|
| pack-priv Comparables |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public SELF | inBinary()
Overrides org. |
| public SELF | inHexadecimal()
Overrides org. |
| public SELF | Returns: this assertion object.the start value (inclusive), expected not to be null. startInclusive, T the end value (inclusive), expected not to be null. endInclusive)Verifies that the actual value is in [start, end] range (start included, end included). |
| public SELF | Returns: this assertion object.the given value to compare the actual value to. other)Verifies that the actual value is equal to the given one by invoking
|
| public SELF | Returns: this assertion object.the given value to compare the actual value to. other)Verifies that the actual value is greater than the given one. |
| public SELF | Returns: this assertion object.the given value to compare the actual value to. other)Verifies that the actual value is greater than or equal to the given one. |
| public SELF | Returns: this assertion object.the given value to compare the actual value to. other)Verifies that the actual value is less than the given one. |
| public SELF | Returns: this assertion object.the given value to compare the actual value to. other)Verifies that the actual value is less than or equal to the given one. |
| public SELF | Returns: this assertion object.the given value to compare the actual value to. other)Verifies that the actual value is not equal to the given one by invoking
|
| public SELF | Returns: this assertion object.the start value (exclusive), expected not to be null. startExclusive, T the end value (exclusive), expected not to be null. endExclusive)Verifies that the actual value is in ]start, end[ range (start excluded, end excluded). |
| public SELF | usingComparator(Comparator<? super Comparable<T>>
the comparator to use for the incoming assertion checks. customComparator)Overrides org. Implements org. |
| public SELF | usingComparator(Comparator<? super Comparable<T>>
the comparator to use for the incoming assertion checks. customComparator, String comparator description to be used in assertion error messages customComparatorDescription)Overrides org. Implements org. |
| public SELF | usingDefaultComparator()
Overrides org. Implements org. |
| comparables | back to summary |
|---|---|
| pack-priv Comparables comparables
| |
| AbstractUniversalComparableAssert | back to summary |
|---|---|
| protected AbstractUniversalComparableAssert(Comparable<T> actual, Class<?> selfType) | |
| inBinary | back to summary |
|---|---|
| public SELF inBinary() Overrides org. Doc from org. Use binary object representation instead of standard representation in error messages. Example:
| |
| inHexadecimal | back to summary |
|---|---|
| public SELF inHexadecimal() Overrides org. Doc from org. Use 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:
| |
| isBetween | back to summary |
|---|---|
| public SELF isBetween(T startInclusive, T endInclusive) Verifies that the actual value is in [start, end] range (start included, end included). Example:
| |
| isEqualByComparingTo | back to summary |
|---|---|
| public SELF isEqualByComparingTo(T other) Verifies that the actual value is equal to the given one by invoking
Example:
| |
| isGreaterThan | back to summary |
|---|---|
| public SELF isGreaterThan(T other) Verifies that the actual value is greater than the given one. Example:
| |
| isGreaterThanOrEqualTo | back to summary |
|---|---|
| public SELF isGreaterThanOrEqualTo(T other) Verifies that the actual value is greater than or equal to the given one. Example:
| |
| isLessThan | back to summary |
|---|---|
| public SELF isLessThan(T other) Verifies that the actual value is less than the given one. Example:
| |
| isLessThanOrEqualTo | back to summary |
|---|---|
| public SELF isLessThanOrEqualTo(T other) Verifies that the actual value is less than or equal to the given one. Example:
| |
| isNotEqualByComparingTo | back to summary |
|---|---|
| public SELF isNotEqualByComparingTo(T other) Verifies that the actual value is not equal to the given one by invoking
Example:
| |
| isStrictlyBetween | back to summary |
|---|---|
| public SELF isStrictlyBetween(T startExclusive, T endExclusive) Verifies that the actual value is in ]start, end[ range (start excluded, end excluded). Example:
| |
| usingComparator | back to summary |
|---|---|
| public SELF usingComparator(Comparator<? super Comparable<T>> customComparator) Overrides org. Implements org. Doc from org. Use 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 :
| |
| usingComparator | back to summary |
|---|---|
| public SELF usingComparator(Comparator<? super Comparable<T>> customComparator, String customComparatorDescription) Overrides org. Implements org. Doc from org. Use 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 :
| |
| usingDefaultComparator | back to summary |
|---|---|
| public SELF usingDefaultComparator() Overrides org. Implements org. Doc from org. Revert to standard comparison for the incoming assertion checks.
This method should be used to disable a custom comparison strategy set by calling
| |