Skip to content

AbstractOptionalDoubleAssert.hasValue(double) fails with NaN #3401

@Caceresenzo

Description

@Caceresenzo

Describe the bug

The AbstractOptionalDoubleAssert.hasValue(double) javadoc state that NaN values are supported (last line of):

* Assertion will pass :
* <pre><code class='java'> 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); </code></pre>

The nature of NaN values prevents the == operator to works, but there is no hasNaNValue() method or equivalent, and the javadoc clearly state that it should works.

  • assertj core version: 3.24.2
  • java version: 21
  • test framework version: junit 5.10.1
  • os (if relevant): windows

Test case reproducing the bug

@Test
void testNaN() {
	assertThat(OptionalDouble.of(Double.NaN)).hasValue(Double.NaN);
}

Result:

org.opentest4j.AssertionFailedError: 
Expecting actual:
  OptionalDouble[NaN]
to contain:
  NaN
but did not.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions