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.public abstract class AbstractComparableAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>,ACTUAL extends Comparable<? super ACTUAL>> extends AbstractObjectAssert<SELF,ACTUAL> implements ComparableAssert<SELF,ACTUAL>
ComparableAssert.actual, info, myself| Constructor and Description |
|---|
AbstractComparableAssert(ACTUAL actual,
Class<?> selfType) |
| Modifier and Type | Method and Description |
|---|---|
SELF |
inBinary()
Use binary object representation instead of standard representation in error messages.
|
SELF |
inHexadecimal()
Use hexadecimal object representation instead of standard representation in error messages.
|
SELF |
isBetween(ACTUAL startInclusive,
ACTUAL endInclusive)
Verifies that the actual value is in [start, end] range (start included, end included).
|
SELF |
isEqualByComparingTo(ACTUAL other)
Verifies that the actual value is equal to the given one by invoking
. |
SELF |
isGreaterThan(ACTUAL other)
Verifies that the actual value is greater than the given one.
|
SELF |
isGreaterThanOrEqualTo(ACTUAL other)
Verifies that the actual value is greater than or equal to the given one.
|
SELF |
isLessThan(ACTUAL other)
Verifies that the actual value is less than the given one.
|
SELF |
isLessThanOrEqualTo(ACTUAL other)
Verifies that the actual value is less than or equal to the given one.
|
SELF |
isNotEqualByComparingTo(ACTUAL other)
Verifies that the actual value is not equal to the given one by invoking
. |
SELF |
isStrictlyBetween(ACTUAL startExclusive,
ACTUAL endExclusive)
Verifies that the actual value is in ]start, end[ range (start excluded, end excluded).
|
SELF |
usingComparator(Comparator<? super ACTUAL> customComparator)
Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
|
SELF |
usingComparator(Comparator<? super ACTUAL> customComparator,
String customComparatorDescription)
Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
|
SELF |
usingDefaultComparator()
Revert to standard comparison for incoming assertion checks.
|
as, as, extracting, hasFieldOrProperty, hasFieldOrPropertyWithValue, hasNoNullFieldsOrProperties, hasNoNullFieldsOrPropertiesExcept, isEqualToComparingFieldByField, isEqualToComparingFieldByFieldRecursively, isEqualToComparingOnlyGivenFields, isEqualToIgnoringGivenFields, isEqualToIgnoringNullFields, usingComparatorForFields, usingComparatorForTypeasList, asString, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasSameHashCodeAs, hasToString, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, overridingErrorMessage, setCustomRepresentation, throwAssertionError, withFailMessage, withRepresentation, withThreadDumpOnErrorpublic SELF isEqualByComparingTo(ACTUAL other)
Comparable.compareTo(Object).
Example:
// assertion will pass
assertThat(1.0).isEqualByComparingTo(1.0);
// assertion will pass because 8.0 is equal to 8.00 using BigDecimal.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));isEqualByComparingTo in interface ComparableAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>,ACTUAL extends Comparable<? super ACTUAL>>other - the given value to compare the actual value to.this assertion object.public SELF isNotEqualByComparingTo(ACTUAL other)
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 using BigDecimal.compareTo(BigDecimal)
assertThat(new BigDecimal("8.0")).isNotEqualByComparingTo(new BigDecimal("8.00"));isNotEqualByComparingTo in interface ComparableAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>,ACTUAL extends Comparable<? super ACTUAL>>other - the given value to compare the actual value to.this assertion object.public SELF isLessThan(ACTUAL other)
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);isLessThan in interface ComparableAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>,ACTUAL extends Comparable<? super ACTUAL>>other - the given value to compare the actual value to.this assertion object.public SELF isLessThanOrEqualTo(ACTUAL other)
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);isLessThanOrEqualTo in interface ComparableAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>,ACTUAL extends Comparable<? super ACTUAL>>other - the given value to compare the actual value to.this assertion object.public SELF isGreaterThan(ACTUAL other)
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);isGreaterThan in interface ComparableAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>,ACTUAL extends Comparable<? super ACTUAL>>other - the given value to compare the actual value to.this assertion object.public SELF isGreaterThanOrEqualTo(ACTUAL other)
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);isGreaterThanOrEqualTo in interface ComparableAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>,ACTUAL extends Comparable<? super ACTUAL>>other - the given value to compare the actual value to.this assertion object.public SELF isBetween(ACTUAL startInclusive, ACTUAL endInclusive)
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');isBetween in interface ComparableAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>,ACTUAL extends Comparable<? super ACTUAL>>startInclusive - the start value (inclusive), expected not to be null.endInclusive - the end value (inclusive), expected not to be null.public SELF isStrictlyBetween(ACTUAL startExclusive, ACTUAL endExclusive)
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');isStrictlyBetween in interface ComparableAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>,ACTUAL extends Comparable<? super ACTUAL>>startExclusive - the start value (exclusive), expected not to be null.endExclusive - the end value (exclusive), expected not to be null.public SELF usingComparator(Comparator<? super ACTUAL> customComparator)
AbstractAssertCustom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default comparison strategy. Examples :
// frodo and sam are instances of Character with Hobbit race (obviously :).
// raceComparator implements Comparator<Character>
assertThat(frodo).usingComparator(raceComparator).isEqualTo(sam);usingComparator in interface Assert<SELF extends AbstractComparableAssert<SELF,ACTUAL>,ACTUAL extends Comparable<? super ACTUAL>>usingComparator in class AbstractAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>,ACTUAL extends Comparable<? super ACTUAL>>customComparator - the comparator to use for incoming assertion checks.this assertion object.public SELF usingComparator(Comparator<? super ACTUAL> customComparator, String customComparatorDescription)
AbstractAssertCustom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default comparison strategy. 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);usingComparator in interface Assert<SELF extends AbstractComparableAssert<SELF,ACTUAL>,ACTUAL extends Comparable<? super ACTUAL>>usingComparator in class AbstractAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>,ACTUAL extends Comparable<? super ACTUAL>>customComparator - the comparator to use for incoming assertion checks.customComparatorDescription - comparator description to be used in assertion messagesthis assertion object.public SELF usingDefaultComparator()
AbstractAssert
This method should be used to disable a custom comparison strategy set by calling
Assert.usingComparator(Comparator).
usingDefaultComparator in interface Assert<SELF extends AbstractComparableAssert<SELF,ACTUAL>,ACTUAL extends Comparable<? super ACTUAL>>usingDefaultComparator in class AbstractAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>,ACTUAL extends Comparable<? super ACTUAL>>this assertion object.public SELF inHexadecimal()
AbstractAssertIt 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']">inHexadecimal in class AbstractAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>,ACTUAL extends Comparable<? super ACTUAL>>this assertion object.public SELF inBinary()
AbstractAssertExample:
assertThat(1).inBinary().isEqualTo(2);
org.junit.ComparisonFailure:
Expected :0b00000000_00000000_00000000_00000010
Actual :0b00000000_00000000_00000000_00000001inBinary in class AbstractAssert<SELF extends AbstractComparableAssert<SELF,ACTUAL>,ACTUAL extends Comparable<? super ACTUAL>>this assertion object.Copyright © 2013–2018 AssertJ. All rights reserved.