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

public abstract Class AbstractOptionalDoubleAssert<SELF extends AbstractOptionalDoubleAssert<SELF>>

extends AbstractAssert<SELF extends AbstractOptionalDoubleAssert<SELF>, OptionalDouble>
Class Inheritance
Known Direct Subclasses
org.assertj.core.api.OptionalDoubleAssert
Static Imports
java.lang.Math.abs, org.assertj.core.error.OptionalDoubleShouldHaveValueCloseToOffset.shouldHaveValueCloseToOffset, .OptionalDoubleShouldHaveValueCloseToPercentage.shouldHaveValueCloseToPercentage, .OptionalShouldBeEmpty.shouldBeEmpty, .OptionalShouldBePresent.shouldBePresent, .OptionalShouldContain.shouldContain

Assertions for java.util.OptionalDouble.
Authors
Jean-Christophe Gay, Alexander Bischof, Grzegorz Piwowarek

Field Summary

Modifier and TypeField and Description
pack-priv Doubles
Inherited from org.assertj.core.api.AbstractAssert:
actualassertionErrorCreatorconditionscustomRepresentationinfomyselfobjectsprintAssertionsDescriptionthrowUnsupportedExceptionOnEquals

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public SELF

Returns:

this assertion object.
hasValue
(double
the expected value inside the java.util.OptionalDouble.
expectedValue
)

Verifies that the actual java.util.OptionalDouble has the value in argument.

public SELF

Returns:

this assertion object.
hasValueCloseTo
(Double
the expected value inside the java.util.OptionalDouble.
expectedValue
,
Offset<Double>
the given positive offset.
offset
)

Verifies that the actual java.util.OptionalDouble has the value close to the argument.

public SELF

Returns:

the assertion object
hasValueCloseTo
(Double
the expected value inside the java.util.OptionalDouble
expectedValue
,
Percentage
the given positive percentage
percentage
)

Verifies that the actual java.util.OptionalDouble has a value close to the expected value, within the given percentage.

public SELF

Returns:

this assertion object.
isEmpty
()

Verifies that the actual java.util.OptionalDouble is empty.

public SELF

Returns:

this assertion object.
isNotEmpty
()

Verifies that there is a value present in the actual java.util.OptionalDouble, it's an alias of isPresent().

public SELF

Returns:

this assertion object.
isNotPresent
()

Verifies that the actual java.util.Optional is empty (alias of isEmpty()).

public SELF

Returns:

this assertion object.
isPresent
()

Verifies that there is a value present in the actual java.util.OptionalDouble.

Inherited from org.assertj.core.api.AbstractAssert:
areEqualasInstanceOfasListassertionErrorasStringdescribedAsdescriptionTextdoesNotHavedoesNotHaveSameClassAsdoesNotHaveSameHashCodeAsdoesNotHaveToStringdoesNotHaveToStringequalsextractingextractingfailurefailureWithActualExpectedfailWithActualExpectedAndMessagefailWithMessagegetWritableAssertionInfohashashCodehasSameClassAshasSameHashCodeAshasToStringhasToStringinBinaryinHexadecimalisisElementOfCustomAssertisEqualToisExactlyInstanceOfisInisInisInstanceOfisInstanceOfAnyisInstanceOfSatisfyingisNotisNotEqualToisNotExactlyInstanceOfisNotInisNotInisNotInstanceOfisNotInstanceOfAnyisNotNullisNotOfAnyClassInisNotSameAsisNullisOfAnyClassInisSameAsmatchesmatchesnewListAssertInstanceoverridingErrorMessageoverridingErrorMessagesatisfiessatisfiessatisfiessatisfiesAnyOfsatisfiesAnyOfsatisfiesAnyOfForProxysatisfiesForProxysetCustomRepresentationsetDescriptionConsumersetPrintAssertionsDescriptionthrowAssertionErrorusingComparatorusingComparatorusingDefaultComparatorusingRecursiveAssertionusingRecursiveAssertionusingRecursiveComparisonusingRecursiveComparisonwithAssertionStatewithFailMessagewithFailMessagewithRepresentationwithThreadDumpOnError

Field Detail

doublesback to summary
pack-priv Doubles doubles
Annotations
@VisibleForTesting

Constructor Detail

AbstractOptionalDoubleAssertback to summary
protected AbstractOptionalDoubleAssert(OptionalDouble actual, Class<?> selfType)

Method Detail

hasValueback to summary
public SELF hasValue(double expectedValue)

Verifies that the actual java.util.OptionalDouble has the value in argument. The check is consistent with java.util.OptionalDouble#equals(Object) since 3.26.0.

 // assertions succeed:
