From e077a753f8ec528979eb47c4d3ce41b88437723d Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sat, 5 Feb 2022 20:37:42 +0100 Subject: [PATCH] Polish JsonContentTests --- .../server/samples/JsonContentTests.java | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/JsonContentTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/JsonContentTests.java index e6a4ed7799..31d8efd369 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/JsonContentTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/JsonContentTests.java @@ -52,10 +52,13 @@ class JsonContentTests { .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().isOk() - .expectBody().json( - "[{\"firstName\":\"Jane\"}," + - "{\"firstName\":\"Jason\"}," + - "{\"firstName\":\"John\"}]"); + .expectBody().json(""" + [ + {"firstName":"Jane"}, + {"firstName":"Jason"}, + {"firstName":"John"} + ] + """); } @Test @@ -64,10 +67,13 @@ class JsonContentTests { .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().isOk() - .expectBody().json( - "[{\"firstName\":\"Jane\",\"lastName\":\"Williams\"}," + - "{\"firstName\":\"Jason\",\"lastName\":\"Johnson\"}," + - "{\"firstName\":\"John\",\"lastName\":\"Smith\"}]", + .expectBody().json(""" + [ + {"firstName":"Jane", "lastName":"Williams"}, + {"firstName":"Jason","lastName":"Johnson"}, + {"firstName":"John", "lastName":"Smith"} + ] + """, true); } @@ -76,10 +82,13 @@ class JsonContentTests { assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> this.client.get().uri("/persons") .accept(MediaType.APPLICATION_JSON) .exchange() - .expectBody().json( - "[{\"firstName\":\"Jane\"}," + - "{\"firstName\":\"Jason\"}," + - "{\"firstName\":\"John\"}]", + .expectBody().json(""" + [ + {"firstName":"Jane"}, + {"firstName":"Jason"}, + {"firstName":"John"} + ] + """, true) ); } @@ -110,7 +119,9 @@ class JsonContentTests { void postJsonContent() { this.client.post().uri("/persons") .contentType(MediaType.APPLICATION_JSON) - .bodyValue("{\"firstName\":\"John\",\"lastName\":\"Smith\"}") + .bodyValue(""" + {"firstName":"John", "lastName":"Smith"} + """) .exchange() .expectStatus().isCreated() .expectBody().isEmpty();