Top Description Fields Constructors Methods
org.assertj.core.api

public abstract Class AbstractComparableAssert<SELF extends AbstractComparableAssert<SELF, ACTUAL>, ACTUAL extends Comparable<? super ACTUAL>>

extends AbstractObjectAssert<SELF extends AbstractComparableAssert<SELF, ACTUAL>, ACTUAL extends Comparable<? super ACTUAL>>
implements ComparableAssert<SELF extends AbstractComparableAssert<SELF, ACTUAL>, ACTUAL extends Comparable<? super ACTUAL>>
Class Inheritance
All Implemented Interfaces
org.assertj.core.api.ComparableAssert
Known Direct Subclasses
org.assertj.core.api.AbstractDoubleAssert, org.assertj.core.api.AbstractDurationAssert, org.assertj.core.api.GenericComparableAssert, org.assertj.core.api.AbstractLongAssert, org.assertj.core.api.AbstractShortAssert, org.assertj.core.api.AbstractPathAssert, org.assertj.core.api.AbstractFloatAssert, org.assertj.core.api.AbstractIntegerAssert, org.assertj.core.api.AbstractUriAssert, org.assertj.core.api.AbstractBigDecimalAssert, org.assertj.core.api.AbstractBigIntegerAssert, org.assertj.core.api.AbstractByteAssert, org.assertj.core.api.AbstractCharacterAssert
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.
Imports
java.util.Comparator, org.assertj.core.internal.Comparables, .ComparatorBasedComparisonStrategy, org.assertj.core.util.CheckReturnValue, .VisibleForTesting

Base class for all implementations of ComparableAssert.
Authors
Alex Ruiz, Mikhail Mazursky

Field Summary

Modifier and TypeField and Description
pack-priv Comparables

Constructor Summary

AccessConstructor and Description
protected
AbstractComparableAssert(ACTUAL actual, Class<?> selfType)

Method Summary

Modifier and TypeMethod and Description
public SELF
inBinary()

Overrides org.assertj.core.api.AbstractAssert.inBinary.

Use binary object representation instead of standard representation in error messages.
public SELF
inHexadecimal()

Overrides org.assertj.core.api.AbstractAssert.inHexadecimal.

Use hexadecimal object representation instead of standard representation in error messages.
public SELF
isBetween(ACTUAL
the start value (inclusive), expected not to be null.
startInclusive
,
ACTUAL
the end value (inclusive), expected not to be null.
endInclusive
)

Implements org.assertj.core.api.ComparableAssert.isBetween.

Verifies that the actual value is in [start, end] range (start included, end included).
public SELF
isEqualByComparingTo(ACTUAL
the given value to compare the actual value to.
other
)

Implements org.assertj.core.api.ComparableAssert.isEqualByComparingTo.

Verifies that the actual value is equal to the given one by invoking Comparable#compareTo(Object).
public SELF
isGreaterThan(ACTUAL
the given value to compare the actual value to.
other
)

Implements org.assertj.core.api.ComparableAssert.isGreaterThan.

Verifies that the actual value is greater than the given one.
public SELF
isGreaterThanOrEqualTo(ACTUAL
the given value to compare the actual value to.
other
)

Implements org.assertj.core.api.ComparableAssert.isGreaterThanOrEqualTo.

Verifies that the actual value is greater than or equal to the given one.
public SELF
isLessThan(ACTUAL
the given value to compare the actual value to.
other
)

Implements org.assertj.core.api.ComparableAssert.isLessThan.

Verifies that the actual value is less than the given one.
public SELF
isLessThanOrEqualTo(ACTUAL
the given value to compare the actual value to.
other
)

Implements org.assertj.core.api.ComparableAssert.isLessThanOrEqualTo.

Verifies that the actual value is less than or equal to the given one.
public SELF
isNotEqualByComparingTo(ACTUAL
the given value to compare the actual value to.
other
)

Implements org.assertj.core.api.ComparableAssert.isNotEqualByComparingTo.

Verifies that the actual value is not equal to the given one by invoking Comparable#compareTo(Object).
public SELF
isStrictlyBetween(ACTUAL
the start value (exclusive), expected not to be null.
startExclusive
,
ACTUAL
the end value (exclusive), expected not to be null.
endExclusive
)

Implements org.assertj.core.api.ComparableAssert.isStrictlyBetween.