assertThat(OptionalDouble.of(8.0)).hasValue(8.0);
assertThat(OptionalDouble.of(8.0)).hasValue(Double.valueOf(8.0));
assertThat(OptionalDouble.of(Double.NaN)).hasValue(Double.NaN);
assertThat(OptionalDouble.of(Double.POSITIVE_INFINITY)).hasValue(Double.POSITIVE_INFINITY);
assertThat(OptionalDouble.of(Double.NEGATIVE_INFINITY)).hasValue(Double.NEGATIVE_INFINITY);

// assertions fail:
assertThat(OptionalDouble.empty()).hasValue(8.0);
assertThat(OptionalDouble.of(7)).hasValue(8.0);
Parameters
expectedValue:double

the expected value inside the java.util.OptionalDouble.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if actual value is empty.
  • if actual is null.
  • if actual does not have the expected value.
hasValueCloseToback to summary
public SELF hasValueCloseTo(Double expectedValue, Offset<Double> offset)

Verifies that the actual java.util.OptionalDouble has the value close to the argument.

Assertion will pass :

 assertThat(OptionalDouble.of(8)).hasValueCloseTo(8.0, within(0d));
assertThat(OptionalDouble.of(8)).hasValueCloseTo(8.0, within(1d));
assertThat(OptionalDouble.of(7)).hasValueCloseTo(8.0, within(1d));

Assertion will fail :

 assertThat(OptionalDouble.empty()).hasValueCloseTo(8.0, within(1d));
assertThat(OptionalDouble.of(7)).hasValueCloseTo(1.0, within(1d));
assertThat(OptionalDouble.of(7)).hasValueCloseTo(1.0, null);
assertThat(OptionalDouble.of(7)).hasValueCloseTo(1.0, within(-1d));
Parameters
expectedValue:Double

the expected value inside the java.util.OptionalDouble.

offset:Offset<Double>

the given positive offset.

Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if actual value is empty.
  • if actual is null.
  • if actual has not the value as expected.
NullPointerException:
if offset is null
IllegalArgumentException:
if offset is not positive.
hasValueCloseToback to summary
public SELF hasValueCloseTo(Double expectedValue, Percentage percentage)

Verifies that the actual java.util.OptionalDouble has a value close to the expected value, within the given percentage.
If the difference is equal to the percentage value, the assertion is considered valid.

// The assertion will pass:
assertThat(OptionalDouble.of(11)).hasValueCloseTo(10.0, withinPercentage(20));

// If the difference is exactly equals to the computed offset (1.0), the assertion will pass:
assertThat(OptionalDouble.of(11)).hasValueCloseTo(10.0, withinPercentage(10));

// The assertions will fail:
assertThat(OptionalDouble.of(11)).hasValueCloseTo(10.0, withinPercentage(5));
assertThat(OptionalDouble.empty()).hasValueCloseTo(10.0, withinPercentage(5));
Parameters
expectedValue:Double

the expected value inside the java.util.OptionalDouble

percentage:Percentage

the given positive percentage

Returns:SELF

the assertion object

Exceptions
AssertionError:
  • if actual value is empty
  • if actual is null
  • if the actual value is not close to the given one
isEmptyback to summary
public SELF isEmpty()

Verifies that the actual java.util.OptionalDouble is empty.

Assertion will pass :

 assertThat(OptionalDouble.empty()).isEmpty();

Assertion will fail :

 assertThat(OptionalDouble.of(10.0)).isEmpty();
Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if actual value is present.
  • if actual is null.
isNotEmptyback to summary
public SELF isNotEmpty()

Verifies that there is a value present in the actual java.util.OptionalDouble, it's an alias of isPresent().

Assertion will pass :

 assertThat(OptionalDouble.of(10.0)).isNotEmpty();

Assertion will fail :

 assertThat(OptionalDouble.empty()).isNotEmpty();
Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if actual value is empty.
  • if actual is null.
isNotPresentback to summary
public SELF isNotPresent()

Verifies that the actual java.util.Optional is empty (alias of isEmpty()).

Assertion will pass :

 assertThat(OptionalDouble.empty()).isNotPresent();
Assertion will fail :
 assertThat(OptionalDouble.of(10.0)).isNotPresent();
Returns:SELF

this assertion object.

isPresentback to summary
public SELF isPresent()

Verifies that there is a value present in the actual java.util.OptionalDouble.

Assertion will pass :

 assertThat(OptionalDouble.of(10.0)).isPresent();

Assertion will fail :

 assertThat(OptionalDouble.empty()).isPresent();
Returns:SELF

this assertion object.

Exceptions
AssertionError:
  • if actual value is empty.
  • if actual is null.