|
21 | 21 | import io.micrometer.observation.ObservationRegistry; |
22 | 22 | import org.junit.jupiter.api.BeforeEach; |
23 | 23 | import org.junit.jupiter.api.Test; |
| 24 | +import org.opentest4j.AssertionFailedError; |
24 | 25 |
|
25 | 26 | import java.util.function.Supplier; |
26 | 27 |
|
27 | 28 | import static io.micrometer.observation.tck.ObservationContextAssert.assertThat; |
| 29 | +import static org.assertj.core.api.BDDAssertions.then; |
28 | 30 | import static org.assertj.core.api.BDDAssertions.thenNoException; |
29 | 31 | import static org.assertj.core.api.BDDAssertions.thenThrownBy; |
30 | 32 | import static org.mockito.Mockito.spy; |
@@ -63,7 +65,11 @@ void should_not_throw_exception_when_name_correct() { |
63 | 65 | void should_throw_exception_when_name_incorrect() { |
64 | 66 | context.setName("foo"); |
65 | 67 |
|
66 | | - thenThrownBy(() -> assertThat(context).hasNameEqualTo("bar")).isInstanceOf(AssertionError.class); |
| 68 | + thenThrownBy(() -> assertThat(context).hasNameEqualTo("bar")).isInstanceOfSatisfying(AssertionFailedError.class, |
| 69 | + error -> { |
| 70 | + then(error.getActual().getStringRepresentation()).isEqualTo("foo"); |
| 71 | + then(error.getExpected().getStringRepresentation()).isEqualTo("bar"); |
| 72 | + }); |
67 | 73 | } |
68 | 74 |
|
69 | 75 | @Test |
@@ -91,7 +97,11 @@ void should_not_throw_exception_when_contextual_name_correct() { |
91 | 97 | void should_throw_exception_when_contextual_name_incorrect() { |
92 | 98 | context.setContextualName("foo"); |
93 | 99 |
|
94 | | - thenThrownBy(() -> assertThat(context).hasContextualNameEqualTo("bar")).isInstanceOf(AssertionError.class); |
| 100 | + thenThrownBy(() -> assertThat(context).hasContextualNameEqualTo("bar")) |
| 101 | + .isInstanceOfSatisfying(AssertionFailedError.class, error -> { |
| 102 | + then(error.getActual().getStringRepresentation()).isEqualTo("foo"); |
| 103 | + then(error.getExpected().getStringRepresentation()).isEqualTo("bar"); |
| 104 | + }); |
95 | 105 | } |
96 | 106 |
|
97 | 107 | @Test |
@@ -120,7 +130,11 @@ void should_not_throw_exception_when_name_ignore_case_correct() { |
120 | 130 | void should_throw_exception_when_name_ignore_case_incorrect() { |
121 | 131 | context.setName("foo"); |
122 | 132 |
|
123 | | - thenThrownBy(() -> assertThat(context).hasNameEqualToIgnoringCase("bar")).isInstanceOf(AssertionError.class); |
| 133 | + thenThrownBy(() -> assertThat(context).hasNameEqualToIgnoringCase("bar")) |
| 134 | + .isInstanceOfSatisfying(AssertionFailedError.class, error -> { |
| 135 | + then(error.getActual().getStringRepresentation()).isEqualTo("foo"); |
| 136 | + then(error.getExpected().getStringRepresentation()).isEqualTo("bar"); |
| 137 | + }); |
124 | 138 | } |
125 | 139 |
|
126 | 140 | @Test |
@@ -150,7 +164,10 @@ void should_throw_exception_when_contextual_name_ignore_case_incorrect() { |
150 | 164 | context.setContextualName("foo"); |
151 | 165 |
|
152 | 166 | thenThrownBy(() -> assertThat(context).hasContextualNameEqualToIgnoringCase("bar")) |
153 | | - .isInstanceOf(AssertionError.class); |
| 167 | + .isInstanceOfSatisfying(AssertionFailedError.class, error -> { |
| 168 | + then(error.getActual().getStringRepresentation()).isEqualTo("foo"); |
| 169 | + then(error.getExpected().getStringRepresentation()).isEqualTo("bar"); |
| 170 | + }); |
154 | 171 | } |
155 | 172 |
|
156 | 173 | @Test |
@@ -248,7 +265,10 @@ void should_throw_exception_when_low_cardinality_key_value_missing() { |
248 | 265 | observation.lowCardinalityKeyValue("foo", "bar"); |
249 | 266 |
|
250 | 267 | thenThrownBy(() -> assertThat(context).hasLowCardinalityKeyValue("foo", "baz")) |
251 | | - .isInstanceOf(AssertionError.class); |
| 268 | + .isInstanceOfSatisfying(AssertionFailedError.class, error -> { |
| 269 | + then(error.getActual().getStringRepresentation()).isEqualTo("bar"); |
| 270 | + then(error.getExpected().getStringRepresentation()).isEqualTo("baz"); |
| 271 | + }); |
252 | 272 | thenThrownBy(() -> assertThat(context).hasLowCardinalityKeyValueWithKey("bar")) |
253 | 273 | .isInstanceOf(AssertionError.class); |
254 | 274 | } |
@@ -284,7 +304,10 @@ void should_throw_exception_when_high_cardinality_key_value_missing() { |
284 | 304 | observation.highCardinalityKeyValue("foo", "bar"); |
285 | 305 |
|
286 | 306 | thenThrownBy(() -> assertThat(context).hasHighCardinalityKeyValue("foo", "baz")) |
287 | | - .isInstanceOf(AssertionError.class); |
| 307 | + .isInstanceOfSatisfying(AssertionFailedError.class, error -> { |
| 308 | + then(error.getActual().getStringRepresentation()).isEqualTo("bar"); |
| 309 | + then(error.getExpected().getStringRepresentation()).isEqualTo("baz"); |
| 310 | + }); |
288 | 311 | thenThrownBy(() -> assertThat(context).hasHighCardinalityKeyValueWithKey("bar")) |
289 | 312 | .isInstanceOf(AssertionError.class); |
290 | 313 | } |
|
0 commit comments