From 94bdd4380f8eb7c078067903e155cc051995d661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Tue, 16 Jan 2024 10:59:43 +0100 Subject: [PATCH] Fix incorrect assertions using json path Closes gh-32040 --- .../client/standalone/ExceptionHandlerTests.java | 12 ++++++------ .../client/standalone/RequestParameterTests.java | 2 +- .../client/standalone/ViewResolutionTests.java | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/ExceptionHandlerTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/ExceptionHandlerTests.java index 06b30d0ab24..5e2f3b1c86b 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/ExceptionHandlerTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/ExceptionHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -110,7 +110,7 @@ class ExceptionHandlerTests { .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().isOk() - .expectBody().jsonPath("$.name", "Yoda"); + .expectBody().jsonPath("$.name").isEqualTo("Yoda"); } @Test @@ -123,7 +123,7 @@ class ExceptionHandlerTests { .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().isOk() - .expectBody().jsonPath("$.error", "local - IllegalArgumentException"); + .expectBody().jsonPath("$.error").isEqualTo("local - IllegalArgumentException"); } @Test @@ -136,7 +136,7 @@ class ExceptionHandlerTests { .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().isOk() - .expectBody().jsonPath("$.error", "global - IllegalArgumentException"); + .expectBody().jsonPath("$.error").isEqualTo("global - IllegalStateException"); } @Test @@ -149,7 +149,7 @@ class ExceptionHandlerTests { .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().isOk() - .expectBody().jsonPath("$.error", "globalPersonController - IllegalStateException"); + .expectBody().jsonPath("$.error").isEqualTo("globalPersonController - IllegalStateException"); } @Test @@ -163,7 +163,7 @@ class ExceptionHandlerTests { .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().isOk() - .expectBody().jsonPath("$.error", "global - NoHandlerFoundException"); + .expectBody().jsonPath("$.error").isEqualTo("global - NoHandlerFoundException"); } } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/RequestParameterTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/RequestParameterTests.java index bb9f0efd408..cc6ed1425d4 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/RequestParameterTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/RequestParameterTests.java @@ -45,7 +45,7 @@ public class RequestParameterTests { .exchange() .expectStatus().isOk() .expectHeader().contentType(MediaType.APPLICATION_JSON) - .expectBody().jsonPath("$.name", "George"); + .expectBody().jsonPath("$.name").isEqualTo("George"); } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/ViewResolutionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/ViewResolutionTests.java index d1d06aa97dc..000c101385b 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/ViewResolutionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/ViewResolutionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -85,7 +85,7 @@ class ViewResolutionTests { .exchange() .expectStatus().isOk() .expectHeader().contentTypeCompatibleWith(MediaType.APPLICATION_JSON) - .expectBody().jsonPath("$.person.name", "Corea"); + .expectBody().jsonPath("$.person.name").isEqualTo("Corea"); } @Test @@ -143,7 +143,7 @@ class ViewResolutionTests { .exchange() .expectStatus().isOk() .expectHeader().contentTypeCompatibleWith(MediaType.APPLICATION_JSON) - .expectBody().jsonPath("$.person.name", "Corea"); + .expectBody().jsonPath("$.person.name").isEqualTo("Corea"); testClient.get().uri("/person/Corea") .accept(MediaType.APPLICATION_XML)