Top Description Methods
org.assertj.core.api

public Interface NumberAssert<SELF extends NumberAssert<SELF, ACTUAL>, ACTUAL extends Number>

Known Direct Subinterfaces
org.assertj.core.api.FloatingPointNumberAssert
Known Direct Implementers
org.assertj.core.api.AbstractLongAssert, org.assertj.core.api.AbstractShortAssert, org.assertj.core.api.AbstractIntegerAssert, org.assertj.core.api.AbstractLongAdderAssert, org.assertj.core.api.AbstractBigDecimalAssert, org.assertj.core.api.AbstractBigIntegerAssert, org.assertj.core.api.AbstractByteAssert
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
org.assertj.core.data.Offset, .Percentage

Assertion methods applicable to Numbers.
Authors
Drummond Dawson, Alex Ruiz, Nicolas François, 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.
start
,
ACTUAL
the end value (inclusive), expected not to be null.
end
)

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

public SELF

Returns:

this assertion object.
isCloseTo
(ACTUAL
the given number to compare the actual value to.
expected
,
Offset<ACTUAL>
the given positive offset.
offset
)

Verifies that the actual number is close to the given one within the given offset.

public SELF

Returns:

this assertion object.
isCloseTo
(ACTUAL
the given number to compare the actual value to.
expected
,
Percentage
the given positive percentage.
percentage
)

Verifies that the actual number is close to the given one within the given percentage.

public SELF

Returns:

this assertion object.
isNegative
()

Verifies that the actual value is negative.

public SELF

Returns:

this assertion object.
isNotCloseTo
(ACTUAL
the given number to compare the actual value to.
expected
,
Offset<ACTUAL>
the given positive offset.
offset
)

Verifies that the actual number is not close to the given one within the given offset.

public SELF

Returns:

this assertion object.
isNotCloseTo
(ACTUAL
the given number to compare the actual value to.
expected
,
Percentage
the given positive percentage.
percentage
)

Verifies that the actual number is not close to the given one within the given percentage.

public SELF

Returns:

this assertion object.
isNotNegative
()

Verifies that the actual value is non negative (positive or equal zero).

public SELF

Returns:

this assertion object.
isNotPositive
()

Verifies that the actual value is non positive (negative or equal zero).

public SELF

Returns:

this assertion object.
isNotZero
()

Verifies that the actual value is not equal to zero.

public SELF

Returns:

this assertion object.
isOne
()

Verifies that the actual value is equal to one.

public SELF

Returns:

this assertion object.
isPositive
()

Verifies that the actual value is positive.

public SELF

Returns:

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

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

public SELF

Returns:

this assertion object.
isZero
()

Verifies that the actual value is equal to zero.

Method Detail

isBetweenback to summary
public SELF isBetween(ACTUAL start, ACTUAL end)

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

Example:

 // these assertions succeed ...
assertThat(12).isBetween(10, 14);
assertThat(12).isBetween(12, 14);
assertThat(12).isBetween(10, 12);

// ... but this one fails
assertThat(12).isBetween(14, 16);
Parameters
start:ACTUAL

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

end: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.
isCloseToback to summary
public SELF isCloseTo(ACTUAL expected, Offset<ACTUAL> offset)

Verifies that the actual number is close to the given one within the given offset.
If difference is equal to offset value, assertion is considered valid.

Example with double:

 // assertions will pass:
assertThat(8.1).isCloseTo(8.0, within(0.2));

// you can use offset if you prefer
assertThat(8.1).isCloseTo(8.0, offset(0.2));

// if difference is exactly equals to the offset (0.1), it's ok
assertThat(8.1).isCloseTo(8.0, within(0.1));

// assertion will fail
assertThat(8.1).isCloseTo(8.0, within(0.01));
Parameters
expected:ACTUAL

the given number to compare the actual value to.

offset:Offset<ACTUAL>

the given positive offset.

Returns:SELF

this assertion object.

Exceptions
NullPointerException:
  • if the given offset is null.
  • if the expected number is null.
AssertionError:
if the actual value is not close to the given one.
isCloseToback to summary
public SELF isCloseTo(ACTUAL expected, Percentage percentage)

Verifies that the actual number is close to the given one within the given percentage.
If difference is equal to the percentage value, assertion is considered valid.

Example with double:

 // assertions will pass:
assertThat(11.0).isCloseTo(10.0, withinPercentage(20));

// if difference is exactly equals to the computed offset (1.0), it's ok
assertThat(11.0).isCloseTo(10.0, withinPercentage(10));

// assertion will fail
assertThat(11.0).isCloseTo(10.0, withinPercentage(5));
Parameters
expected:ACTUAL

the given number to compare the actual value to.

percentage:Percentage

the given positive percentage.

Returns:SELF

this assertion object.