Verifies that the actual value is in ]start, end[ range (start excluded, end excluded).
public SELF
usingComparator(Comparator<? super ACTUAL>
the comparator to use for the incoming assertion checks.
customComparator
)

Overrides org.assertj.core.api.AbstractAssert.usingComparator.

Implements org.assertj.core.api.Assert.usingComparator.

Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
public SELF
usingComparator(Comparator<? super ACTUAL>
the comparator to use for the incoming assertion checks.
customComparator
,
String
comparator description to be used in assertion error messages
customComparatorDescription
)

Overrides org.assertj.core.api.AbstractAssert.usingComparator.

Implements org.assertj.core.api.Assert.usingComparator.

Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
public SELF
usingDefaultComparator()

Overrides org.assertj.core.api.AbstractAssert.usingDefaultComparator.

Implements org.assertj.core.api.Assert.usingDefaultComparator.

Revert to standard comparison for the incoming assertion checks.
Inherited from org.assertj.core.api.AbstractObjectAssert:
asasdoesNotReturnextractingextractingextractingextractingextractingextractingextractingForProxygetComparatorsByTypehasAllNullFieldsOrPropertieshasAllNullFieldsOrPropertiesExcepthasFieldOrPropertyhasFieldOrPropertyWithValuehasNoNullFieldsOrPropertieshasNoNullFieldsOrPropertiesExcepthasOnlyFieldsisEqualToComparingFieldByFieldisEqualToComparingFieldByFieldRecursivelyisEqualToComparingOnlyGivenFieldsisEqualToIgnoringGivenFieldsisEqualToIgnoringNullFieldsnewObjectAssertreturnsusingComparatorForFieldsusingComparatorForTypeusingRecursiveAssertionusingRecursiveAssertionusingRecursiveComparisonusingRecursiveComparisonwithAssertionStatewithComparatorByPropertyOrFieldwithTypeComparator

Field Detail

comparablesback to summary
pack-priv Comparables comparables
Annotations
@VisibleForTesting

Constructor Detail

AbstractComparableAssertback to summary
protected AbstractComparableAssert(ACTUAL actual, Class<?> selfType)

Method Detail

inBinaryback to summary
public SELF inBinary()

Overrides org.assertj.core.api.AbstractAssert.inBinary.

Doc from org.assertj.core.api.AbstractAssert.inBinary.

Use 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
Returns:SELF

this assertion object.

Annotations
@Override
@CheckReturnValue
inHexadecimalback to summary
public SELF inHexadecimal()

Overrides org.assertj.core.api.AbstractAssert.inHexadecimal.

Doc from org.assertj.core.api.AbstractAssert.inHexadecimal.

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:

 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']">
Returns:SELF

this assertion object.

Annotations
@Override
@CheckReturnValue
isBetweenback to summary
public SELF isBetween(ACTUAL startInclusive, ACTUAL endInclusive)

Implements org.assertj.core.api.ComparableAssert.isBetween.

Doc from org.assertj.core.api.ComparableAssert.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');
Parameters
startInclusive:ACTUAL

the start value (inclusive), expected not to be null.

endInclusive:ACTUAL

the end value (inclusive), expected not to be null.

Returns:SELF

this assertion object.

Annotations
@Override
isEqualByComparingToback to summary
public SELF isEqualByComparingTo(ACTUAL other)

Implements org.assertj.core.api.ComparableAssert.isEqualByComparingTo.

Doc from org.assertj.core.api.ComparableAssert.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 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));
Parameters
other:ACTUAL

the given value to compare the actual value to.

Returns:SELF

this assertion object.

Annotations
@Override
isGreaterThanback to summary
public SELF isGreaterThan(ACTUAL other)

Implements org.assertj.core.api.ComparableAssert.isGreaterThan.

Doc from org.assertj.core.api.ComparableAssert.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);
Parameters
other:ACTUAL

the given value to compare the actual value to.

Returns:SELF

this assertion object.

Annotations
@Override
isGreaterThanOrEqualToback to summary
public SELF isGreaterThanOrEqualTo(ACTUAL other)

Implements org.assertj.core.api.ComparableAssert.isGreaterThanOrEqualTo.

Doc from org.assertj.core.api.ComparableAssert.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);
Parameters
other:ACTUAL

