From 0319fe92114d6e7c5c39b2cbe36dc6ba19040616 Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Wed, 29 Oct 2025 09:49:48 +0000 Subject: [PATCH] Deprecate Hamcrest use in WebTestClient Closes gh-35703 --- .../web/reactive/server/CookieAssertions.java | 10 ++++++++ .../reactive/server/DefaultWebTestClient.java | 13 ++++++++++- .../web/reactive/server/HeaderAssertions.java | 6 ++++- .../reactive/server/JsonPathAssertions.java | 9 +++++++- .../web/reactive/server/StatusAssertions.java | 4 ++++ .../web/reactive/server/WebTestClient.java | 11 +++++++++ .../web/reactive/server/XpathAssertions.java | 7 ++++++ .../server/samples/JsonContentTests.java | 3 ++- .../server/samples/ResponseEntityTests.java | 3 ++- .../server/samples/XmlContentTests.java | 3 ++- .../client/context/WebAppResourceTests.java | 3 ++- .../standalone/RouterFunctionTests.java | 5 ++-- .../resultmatches/ContentAssertionTests.java | 10 ++++---- .../resultmatches/JsonPathAssertionTests.java | 23 ++++++++++--------- .../resultmatches/XpathAssertionTests.java | 17 +++++++------- 15 files changed, 95 insertions(+), 32 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/CookieAssertions.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/CookieAssertions.java index a3a49b3988c..f3f8b754266 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/CookieAssertions.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/CookieAssertions.java @@ -16,6 +16,8 @@ package org.springframework.test.web.reactive.server; +import java.util.function.Consumer; + import org.hamcrest.Matcher; import org.springframework.http.ResponseCookie; @@ -53,7 +55,9 @@ public class CookieAssertions extends AbstractCookieAssertions matcher) { String value = getCookie(name).getValue(); assertWithDiagnostics(() -> { @@ -66,7 +70,9 @@ public class CookieAssertions extends AbstractCookieAssertions matcher) { long maxAge = getCookie(name).getMaxAge().getSeconds(); assertWithDiagnostics(() -> { @@ -78,7 +84,9 @@ public class CookieAssertions extends AbstractCookieAssertions matcher) { String path = getCookie(name).getPath(); assertWithDiagnostics(() -> { @@ -90,7 +98,9 @@ public class CookieAssertions extends AbstractCookieAssertions matcher) { String domain = getCookie(name).getDomain(); assertWithDiagnostics(() -> { diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java index 589cfbff8ee..37ad8458970 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java @@ -34,6 +34,7 @@ import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.spi.mapper.MappingProvider; import org.hamcrest.Matcher; import org.hamcrest.MatcherAssert; +import org.jspecify.annotations.NonNull; import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; @@ -584,6 +585,7 @@ class DefaultWebTestClient implements WebTestClient { return self(); } + @SuppressWarnings("removal") @Override public T value(Matcher matcher) { this.result.assertWithDiagnostics(() -> MatcherAssert.assertThat(this.result.getResponseBody(), matcher)); @@ -591,7 +593,7 @@ class DefaultWebTestClient implements WebTestClient { } @Override - @SuppressWarnings("NullAway") // https://github.com/uber/NullAway/issues/1129 + @SuppressWarnings({"NullAway", "removal"}) // https://github.com/uber/NullAway/issues/1129 public T value(Function<@Nullable B, @Nullable R> bodyMapper, Matcher matcher) { this.result.assertWithDiagnostics(() -> { B body = this.result.getResponseBody(); @@ -606,6 +608,15 @@ class DefaultWebTestClient implements WebTestClient { return self(); } + @Override + public T value(@NonNull Function<@Nullable B, @Nullable R> bodyMapper, Consumer consumer) { + this.result.assertWithDiagnostics(() -> { + B body = this.result.getResponseBody(); + consumer.accept(bodyMapper.apply(body)); + }); + return self(); + } + @Override public T consumeWith(Consumer> consumer) { this.result.assertWithDiagnostics(() -> consumer.accept(this.result)); diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/HeaderAssertions.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/HeaderAssertions.java index df1c2b3fae6..5cd50af6381 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/HeaderAssertions.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/HeaderAssertions.java @@ -17,6 +17,7 @@ package org.springframework.test.web.reactive.server; import java.util.List; +import java.util.function.Consumer; import org.hamcrest.Matcher; @@ -59,7 +60,9 @@ public class HeaderAssertions extends AbstractHeaderAssertions matcher) { String value = getResponseHeaders().getFirst(name); assertWithDiagnostics(() -> { @@ -73,7 +76,9 @@ public class HeaderAssertions extends AbstractHeaderAssertions> matcher) { List values = getResponseHeaders().get(name); assertWithDiagnostics(() -> { @@ -83,5 +88,4 @@ public class HeaderAssertions extends AbstractHeaderAssertions WebTestClient.BodyContentSpec value(Matcher matcher) { getPathHelper().assertValue(getContent(), matcher); return getBodySpec(); @@ -56,7 +59,9 @@ public class JsonPathAssertions extends AbstractJsonPathAssertions WebTestClient.BodyContentSpec value(Class targetType, Matcher matcher) { getPathHelper().assertValue(getContent(), matcher, targetType); return getBodySpec(); @@ -64,7 +69,9 @@ public class JsonPathAssertions extends AbstractJsonPathAssertions WebTestClient.BodyContentSpec value(ParameterizedTypeReference targetType, Matcher matcher) { getPathHelper().assertValue(getContent(), matcher, targetType); return getBodySpec(); diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/StatusAssertions.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/StatusAssertions.java index c4b1fb2c16a..da785589f1e 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/StatusAssertions.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/StatusAssertions.java @@ -16,6 +16,8 @@ package org.springframework.test.web.reactive.server; +import java.util.function.Consumer; + import org.hamcrest.Matcher; import org.hamcrest.MatcherAssert; @@ -51,7 +53,9 @@ public class StatusAssertions extends AbstractStatusAssertions matcher) { int actual = getStatus().value(); assertWithDiagnostics(() -> MatcherAssert.assertThat("Response status", actual, matcher)); diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java index 5b895ec86e5..e34e21fce8e 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java @@ -957,7 +957,9 @@ public interface WebTestClient { /** * Assert the extracted body with a {@link Matcher}. * @since 5.1 + * @deprecated in favor of {@link Consumer}-based variants */ + @Deprecated(since = "7.0", forRemoval = true) @NullUnmarked // To avoid a "Cannot attach type annotations" error when org.hamcrest.Matcher is not in the classpath T value(Matcher matcher); @@ -965,7 +967,9 @@ public interface WebTestClient { * Transform the extracted the body with a function, for example, extracting a * property, and assert the mapped value with a {@link Matcher}. * @since 5.1 + * @deprecated in favor of {@link Consumer}-based variants */ + @Deprecated(since = "7.0", forRemoval = true) @NullUnmarked // To avoid a "Cannot attach type annotations" error when org.hamcrest.Matcher is not in the classpath T value(@NonNull Function<@Nullable B, @Nullable R> bodyMapper, Matcher matcher); @@ -975,6 +979,13 @@ public interface WebTestClient { */ T value(Consumer<@Nullable B> consumer); + /** + * Transform the extracted the body with a function, for example, extracting a + * property, and assert the mapped value with a {@link Consumer}. + * @since 7.0 + */ + T value(@NonNull Function<@Nullable B, @Nullable R> bodyMapper, Consumer consumer); + /** * Assert the exchange result with the given {@link Consumer}. */ diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/XpathAssertions.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/XpathAssertions.java index 9463d4257a1..9b70e86f3c1 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/XpathAssertions.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/XpathAssertions.java @@ -18,6 +18,7 @@ package org.springframework.test.web.reactive.server; import java.util.Map; import java.util.Optional; +import java.util.function.Consumer; import org.hamcrest.Matcher; import org.jspecify.annotations.Nullable; @@ -60,21 +61,27 @@ public class XpathAssertions extends AbstractXpathAssertions matcher){ return assertWith(() -> getXpathHelper().assertString(getContent(), getCharset(), matcher)); } /** * Delegates to {@link XpathExpectationsHelper#assertNumber(byte[], String, Matcher)}. + * @deprecated in favor of {@link Consumer}-based variants */ + @Deprecated(since = "7.0", forRemoval = true) public WebTestClient.BodyContentSpec number(Matcher matcher){ return assertWith(() -> getXpathHelper().assertNumber(getContent(), getCharset(), matcher)); } /** * Delegates to {@link XpathExpectationsHelper#assertNodeCount(byte[], String, Matcher)}. + * @deprecated in favor of {@link Consumer}-based variants */ + @Deprecated(since = "7.0", forRemoval = true) public WebTestClient.BodyContentSpec nodeCount(Matcher matcher){ return assertWith(() -> getXpathHelper().assertNodeCount(getContent(), getCharset(), matcher)); } 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 8fdcfc5d14a..c2b552bf2fa 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 @@ -18,6 +18,7 @@ package org.springframework.test.web.reactive.server.samples; import java.net.URI; +import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; @@ -113,7 +114,7 @@ class JsonContentTests { .exchange() .expectStatus().isOk() .expectBody() - .jsonPath("$.firstName").value(containsString("oh")); + .jsonPath("$.firstName").value(String.class, v -> MatcherAssert.assertThat(v, containsString("oh"))); } @Test diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ResponseEntityTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ResponseEntityTests.java index f6921c03cda..e8ee2ee8f75 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ResponseEntityTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ResponseEntityTests.java @@ -22,6 +22,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.test.StepVerifier; @@ -72,7 +73,7 @@ class ResponseEntityTests { .exchange() .expectStatus().isOk() .expectHeader().contentType(MediaType.APPLICATION_JSON) - .expectBody(Person.class).value(Person::getName, startsWith("Joh")); + .expectBody(Person.class).value(Person::getName, v -> MatcherAssert.assertThat(v, startsWith("Joh"))); } @Test diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/XmlContentTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/XmlContentTests.java index 5495ee071b4..6615821a3fc 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/XmlContentTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/XmlContentTests.java @@ -25,6 +25,7 @@ import jakarta.xml.bind.annotation.XmlAccessType; import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; +import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; @@ -93,7 +94,7 @@ class XmlContentTests { .exchange() .expectStatus().isOk() .expectBody() - .xpath("//person/name").string(startsWith("J")); + .xpath("//person/name").string(v -> MatcherAssert.assertThat(v, startsWith("J"))); } @Test diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/context/WebAppResourceTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/context/WebAppResourceTests.java index 2df8a63b51a..56be50662e8 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/context/WebAppResourceTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/context/WebAppResourceTests.java @@ -16,6 +16,7 @@ package org.springframework.test.web.servlet.samples.client.context; +import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -70,7 +71,7 @@ public class WebAppResourceTests { .exchange() .expectStatus().isOk() .expectHeader().contentType("text/javascript") - .expectBody(String.class).value(containsString("Spring={};")); + .expectBody(String.class).value(v -> MatcherAssert.assertThat(v, containsString("Spring={};"))); } // Forwarded to the "default" servlet via diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/RouterFunctionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/RouterFunctionTests.java index 5e8dc814893..95b1318d821 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/RouterFunctionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/RouterFunctionTests.java @@ -19,6 +19,7 @@ package org.springframework.test.web.servlet.samples.client.standalone; import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; +import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; @@ -46,8 +47,8 @@ public class RouterFunctionTests { void json() { execute("/person/Lee", body -> body.jsonPath("$.name").isEqualTo("Lee") .jsonPath("$.age").isEqualTo(42) - .jsonPath("$.age").value(equalTo(42)) - .jsonPath("$.age").value(Float.class, equalTo(42.0f))); + .jsonPath("$.age").value(v -> MatcherAssert.assertThat(v, equalTo(42))) + .jsonPath("$.age").value(Float.class, v -> MatcherAssert.assertThat(v, equalTo(42.0f)))); } @Test diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/resultmatches/ContentAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/resultmatches/ContentAssertionTests.java index c69d4972087..d6d4ed998b3 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/resultmatches/ContentAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/resultmatches/ContentAssertionTests.java @@ -16,6 +16,7 @@ package org.springframework.test.web.servlet.samples.client.standalone.resultmatches; +import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; @@ -77,11 +78,12 @@ class ContentAssertionTests { testClient.get().uri("/handle").accept(TEXT_PLAIN) .exchange() .expectStatus().isOk() - .expectBody(String.class).value(equalTo("Hello world!")); + .expectBody(String.class).value(v -> MatcherAssert.assertThat(v, equalTo("Hello world!"))); testClient.get().uri("/handleUtf8") .exchange() .expectStatus().isOk() - .expectBody(String.class).value(equalTo("\u3053\u3093\u306b\u3061\u306f\u4e16\u754c\uff01")); + .expectBody(String.class).value(v -> + MatcherAssert.assertThat(v, equalTo("\u3053\u3093\u306b\u3061\u306f\u4e16\u754c\uff01"))); } @Test @@ -104,7 +106,7 @@ class ContentAssertionTests { testClient.get().uri("/handle").accept(TEXT_PLAIN) .exchange() .expectStatus().isOk() - .expectBody(String.class).value(containsString("world")); + .expectBody(String.class).value(v -> MatcherAssert.assertThat(v, containsString("world"))); } @Test @@ -113,7 +115,7 @@ class ContentAssertionTests { .exchange() .expectStatus().isOk() .expectHeader().contentType("text/plain;charset=ISO-8859-1") - .expectBody(String.class).value(containsString("world")); + .expectBody(String.class).value(v -> MatcherAssert.assertThat(v, containsString("world"))); testClient.get().uri("/handleUtf8") .exchange() diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/resultmatches/JsonPathAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/resultmatches/JsonPathAssertionTests.java index 6cb772f3788..1b6642a168d 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/resultmatches/JsonPathAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/resultmatches/JsonPathAssertionTests.java @@ -16,8 +16,9 @@ package org.springframework.test.web.servlet.samples.client.standalone.resultmatches; -import java.util.Arrays; +import java.util.List; +import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; @@ -100,8 +101,8 @@ public class JsonPathAssertionTests { .expectStatus().isOk() .expectHeader().contentType(MediaType.APPLICATION_JSON) .expectBody() - .jsonPath("$.composers[0].name").value(equalTo("Johann Sebastian Bach")) - .jsonPath("$.performers[1].name").value(equalTo("Yehudi Menuhin")); + .jsonPath("$.composers[0].name").value(v -> MatcherAssert.assertThat(v, equalTo("Johann Sebastian Bach"))) + .jsonPath("$.performers[1].name").value(v -> MatcherAssert.assertThat(v, equalTo("Yehudi Menuhin"))); } @Test @@ -109,10 +110,10 @@ public class JsonPathAssertionTests { client.get().uri("/music/people") .exchange() .expectBody() - .jsonPath("$.composers[0].name").value(startsWith("Johann")) - .jsonPath("$.performers[0].name").value(endsWith("Ashkenazy")) - .jsonPath("$.performers[1].name").value(containsString("di Me")) - .jsonPath("$.composers[1].name").value(is(in(Arrays.asList("Johann Sebastian Bach", "Johannes Brahms")))); + .jsonPath("$.composers[0].name").value(String.class, v -> MatcherAssert.assertThat(v, startsWith("Johann"))) + .jsonPath("$.performers[0].name").value(String.class, v -> MatcherAssert.assertThat(v, endsWith("Ashkenazy"))) + .jsonPath("$.performers[1].name").value(String.class, v -> MatcherAssert.assertThat(v, containsString("di Me"))) + .jsonPath("$.composers[1].name").value(v -> MatcherAssert.assertThat(v, is(in(List.of("Johann Sebastian Bach", "Johannes Brahms"))))); } @Test @@ -120,10 +121,10 @@ public class JsonPathAssertionTests { client.get().uri("/music/people") .exchange() .expectBody() - .jsonPath("$.composers[0].name").value(startsWith("Johann")) - .jsonPath("$.performers[0].name").value(endsWith("Ashkenazy")) - .jsonPath("$.performers[1].name").value(containsString("di Me")) - .jsonPath("$.composers[1].name").value(is(in(Arrays.asList("Johann Sebastian Bach", "Johannes Brahms")))); + .jsonPath("$.composers[0].name").value(String.class, v -> MatcherAssert.assertThat(v, startsWith("Johann"))) + .jsonPath("$.performers[0].name").value(String.class, v -> MatcherAssert.assertThat(v, endsWith("Ashkenazy"))) + .jsonPath("$.performers[1].name").value(String.class, v -> MatcherAssert.assertThat(v, containsString("di Me"))) + .jsonPath("$.composers[1].name").value(v -> MatcherAssert.assertThat(v, is(in(List.of("Johann Sebastian Bach", "Johannes Brahms"))))); } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/resultmatches/XpathAssertionTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/resultmatches/XpathAssertionTests.java index 25b64cd4b03..f32dd11c806 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/resultmatches/XpathAssertionTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/resultmatches/XpathAssertionTests.java @@ -26,6 +26,7 @@ import jakarta.xml.bind.annotation.XmlAccessorType; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlElementWrapper; import jakarta.xml.bind.annotation.XmlRootElement; +import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; @@ -80,7 +81,7 @@ public class XpathAssertionTests { .xpath(composer, musicNamespace, 4).exists() .xpath(performer, musicNamespace, 1).exists() .xpath(performer, musicNamespace, 2).exists() - .xpath(composer, musicNamespace, 1).string(notNullValue()); + .xpath(composer, musicNamespace, 1).string(v -> MatcherAssert.assertThat(v, notNullValue())); } @Test @@ -112,9 +113,9 @@ public class XpathAssertionTests { .xpath(composerName, musicNamespace, 4).isEqualTo("Robert Schumann") .xpath(performerName, musicNamespace, 1).isEqualTo("Vladimir Ashkenazy") .xpath(performerName, musicNamespace, 2).isEqualTo("Yehudi Menuhin") - .xpath(composerName, musicNamespace, 1).string(equalTo("Johann Sebastian Bach")) // Hamcrest.. - .xpath(composerName, musicNamespace, 1).string(startsWith("Johann")) - .xpath(composerName, musicNamespace, 1).string(notNullValue()); + .xpath(composerName, musicNamespace, 1).string(v -> MatcherAssert.assertThat(v, equalTo("Johann Sebastian Bach"))) // Hamcrest.. + .xpath(composerName, musicNamespace, 1).string(v -> MatcherAssert.assertThat(v, startsWith("Johann"))) + .xpath(composerName, musicNamespace, 1).string(v -> MatcherAssert.assertThat(v, notNullValue())); } @Test @@ -128,8 +129,8 @@ public class XpathAssertionTests { .xpath(expression, musicNamespace, 2).isEqualTo(.0025) .xpath(expression, musicNamespace, 3).isEqualTo(1.6035) .xpath(expression, musicNamespace, 4).isEqualTo(Double.NaN) - .xpath(expression, musicNamespace, 1).number(equalTo(21d)) // Hamcrest.. - .xpath(expression, musicNamespace, 3).number(closeTo(1.6, .01)); + .xpath(expression, musicNamespace, 1).number(v -> MatcherAssert.assertThat(v, equalTo(21d))) // Hamcrest.. + .xpath(expression, musicNamespace, 3).number(v -> MatcherAssert.assertThat(v, closeTo(1.6, .01))); } @Test @@ -150,8 +151,8 @@ public class XpathAssertionTests { .expectBody() .xpath("/ns:people/composers/composer", musicNamespace).nodeCount(4) .xpath("/ns:people/performers/performer", musicNamespace).nodeCount(2) - .xpath("/ns:people/composers/composer", musicNamespace).nodeCount(equalTo(4)) // Hamcrest.. - .xpath("/ns:people/performers/performer", musicNamespace).nodeCount(equalTo(2)); + .xpath("/ns:people/composers/composer", musicNamespace).nodeCount(v -> MatcherAssert.assertThat(v, equalTo(4))) // Hamcrest.. + .xpath("/ns:people/performers/performer", musicNamespace).nodeCount(v -> MatcherAssert.assertThat(v, equalTo(2))); } @Test