Top Description Methods
org.assertj.core.api

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

extends NumberAssert<SELF extends FloatingPointNumberAssert<SELF, ACTUAL>, ACTUAL extends Number>
Known Direct Implementers
org.assertj.core.api.AbstractFloatAssert, org.assertj.core.api.AbstractDoubleAssert
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

Assertion methods applicable to floating-point Numbers.
Authors
Alex Ruiz, Yvonne Wang, Mikhail Mazursky

Method Summary

Modifier and TypeMethod and Description
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
)

Redeclares org.assertj.core.api.NumberAssert.isCloseTo.

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

Returns:

this assertion object.
isEqualTo
(ACTUAL
the given value 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 value.

public SELF
public SELF
public SELF

Returns:

this assertion object.
isNaN
()

Verifies that the actual value is equal to NaN.

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
)

Redeclares org.assertj.core.api.NumberAssert.isNotCloseTo.

Verifies that the actual number is not close to the given one by less than the given offset.
public SELF
public SELF
public SELF

Returns:

this assertion object.
isNotNaN
()

Verifies that the actual value is not equal to NaN.

Inherited from org.assertj.core.api.NumberAssert:
isBetweenisCloseToisNegativeisNotCloseToisNotNegativeisNotPositiveisNotZeroisOneisPositiveisStrictlyBetweenisZero

Method Detail

isCloseToback to summary
public SELF isCloseTo(ACTUAL expected, Offset<ACTUAL> offset)

Redeclares org.assertj.core.api.NumberAssert.isCloseTo.

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 succeed:
assertThat(8.1).isCloseTo(new Double(8.0), within(0.2));

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

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

// assertion will fail
assertThat(8.1).isCloseTo(new Double(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.

Annotations
@Override
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.
isEqualToback to summary
public SELF isEqualTo(ACTUAL expected, Offset<ACTUAL> offset)

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

This assertion is the same as isCloseTo(Number, Offset).

When abs(actual - expected) == offset value, the assertion:

Examples:

 // assertions succeed
assertThat(8.1).isEqualTo(8.0, within(0.2));
assertThat(8.1).isEqualTo(8.0, offset(0.2)); // alias of within
assertThat(8.1).isEqualTo(8.0, byLessThan(0.2)); // strict

// assertions succeed when the difference == offset value ...
assertThat(8.1).isEqualTo(8.0, within(0.1));
assertThat(8.1).isEqualTo(8.0, offset(0.1));
// ... except when using byLessThan which is strict
assertThat(8.1).isEqualTo(8.0, byLessThan(0.1)); // strict => fail

// this assertions also fails
assertThat(8.1).isEqualTo(8.0, within(0.001));
Parameters
expected:ACTUAL

the given value 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 equal to the given one.
isFiniteback to summary
public SELF isFinite()
isInfiniteback to summary
public SELF isInfinite()
isNaNback to summary
public SELF isNaN()

Verifies that the actual value is equal to NaN.

Example:

 // assertions succeed
assertThat(Double.NaN).isNaN();
assertThat(0.0 / 0.0).isNaN();
assertThat(0.0F * Float.POSITIVE_INFINITY).isNaN();

// assertions fail
assertThat(1.0).isNaN();
assertThat(-1.0F).isNaN();
Returns:SELF

this assertion object.

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

Redeclares org.assertj.core.api.NumberAssert.isNotCloseTo.

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

Example with double:

 // assertions succeed:
assertThat(8.3).isNotCloseTo(new Double(8.0), byLessThan(0.2));

// you can use offset if you prefer
assertThat(8.3).isNotCloseTo(new Double(8.0), offset(0.2));

// assertions fail
assertThat(8.1).isNotCloseTo(new Double(8.0), byLessThan(0.1));
assertThat(8.1).isNotCloseTo(new Double(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.

Annotations
@Override
Exceptions
NullPointerException:
  • if the given offset is null.
  • if the expected number is null.
AssertionError:
if the actual value is equal to the given one.
Since
2.6.0 / 3.6.0
See Also
Assertions#byLessThan(Double)
isNotFiniteback to summary
public SELF isNotFinite()
isNotInfiniteback to summary
public SELF isNotInfinite()
isNotNaNback to summary
public SELF isNotNaN()

Verifies that the actual value is not equal to NaN.

Example:

 // assertions succeed
assertThat(1.0).isNotNaN();
assertThat(-1.0F).isNotNaN();

// assertions fail
assertThat(Double.NaN).isNotNaN();
assertThat(0.0 / 0.0).isNotNaN();
assertThat(0.0F * Float.POSITIVE_INFINITY).isNotNaN();
Returns:SELF

this assertion object.

Exceptions
AssertionError:
if the actual value is equal to NaN.