the given value to compare the actual value to.

Returns:SELF

this assertion object.

Annotations
@Override
isLessThanback to summary
public SELF isLessThan(ACTUAL other)

Implements org.assertj.core.api.ComparableAssert.isLessThan.

Doc from org.assertj.core.api.ComparableAssert.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);
Parameters
other:ACTUAL

the given value to compare the actual value to.

Returns:SELF

this assertion object.

Annotations
@Override
isLessThanOrEqualToback to summary
public SELF isLessThanOrEqualTo(ACTUAL other)

Implements org.assertj.core.api.ComparableAssert.isLessThanOrEqualTo.

Doc from org.assertj.core.api.ComparableAssert.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);
Parameters
other:ACTUAL

the given value to compare the actual value to.

Returns:SELF

this assertion object.

Annotations
@Override
isNotEqualByComparingToback to summary
public SELF isNotEqualByComparingTo(ACTUAL other)

Implements org.assertj.core.api.ComparableAssert.isNotEqualByComparingTo.

Doc from org.assertj.core.api.ComparableAssert.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 using BigDecimal#compareTo(BigDecimal)
assertThat(new BigDecimal("8.0")).isNotEqualByComparingTo(new BigDecimal("8.00"));
Parameters
other:ACTUAL

the given value to compare the actual value to.

Returns:SELF

this assertion object.

Annotations
@Override
isStrictlyBetweenback to summary
public SELF isStrictlyBetween(ACTUAL startExclusive, ACTUAL endExclusive)

Implements org.assertj.core.api.ComparableAssert.isStrictlyBetween.

Doc from org.assertj.core.api.ComparableAssert.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');
Parameters
startExclusive:ACTUAL

the start value (exclusive), expected not to be null.

endExclusive:ACTUAL

the end value (exclusive), expected not to be null.

Returns:SELF

this assertion object.

Annotations
@Override
usingComparatorback to summary
public SELF usingComparator(Comparator<? super ACTUAL> customComparator)

Overrides org.assertj.core.api.AbstractAssert.usingComparator.

Implements org.assertj.core.api.Assert.usingComparator.

Doc from org.assertj.core.api.AbstractAssert.usingComparator.

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 :

 // frodo and sam are instances of Character with Hobbit race (obviously :).
// raceComparator implements Comparator<Character>
assertThat(frodo).usingComparator(raceComparator).isEqualTo(sam);
Parameters
customComparator:Comparator<? super ACTUAL>

Doc from org.assertj.core.api.Assert.usingComparator.

the comparator to use for the incoming assertion checks.

Returns:SELF

Doc from org.assertj.core.api.Assert.usingComparator.

this assertion object.

Annotations
@Override
@CheckReturnValue
usingComparatorback to summary
public SELF usingComparator(Comparator<? super ACTUAL> customComparator, String customComparatorDescription)

Overrides org.assertj.core.api.AbstractAssert.usingComparator.

Implements org.assertj.core.api.Assert.usingComparator.

Doc from org.assertj.core.api.AbstractAssert.usingComparator.

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 :

 // frodo and sam are instances of Character with Hobbit race (obviously :).
// raceComparator implements Comparator<Character>
assertThat(frodo).usingComparator(raceComparator, "Hobbit Race Comparator").isEqualTo(sam);
Parameters
customComparator:Comparator<? super ACTUAL>

Doc from org.assertj.core.api.Assert.usingComparator.

the comparator to use for the incoming assertion checks.

customComparatorDescription:String

Doc from org.assertj.core.api.Assert.usingComparator.

comparator description to be used in assertion error messages

Returns:SELF

Doc from org.assertj.core.api.Assert.usingComparator.

this assertion object.

Annotations
@Override
@CheckReturnValue
usingDefaultComparatorback to summary
public SELF usingDefaultComparator()

Overrides org.assertj.core.api.AbstractAssert.usingDefaultComparator.

Implements org.assertj.core.api.Assert.usingDefaultComparator.

Doc from org.assertj.core.api.AbstractAssert.usingDefaultComparator.

Revert to standard comparison for the incoming assertion checks.

This method should be used to disable a custom comparison strategy set by calling usingComparator.

Returns:SELF

Doc from org.assertj.core.api.Assert.usingDefaultComparator.

this assertion object.

Annotations
@Override
@CheckReturnValue