|
13 | 13 | package org.assertj.core.api.optionaldouble; |
14 | 14 |
|
15 | 15 | import static org.assertj.core.api.Assertions.assertThat; |
16 | | -import static org.assertj.core.api.Assertions.catchThrowable; |
17 | 16 | import static org.assertj.core.api.Assertions.catchThrowableOfType; |
| 17 | +import static org.assertj.core.api.BDDAssertions.then; |
18 | 18 | import static org.assertj.core.error.OptionalShouldContain.shouldContain; |
19 | | -import static org.assertj.core.util.AssertionsUtil.assertThatAssertionErrorIsThrownBy; |
| 19 | +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; |
20 | 20 | import static org.assertj.core.util.FailureMessages.actualIsNull; |
21 | 21 |
|
22 | 22 | import java.util.OptionalDouble; |
23 | 23 |
|
24 | 24 | import org.junit.jupiter.api.Test; |
| 25 | +import org.junit.jupiter.params.ParameterizedTest; |
| 26 | +import org.junit.jupiter.params.provider.ValueSource; |
25 | 27 | import org.opentest4j.AssertionFailedError; |
26 | 28 |
|
27 | 29 | class OptionalDoubleAssert_hasValue_Test { |
28 | 30 |
|
| 31 | + @ParameterizedTest |
| 32 | + @ValueSource(doubles = { 10.0, -10.0, 0.0, -0.0, Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY }) |
| 33 | + void should_pass_if_optionalDouble_has_the_expected_value(double value) { |
| 34 | + assertThat(OptionalDouble.of(value)).hasValue(value); |
| 35 | + } |
| 36 | + |
| 37 | + @Test |
| 38 | + void should_pass_if_optionalDouble_has_the_expected_value_as_Double() { |
| 39 | + assertThat(OptionalDouble.of(10.0)).hasValue(Double.valueOf(10.0)); |
| 40 | + } |
| 41 | + |
29 | 42 | @Test |
30 | 43 | void should_fail_when_optionalDouble_is_null() { |
31 | 44 | // GIVEN |
32 | 45 | OptionalDouble nullActual = null; |
| 46 | + // WHEN |
| 47 | + AssertionError assertionError = expectAssertionError(() -> assertThat(nullActual).hasValue(10.0)); |
33 | 48 | // THEN |
34 | | - assertThatAssertionErrorIsThrownBy(() -> assertThat(nullActual).hasValue(10.0)).withMessage(actualIsNull()); |
35 | | - } |
36 | | - |
37 | | - @Test |
38 | | - void should_pass_if_optionalDouble_has_expected_value() { |
39 | | - assertThat(OptionalDouble.of(10.0)).hasValue(10.0); |
| 49 | + then(assertionError).hasMessage(actualIsNull()); |
40 | 50 | } |
41 | 51 |
|
42 | 52 | @Test |
43 | | - void should_fail_if_optionalDouble_does_not_have_expected_value() { |
| 53 | + void should_fail_if_optionalDouble_does_not_have_the_expected_value() { |
44 | 54 | // GIVEN |
45 | 55 | OptionalDouble actual = OptionalDouble.of(5.0); |
46 | 56 | double expectedValue = 10.0; |
47 | 57 | // WHEN |
48 | 58 | AssertionFailedError error = catchThrowableOfType(() -> assertThat(actual).hasValue(expectedValue), |
49 | 59 | AssertionFailedError.class); |
50 | 60 | // THEN |
51 | | - assertThat(error).hasMessage(shouldContain(actual, expectedValue).create()); |
52 | | - assertThat(error.getActual().getStringRepresentation()).isEqualTo(String.valueOf(actual.getAsDouble())); |
53 | | - assertThat(error.getExpected().getStringRepresentation()).isEqualTo(String.valueOf(expectedValue)); |
| 61 | + then(error).hasMessage(shouldContain(actual, expectedValue).create()); |
| 62 | + then(error.getActual().getStringRepresentation()).isEqualTo(String.valueOf(actual.getAsDouble())); |
| 63 | + then(error.getExpected().getStringRepresentation()).isEqualTo(String.valueOf(expectedValue)); |
54 | 64 | } |
55 | 65 |
|
56 | 66 | @Test |
57 | 67 | void should_fail_if_optionalDouble_is_empty() { |
58 | 68 | // GIVEN |
59 | 69 | double expectedValue = 10.0; |
60 | 70 | // WHEN |
61 | | - Throwable error = catchThrowable(() -> assertThat(OptionalDouble.empty()).hasValue(expectedValue)); |
| 71 | + AssertionError error = expectAssertionError(() -> assertThat(OptionalDouble.empty()).hasValue(expectedValue)); |
62 | 72 | // THEN |
63 | | - assertThat(error).hasMessage(shouldContain(expectedValue).create()); |
| 73 | + then(error).hasMessage(shouldContain(expectedValue).create()); |
64 | 74 | } |
65 | 75 | } |
0 commit comments