Skip to content

Commit 19ed439

Browse files
committed
Avoid Hamcrest 2.x deprecation warnings
See gh-23467
1 parent dce8036 commit 19ed439

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

spring-test/src/test/java/org/springframework/test/web/client/samples/matchers/JsonPathRequestMatchersIntegrationTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
import static org.hamcrest.Matchers.endsWith;
3535
import static org.hamcrest.Matchers.equalTo;
3636
import static org.hamcrest.Matchers.hasItem;
37-
import static org.hamcrest.Matchers.isIn;
37+
import static org.hamcrest.Matchers.in;
38+
import static org.hamcrest.Matchers.is;
3839
import static org.hamcrest.Matchers.startsWith;
3940
import static org.springframework.test.web.client.match.MockRestRequestMatchers.content;
4041
import static org.springframework.test.web.client.match.MockRestRequestMatchers.jsonPath;
@@ -115,7 +116,7 @@ public void hamcrestMatchers() throws Exception {
115116
.andExpect(jsonPath("$.composers[0].name", startsWith("Johann")))
116117
.andExpect(jsonPath("$.performers[0].name", endsWith("Ashkenazy")))
117118
.andExpect(jsonPath("$.performers[1].name", containsString("di Me")))
118-
.andExpect(jsonPath("$.composers[1].name", isIn(Arrays.asList("Johann Sebastian Bach", "Johannes Brahms"))))
119+
.andExpect(jsonPath("$.composers[1].name", is(in(Arrays.asList("Johann Sebastian Bach", "Johannes Brahms")))))
119120
.andExpect(jsonPath("$.composers[:3].name", hasItem("Johannes Brahms")))
120121
.andRespond(withSuccess());
121122

@@ -132,7 +133,7 @@ public void hamcrestMatchersWithParameterizedJsonPaths() throws Exception {
132133
.andExpect(jsonPath(composerName, 0).value(startsWith("Johann")))
133134
.andExpect(jsonPath(performerName, 0).value(endsWith("Ashkenazy")))
134135
.andExpect(jsonPath(performerName, 1).value(containsString("di Me")))
135-
.andExpect(jsonPath(composerName, 1).value(isIn(Arrays.asList("Johann Sebastian Bach", "Johannes Brahms"))))
136+
.andExpect(jsonPath(composerName, 1).value(is(in(Arrays.asList("Johann Sebastian Bach", "Johannes Brahms")))))
136137
.andRespond(withSuccess());
137138

138139
executeAndVerify();

spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/JsonPathAssertionTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
import static org.hamcrest.Matchers.containsString;
3333
import static org.hamcrest.Matchers.endsWith;
3434
import static org.hamcrest.Matchers.equalTo;
35-
import static org.hamcrest.Matchers.isIn;
35+
import static org.hamcrest.Matchers.in;
36+
import static org.hamcrest.Matchers.is;
3637
import static org.hamcrest.Matchers.startsWith;
3738
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
3839
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
@@ -106,7 +107,7 @@ public void hamcrestMatcher() throws Exception {
106107
.andExpect(jsonPath("$.composers[0].name", startsWith("Johann")))
107108
.andExpect(jsonPath("$.performers[0].name", endsWith("Ashkenazy")))
108109
.andExpect(jsonPath("$.performers[1].name", containsString("di Me")))
109-
.andExpect(jsonPath("$.composers[1].name", isIn(Arrays.asList("Johann Sebastian Bach", "Johannes Brahms"))));
110+
.andExpect(jsonPath("$.composers[1].name", is(in(Arrays.asList("Johann Sebastian Bach", "Johannes Brahms")))));
110111
}
111112

112113
@Test
@@ -118,7 +119,7 @@ public void hamcrestMatcherWithParameterizedJsonPath() throws Exception {
118119
.andExpect(jsonPath(composerName, 0).value(startsWith("Johann")))
119120
.andExpect(jsonPath(performerName, 0).value(endsWith("Ashkenazy")))
120121
.andExpect(jsonPath(performerName, 1).value(containsString("di Me")))
121-
.andExpect(jsonPath(composerName, 1).value(isIn(Arrays.asList("Johann Sebastian Bach", "Johannes Brahms"))));
122+
.andExpect(jsonPath(composerName, 1).value(is(in(Arrays.asList("Johann Sebastian Bach", "Johannes Brahms")))));
122123
}
123124

124125

0 commit comments

Comments
 (0)