Top Description Methods
org.assertj.core.api

public Interface ComparableAssert<SELF extends ComparableAssert<SELF, ACTUAL>, ACTUAL extends Comparable<? super ACTUAL>>

Known Direct Implementers
org.assertj.core.api.AbstractLongAdderAssert, org.assertj.core.api.AbstractComparableAssert
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.math.BigDecimal

Assertion methods applicable to Comparables.
Authors
Alex Ruiz, Ted M. Young, Mikhail Mazursky

Method Summary

Modifier and TypeMethod and Description
public SELF

Returns:

this assertion object.
isBetween
(ACTUAL
the start value (inclusive), expected not to be null.
startInclusive
,
ACTUAL
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.
isEqualByComparingTo
(ACTUAL
the given value to compare the actual value to.
other
)

Verifies that the actual value is equal to the given one by invoking Comparable#compareTo(Object).

public SELF

Returns:

this assertion object.
isGreaterThan
(ACTUAL
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.
isGreaterThanOrEqualTo
(ACTUAL
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.
isLessThan
(ACTUAL
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.
isLessThanOrEqualTo
(ACTUAL
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.
isNotEqualByComparingTo
(ACTUAL
the given value to compare the actual value to.
other
)

Verifies that the actual value is not equal to the given one by invoking Comparable#compareTo(Object).

public SELF

Returns:

this assertion object.
isStrictlyBetween
(ACTUAL
the start value (exclusive), expected not to be null.
startExclusive
,
ACTUAL
the end value (exclusive), expected not to be null.
endExclusive
)

Verifies that the actual value is in ]start, end[ range (start excluded, end excluded).

Method Detail

isBetweenback to summary
public SELF isBetween(ACTUAL startInclusive, ACTUAL endInclusive)

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.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is not in [start, end] range.
NullPointerException:
  • if start value is null.
  • if end value is null.
Since
2.5.0 / 3.5.0
isEqualByComparingToback to summary
public SELF isEqualByComparingTo(ACTUAL other)

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.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is not equal when comparing to the given one.
isGreaterThanback to summary
public SELF isGreaterThan(ACTUAL other)

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.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is equal to or less than the given one.
isGreaterThanOrEqualToback to summary
public SELF isGreaterThanOrEqualTo(ACTUAL other)

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.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is less than the given one.
isLessThanback to summary
public SELF isLessThan(ACTUAL other)

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.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is equal to or greater than the given one.
isLessThanOrEqualToback to summary
public SELF isLessThanOrEqualTo(ACTUAL other)

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.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is greater than the given one.
isNotEqualByComparingToback to summary
public SELF isNotEqualByComparingTo(ACTUAL other)

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.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is equal when comparing to the given one.
isStrictlyBetweenback to summary
public SELF isStrictlyBetween(ACTUAL startExclusive, ACTUAL endExclusive)

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.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is not in ]start, end[ range.
NullPointerException:
  • if start value is null.
  • if end value is null.
Since
2.5.0 / 3.5.0