Document AssertJ's satisfies with extractingJsonPathNumberValue

Closes gh-16229
pull/16287/head
Madhura Bhave 6 years ago
parent c8ec621125
commit 4a230fdec9

@ -6983,6 +6983,19 @@ NOTE: JSON helper classes can also be used directly in standard unit tests. To d
call the `initFields` method of the helper in your `@Before` method if you do not use call the `initFields` method of the helper in your `@Before` method if you do not use
`@JsonTest`. `@JsonTest`.
If you're using Spring Boot's AssertJ-based helpers to assert on a number value
at a given JSON path, you might not be able to use `isEqualTo` depending on the type.
Instead, you can use AssertJ's `satisfies` to assert that the value matches the given
condition. For instance, the following example asserts that the actual number is a float
value close to `0.15` within an offset of `0.01`.
[source,java,indent=0]
----
assertThat(json.write(message))
.extractingJsonPathNumberValue("@.test.numberValue")
.satisfies((number) -> assertThat(number.floatValue()).isCloseTo(0.15f, within(0.01f)));
----
[[boot-features-testing-spring-boot-applications-testing-autoconfigured-mvc-tests]] [[boot-features-testing-spring-boot-applications-testing-autoconfigured-mvc-tests]]

Loading…
Cancel
Save