From 4a230fdec96809b05fa8878277d3f8692665b9fb Mon Sep 17 00:00:00 2001 From: Madhura Bhave Date: Tue, 19 Mar 2019 17:08:20 -0700 Subject: [PATCH] Document AssertJ's satisfies with extractingJsonPathNumberValue Closes gh-16229 --- .../src/main/asciidoc/spring-boot-features.adoc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index 006a62e1307..dbefe4fd931 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -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 `@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]]