From 4f8eca13503489bbca5d1021d1405bfa1ce97169 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Nicoll?= Date: Fri, 19 Jan 2024 11:53:35 +0100 Subject: [PATCH] Order methods that take a type as a lambda consistently Closes gh-32062 --- .../reactive/server/JsonPathAssertions.java | 28 ++++++++++++++++--- .../client/standalone/ResponseBodyTests.java | 4 +-- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/JsonPathAssertions.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/JsonPathAssertions.java index c0c2d861fd3..0781f607c0e 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/JsonPathAssertions.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/JsonPathAssertions.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. @@ -148,8 +148,19 @@ public class JsonPathAssertions { /** * Delegates to {@link JsonPathExpectationsHelper#assertValue(String, Matcher, Class)}. - * @since 5.1 + * @since 6.2 */ + public WebTestClient.BodyContentSpec value(Class targetType, Matcher matcher) { + this.pathHelper.assertValue(this.content, matcher, targetType); + return this.bodySpec; + } + + /** + * Delegates to {@link JsonPathExpectationsHelper#assertValue(String, Matcher, Class)}. + * @since 5.1 + * @deprecated in favor of {@link #value(Class, Matcher)} + */ + @Deprecated(since = "6.2", forRemoval = true) public WebTestClient.BodyContentSpec value(Matcher matcher, Class targetType) { this.pathHelper.assertValue(this.content, matcher, targetType); return this.bodySpec; @@ -168,15 +179,24 @@ public class JsonPathAssertions { /** * Consume the result of the JSONPath evaluation and provide a target class. - * @since 5.1 + * @since 6.2 */ @SuppressWarnings("unchecked") - public WebTestClient.BodyContentSpec value(Consumer consumer, Class targetType) { + public WebTestClient.BodyContentSpec value(Class targetType, Consumer consumer) { Object value = this.pathHelper.evaluateJsonPath(this.content, targetType); consumer.accept((T) value); return this.bodySpec; } + /** + * Consume the result of the JSONPath evaluation and provide a target class. + * @since 5.1 + * @deprecated in favor of {@link #value(Class, Consumer)} + */ + @Deprecated(since = "6.2", forRemoval = true) + public WebTestClient.BodyContentSpec value(Consumer consumer, Class targetType) { + return value(targetType, consumer); + } @Override public boolean equals(@Nullable Object obj) { diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/ResponseBodyTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/ResponseBodyTests.java index 691a60e8040..d5de16450df 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/ResponseBodyTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/ResponseBodyTests.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. @@ -48,7 +48,7 @@ class ResponseBodyTests { .jsonPath("$.name").isEqualTo("Lee") .jsonPath("$.age").isEqualTo(42) .jsonPath("$.age").value(equalTo(42)) - .jsonPath("$.age").value(equalTo(42.0f), Float.class); + .jsonPath("$.age").value(Float.class, equalTo(42.0f)); }