Exceptions
NullPointerException:
  • if the given offset is null.
  • if the expected number is null.
AssertionError:
if the actual value is close to the given one.
isNegativeback to summary
public SELF isNegative()

Verifies that the actual value is negative.

Example:

 // assertions will pass
assertThat(-42).isNegative();
assertThat(-3.124).isNegative();

// assertions will fail
assertThat(0).isNegative();
assertThat(42).isNegative();
Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is not negative.
isNotCloseToback to summary
public SELF isNotCloseTo(ACTUAL expected, Offset<ACTUAL> offset)

Verifies that the actual number is not close to the given one within the given offset.
If the difference is equal to the offset value, the assertion fails.

Example with double:

 // assertions will pass:
assertThat(8.1).isNotCloseTo(8.0, byLessThan(0.01));

// you can use offset if you prefer
assertThat(8.1).isNotCloseTo(8.0, offset(0.01));

// assertions will fail
assertThat(8.1).isNotCloseTo(8.0, byLessThan(0.1));
assertThat(8.1).isNotCloseTo(8.0, byLessThan(0.2));
Parameters
expected:ACTUAL

the given number to compare the actual value to.

offset:Offset<ACTUAL>

the given positive offset.

Returns:SELF

this assertion object.

Exceptions
NullPointerException:
  • if the given offset is null.
  • if the expected number is null.
AssertionError:
if the actual value is close to the given one.
Since
2.6.0 / 3.6.0
isNotCloseToback to summary
public SELF isNotCloseTo(ACTUAL expected, Percentage percentage)

Verifies that the actual number is not close to the given one within the given percentage.
If difference is equal to the percentage value, the assertion fails.

Example with double:

 // assertions will pass:
assertThat(11.0).isNotCloseTo(10.0, withinPercentage(5));

// assertions will fail
assertThat(11.0).isNotCloseTo(10.0, withinPercentage(10));
assertThat(11.0).isNotCloseTo(10.0, withinPercentage(20));
Parameters
expected:ACTUAL

the given number to compare the actual value to.

percentage:Percentage

the given positive percentage.

Returns:SELF

this assertion object.

Exceptions
NullPointerException:
  • if the given offset is null.
  • if the expected number is null.
AssertionError:
if the actual value is not close to the given one.
Since
2.6.0 / 3.6.0
isNotNegativeback to summary
public SELF isNotNegative()

Verifies that the actual value is non negative (positive or equal zero).

Example:

 // assertions will pass
assertThat(42).isNotNegative();
assertThat(0).isNotNegative();

// assertions will fail
assertThat(-42).isNotNegative();
assertThat(-3.124).isNotNegative();
Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is not non negative.
isNotPositiveback to summary
public SELF isNotPositive()

Verifies that the actual value is non positive (negative or equal zero).

Example:

 // assertions will pass
assertThat(-42).isNotPositive();
assertThat(0).isNotPositive();

// assertions will fail
assertThat(42).isNotPositive();
assertThat(3.124).isNotPositive();
Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is not non positive.
isNotZeroback to summary
public SELF isNotZero()

Verifies that the actual value is not equal to zero.

Example:

 // assertions will pass
assertThat(42).isNotZero();
assertThat(3.142).isNotZero();

// assertions will fail
assertThat(0).isNotZero();
assertThat(0.0).isNotZero();
Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is equal to zero.
isOneback to summary
public SELF isOne()

Verifies that the actual value is equal to one.

Example:

 // assertions will pass
assertThat(1).isOne();
assertThat(1.0).isOne();

// assertions will fail
assertThat(42).isOne();
assertThat(3.142).isOne();
Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is not equal to one.
Since
2.7.0 / 3.7.0
isPositiveback to summary
public SELF isPositive()

Verifies that the actual value is positive.

Example:

 // assertions will pass
assertThat(42).isPositive();
assertThat(3.142).isPositive();

// assertions will fail
assertThat(0).isPositive();
assertThat(-42).isPositive();
Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is not positive.
isStrictlyBetweenback to summary
public SELF isStrictlyBetween(ACTUAL start, ACTUAL end)

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

Example:

 // this assertion succeeds ...
assertThat(12).isStrictlyBetween(10, 14);

// ... but these ones fail
assertThat(12).isStrictlyBetween(12, 14);
assertThat(12).isStrictlyBetween(10, 12);
assertThat(12).isStrictlyBetween(16, 18);
Parameters
start:ACTUAL

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

end: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.
isZeroback to summary
public SELF isZero()

Verifies that the actual value is equal to zero.

Example:

 // assertions will pass
assertThat(0).isZero();
assertThat(0.0).isZero();

// assertions will fail
assertThat(42).isZero();
assertThat(3.142).isZero();
Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if the actual value is null.
  • if the actual value is not equal to zero.