Class AbstractComparableAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>,ACTUAL extends Comparable<? super ACTUAL>>
- 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> ComparableAssert<SELF,,ACTUAL> Descriptable<SELF>,ExtensionPoints<SELF,ACTUAL>
- Direct Known Subclasses:
AbstractBigDecimalAssert,AbstractBigIntegerAssert,AbstractByteAssert,AbstractCharacterAssert,AbstractDoubleAssert,AbstractDurationAssert,AbstractFloatAssert,AbstractIntegerAssert,AbstractLongAssert,AbstractPathAssert,AbstractShortAssert,AbstractUriAssert,GenericComparableAssert
ComparableAssert.- Author:
- Alex Ruiz, Mikhail Mazursky
-
Field Summary
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, info, myself, objects, throwUnsupportedExceptionOnEquals -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractComparableAssert(ACTUAL actual, Class<?> selfType) -
Method Summary
Modifier and TypeMethodDescriptioninBinary()Use binary object representation instead of standard representation in error messages.Use hexadecimal object representation instead of standard representation in error messages.Verifies that the actual value is in [start, end] range (start included, end included).isEqualByComparingTo(ACTUAL other) Verifies that the actual value is equal to the given one by invoking.Comparable.compareTo(Object)isGreaterThan(ACTUAL other) Verifies that the actual value is greater than the given one.isGreaterThanOrEqualTo(ACTUAL other) Verifies that the actual value is greater than or equal to the given one.isLessThan(ACTUAL other) Verifies that the actual value is less than the given one.isLessThanOrEqualTo(ACTUAL other) Verifies that the actual value is less than or equal to the given one.isNotEqualByComparingTo(ACTUAL other) Verifies that the actual value is not equal to the given one by invoking.Comparable.compareTo(Object)isStrictlyBetween(ACTUAL startExclusive, ACTUAL endExclusive) Verifies that the actual value is in ]start, end[ range (start excluded, end excluded).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.Methods inherited from class org.assertj.core.api.AbstractObjectAssert
as, as, doesNotReturn, extracting, extracting, extracting, extracting, extracting, extracting, extractingForProxy, getComparatorsByType, hasAllNullFieldsOrProperties, hasAllNullFieldsOrPropertiesExcept, hasFieldOrProperty, hasFieldOrPropertyWithValue, hasNoNullFieldsOrProperties, hasNoNullFieldsOrPropertiesExcept, hasOnlyFields, isEqualToComparingFieldByField, isEqualToComparingFieldByFieldRecursively, isEqualToComparingOnlyGivenFields, isEqualToIgnoringGivenFields, isEqualToIgnoringNullFields, newObjectAssert, returns, usingComparatorForFields, usingComparatorForType, usingRecursiveAssertion, usingRecursiveAssertion, usingRecursiveComparison, usingRecursiveComparisonMethods inherited from class org.assertj.core.api.AbstractAssert
actual, areEqual, asInstanceOf, asList, assertionError, asString, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, doesNotHaveSameHashCodeAs, doesNotHaveToString, doesNotHaveToString, doesNotMatch, doesNotMatch, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, hasToString, 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, usingEquals, usingEquals, 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, describedAs, describedAs
-
Constructor Details
-
AbstractComparableAssert
-
-
Method Details
-
isEqualByComparingTo
Verifies that the actual value is equal to the given one by invoking.Comparable.compareTo(Object)Example:
// assertion will pass assertThat(1.0).isEqualByComparingTo(1.0); // assertion will pass because 8.0 is equal to 8.00 usingBigDecimal.compareTo(BigDecimal)assertThat(new BigDecimal("8.0")).isEqualByComparingTo(new BigDecimal("8.00")); // assertion will fail assertThat(new BigDecimal(1.0)).isEqualByComparingTo(new BigDecimal(2.0));- Specified by:
isEqualByComparingToin interfaceComparableAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>, ACTUAL extends Comparable<? super ACTUAL>> - Parameters:
other- the given value to compare the actual value to.- Returns:
thisassertion object.
-
isNotEqualByComparingTo
Verifies that the actual value is not equal to the given one by invoking.Comparable.compareTo(Object)Example:
// assertion will pass assertThat(new BigDecimal(1.0)).isNotEqualByComparingTo(new BigDecimal(2.0)); // assertion will fail assertThat(1.0).isNotEqualByComparingTo(1.0); // assertion will fail because 8.0 is equal to 8.00 usingBigDecimal.compareTo(BigDecimal)assertThat(new BigDecimal("8.0")).isNotEqualByComparingTo(new BigDecimal("8.00"));- Specified by:
isNotEqualByComparingToin interfaceComparableAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>, ACTUAL extends Comparable<? super ACTUAL>> - Parameters:
other- the given value to compare the actual value to.- Returns:
thisassertion object.
-
isLessThan
Verifies that the actual value is less than the given one.Example:
// assertions will pass assertThat('a').isLessThan('b'); assertThat(BigInteger.ZERO).isLessThan(BigInteger.ONE); // assertions will fail assertThat('a').isLessThan('a'); assertThat(BigInteger.ONE).isLessThan(BigInteger.ZERO);- Specified by:
isLessThanin interfaceComparableAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>, ACTUAL extends Comparable<? super ACTUAL>> - Parameters:
other- the given value to compare the actual value to.- Returns:
thisassertion object.
-
isLessThanOrEqualTo
Verifies that the actual value is less than or equal to the given one.Example:
// assertions will pass assertThat('a').isLessThanOrEqualTo('b'); assertThat('a').isLessThanOrEqualTo('a'); assertThat(BigInteger.ZERO).isLessThanOrEqualTo(BigInteger.ZERO); // assertions will fail assertThat('b').isLessThanOrEqualTo('a'); assertThat(BigInteger.ONE).isLessThanOrEqualTo(BigInteger.ZERO);- Specified by:
isLessThanOrEqualToin interfaceComparableAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>, ACTUAL extends Comparable<? super ACTUAL>> - Parameters:
other- the given value to compare the actual value to.- Returns:
thisassertion object.
-
isGreaterThan
Verifies that the actual value is greater than the given one.Example:
// assertions will pass assertThat('b').isGreaterThan('a'); assertThat(BigInteger.ONE).isGreaterThan(BigInteger.ZERO); // assertions will fail assertThat('b').isGreaterThan('a'); assertThat(BigInteger.ZERO).isGreaterThan(BigInteger.ZERO);- Specified by:
isGreaterThanin interfaceComparableAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>, ACTUAL extends Comparable<? super ACTUAL>> - Parameters:
other- the given value to compare the actual value to.- Returns:
thisassertion object.
-
isGreaterThanOrEqualTo
Verifies that the actual value is greater than or equal to the given one.Example:
// assertions will pass assertThat('b').isGreaterThanOrEqualTo('a'); assertThat(BigInteger.ONE).isGreaterThanOrEqualTo(BigInteger.ONE); // assertions will fail assertThat('a').isGreaterThanOrEqualTo('b'); assertThat(BigInteger.ZERO).isGreaterThanOrEqualTo(BigInteger.ONE);- Specified by:
isGreaterThanOrEqualToin interfaceComparableAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>, ACTUAL extends Comparable<? super ACTUAL>> - Parameters:
other- the given value to compare the actual value to.- Returns:
thisassertion object.
-
isBetween
Verifies that the actual value is in [start, end] range (start included, end included).Example:
// assertions succeed assertThat('b').isBetween('a', 'c'); assertThat('a').isBetween('a', 'b'); assertThat('b').isBetween('a', 'b'); // assertions fail assertThat('a').isBetween('b', 'c'); assertThat('c').isBetween('a', 'b');- Specified by:
isBetweenin interfaceComparableAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>, ACTUAL extends Comparable<? super ACTUAL>> - Parameters:
startInclusive- the start value (inclusive), expected not to be null.endInclusive- the end value (inclusive), expected not to be null.- Returns:
- this assertion object.
-
isStrictlyBetween
Verifies that the actual value is in ]start, end[ range (start excluded, end excluded).Example:
// assertion succeeds assertThat('b').isStrictlyBetween('a', 'c'); // assertions fail assertThat('d').isStrictlyBetween('a', 'c'); assertThat('a').isStrictlyBetween('b', 'd'); assertThat('a').isStrictlyBetween('a', 'b'); assertThat('b').isStrictlyBetween('a', 'b');- Specified by:
isStrictlyBetweenin interfaceComparableAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>, ACTUAL extends Comparable<? super ACTUAL>> - Parameters:
startExclusive- the start value (exclusive), expected not to be null.endExclusive- the end value (exclusive), expected not to be null.- Returns:
- this assertion object.
-
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 AbstractComparableAssert<SELF,ACTUAL>, ACTUAL extends Comparable<? super ACTUAL>> - Overrides:
usingComparatorin classAbstractAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>, ACTUAL extends Comparable<? super ACTUAL>> - 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 the current assertion chain, 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 AbstractComparableAssert<SELF,ACTUAL>, ACTUAL extends Comparable<? super ACTUAL>> - Overrides:
usingComparatorin classAbstractAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>, ACTUAL extends Comparable<? super ACTUAL>> - 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 AbstractComparableAssert<SELF,ACTUAL>, ACTUAL extends Comparable<? super ACTUAL>> - Overrides:
usingDefaultComparatorin classAbstractAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>, ACTUAL extends Comparable<? super ACTUAL>> - 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:
assertThat("µµµ").contains("μμμ"); java.lang.AssertionError: Expecting: <"µµµ"> to contain: <"μμμ">With Hexadecimal message:
assertThat("µµµ").inHexadecimal().contains("μμμ"); java.lang.AssertionError: Expecting: <"['00B5', '00B5', '00B5']"> to contain: <"['03BC', '03BC', '03BC']">- Overrides:
inHexadecimalin classAbstractAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>, ACTUAL extends Comparable<? super ACTUAL>> - Returns:
thisassertion object.
-
inBinary
Description copied from class:AbstractAssertUse binary object representation instead of standard representation in error messages.Example:
assertThat(1).inBinary().isEqualTo(2); org.junit.ComparisonFailure: Expected :0b00000000_00000000_00000000_00000010 Actual :0b00000000_00000000_00000000_00000001- Overrides:
inBinaryin classAbstractAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>, ACTUAL extends Comparable<? super ACTUAL>> - Returns:
thisassertion object.
-