Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delegate OptionalDouble value comparison to Double.compare in hasValue assertion #3411

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public SELF isNotEmpty() {
}

/**
* Verifies that the actual {@link java.util.OptionalDouble} has the value in argument.
* Verifies that the actual {@link java.util.OptionalDouble} has the value in argument. The check is consistent
* with {@link java.util.OptionalDouble#equals(Object)}
* <p>
* Assertion will pass :
* <pre><code class='java'> assertThat(OptionalDouble.of(8.0)).hasValue(8.0);
Expand All @@ -135,7 +136,7 @@ public SELF isNotEmpty() {
public SELF hasValue(double expectedValue) {
isNotNull();
if (!actual.isPresent()) throwAssertionError(shouldContain(expectedValue));
if (expectedValue != actual.getAsDouble())
if (Double.compare(expectedValue, actual.getAsDouble()) != 0)
throw Failures.instance().failure(info, shouldContain(actual, expectedValue), actual.getAsDouble(), expectedValue);
return myself;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ void should_pass_if_optionalDouble_has_expected_value() {
assertThat(OptionalDouble.of(10.0)).hasValue(10.0);
}

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

@Test
void should_pass_if_optionalDouble_has_expected_positive_infinity_value() {
assertThat(OptionalDouble.of(Double.POSITIVE_INFINITY)).hasValue(Double.POSITIVE_INFINITY);
}

@Test
void should_pass_if_optionalDouble_has_expected_negative_infinity_value() {
assertThat(OptionalDouble.of(Double.NEGATIVE_INFINITY)).hasValue(Double.NEGATIVE_INFINITY);
}

@Test
void should_fail_if_optionalDouble_does_not_have_expected_value() {
// GIVEN
Expand Down