S
- the "self" type of this assertion class. Please read "Emulating
'self types' using Java Generics to simplify fluent API implementation" for more details.A
- the type of the "actual" value.public abstract class AbstractComparableAssert<S extends AbstractComparableAssert<S,A>,A extends Comparable<? super A>> extends AbstractObjectAssert<S,A> implements ComparableAssert<S,A>
ComparableAssert
.actual, info, myself
Modifier | Constructor and Description |
---|---|
protected |
AbstractComparableAssert(A actual,
Class<?> selfType) |
Modifier and Type | Method and Description |
---|---|
S |
inBinary()
Use binary object representation instead of standard representation in error messages.
|
S |
inHexadecimal()
Use hexadecimal object representation instead of standard representation in error messages.
|
S |
isEqualByComparingTo(A other)
Verifies that the actual value is equal to the given one by invoking
. |
S |
isGreaterThan(A other)
Verifies that the actual value is greater than the given one.
|
S |
isGreaterThanOrEqualTo(A other)
Verifies that the actual value is greater than or equal to the given one.
|
S |
isLessThan(A other)
Verifies that the actual value is less than the given one.
|
S |
isLessThanOrEqualTo(A other)
Verifies that the actual value is less than or equal to the given one.
|
S |
isNotEqualByComparingTo(A other)
Verifies that the actual value is not equal to the given one by invoking
. |
S |
usingComparator(Comparator<? super A> customComparator)
Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
|
S |
usingDefaultComparator()
Revert to standard comparison for incoming assertion checks.
|
extracting, extracting, hasFieldOrProperty, hasFieldOrPropertyWithValue, isEqualToComparingFieldByField, isEqualToComparingOnlyGivenFields, isEqualToIgnoringGivenFields, isEqualToIgnoringNullFields
as, as, asList, asString, describedAs, describedAs, descriptionText, doesNotHave, doesNotHaveSameClassAs, equals, failWithMessage, getWritableAssertionInfo, has, hashCode, hasSameClassAs, hasToString, is, isEqualTo, isExactlyInstanceOf, isIn, isIn, isInstanceOf, isInstanceOfAny, isNot, isNotEqualTo, isNotExactlyInstanceOf, isNotIn, isNotIn, isNotInstanceOf, isNotInstanceOfAny, isNotNull, isNotOfAnyClassIn, isNotSameAs, isNull, isOfAnyClassIn, isSameAs, matches, matches, overridingErrorMessage, throwAssertionError, withFailMessage, withThreadDumpOnError
public S isEqualByComparingTo(A 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<S extends AbstractComparableAssert<S,A>,A extends Comparable<? super A>>
other
- the given value to compare the actual value to.this
assertion object.public S isNotEqualByComparingTo(A 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<S extends AbstractComparableAssert<S,A>,A extends Comparable<? super A>>
other
- the given value to compare the actual value to.this
assertion object.public S isLessThan(A other)
isLessThan
in interface ComparableAssert<S extends AbstractComparableAssert<S,A>,A extends Comparable<? super A>>
other
- the given value to compare the actual value to.this
assertion object.public S isLessThanOrEqualTo(A other)
isLessThanOrEqualTo
in interface ComparableAssert<S extends AbstractComparableAssert<S,A>,A extends Comparable<? super A>>
other
- the given value to compare the actual value to.this
assertion object.public S isGreaterThan(A other)
isGreaterThan
in interface ComparableAssert<S extends AbstractComparableAssert<S,A>,A extends Comparable<? super A>>
other
- the given value to compare the actual value to.this
assertion object.public S isGreaterThanOrEqualTo(A other)
isGreaterThanOrEqualTo
in interface ComparableAssert<S extends AbstractComparableAssert<S,A>,A extends Comparable<? super A>>
other
- the given value to compare the actual value to.this
assertion object.public S usingComparator(Comparator<? super A> customComparator)
AbstractAssert
Custom 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<S extends AbstractComparableAssert<S,A>,A extends Comparable<? super A>>
usingComparator
in class AbstractAssert<S extends AbstractComparableAssert<S,A>,A extends Comparable<? super A>>
customComparator
- the comparator to use for incoming assertion checks.this
assertion object.public S usingDefaultComparator()
AbstractAssert
This method should be used to disable a custom comparison strategy set by calling
Assert.usingComparator(Comparator)
.
usingDefaultComparator
in interface Assert<S extends AbstractComparableAssert<S,A>,A extends Comparable<? super A>>
usingDefaultComparator
in class AbstractAssert<S extends AbstractComparableAssert<S,A>,A extends Comparable<? super A>>
this
assertion object.public S inHexadecimal()
AbstractAssert
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<S extends AbstractComparableAssert<S,A>,A extends Comparable<? super A>>
this
assertion object.public S inBinary()
AbstractAssert
assertThat(1).inBinary().isEqualTo(2);
org.junit.ComparisonFailure:
Expected :0b00000000_00000000_00000000_00000010
Actual :0b00000000_00000000_00000000_00000001
inBinary
in class AbstractAssert<S extends AbstractComparableAssert<S,A>,A extends Comparable<? super A>>
this
assertion object.Copyright © 2014-2016 AssertJ. All Rights Reserved.