Skip to content

Commit 97647ef

Browse files
committed
Flag tests using deprecated json method deprecated
See gh-32791
1 parent 0110c5a commit 97647ef

File tree

2 files changed

+80
-3
lines changed

2 files changed

+80
-3
lines changed

spring-test/src/test/java/org/springframework/test/web/client/match/ContentRequestMatchersTests.java

+49
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import org.springframework.http.MediaType;
2626
import org.springframework.mock.http.client.MockClientHttpRequest;
27+
import org.springframework.test.json.JsonCompareMode;
2728
import org.springframework.util.LinkedMultiValueMap;
2829
import org.springframework.util.MultiValueMap;
2930

@@ -234,6 +235,16 @@ public void testJsonLenientMatch() throws Exception {
234235

235236
MockRestRequestMatchers.content().json("{\n \"foo array\":[\"second\",\"first\"] \n}")
236237
.match(this.request);
238+
MockRestRequestMatchers.content().json("{\n \"foo array\":[\"second\",\"first\"] \n}", JsonCompareMode.LENIENT)
239+
.match(this.request);
240+
}
241+
242+
@Test
243+
@Deprecated
244+
public void testJsonLenientMatchWithDeprecatedBooleanFlag() throws Exception {
245+
String content = "{\n \"foo array\":[\"first\",\"second\"] , \"someExtraProperty\": \"which is allowed\" \n}";
246+
this.request.getBody().write(content.getBytes());
247+
237248
MockRestRequestMatchers.content().json("{\n \"foo array\":[\"second\",\"first\"] \n}", false)
238249
.match(this.request);
239250
}
@@ -243,6 +254,18 @@ public void testJsonStrictMatch() throws Exception {
243254
String content = "{\n \"foo\": \"bar\", \"foo array\":[\"first\",\"second\"] \n}";
244255
this.request.getBody().write(content.getBytes());
245256

257+
MockRestRequestMatchers
258+
.content()
259+
.json("{\n \"foo array\":[\"first\",\"second\"] , \"foo\": \"bar\" \n}", JsonCompareMode.STRICT)
260+
.match(this.request);
261+
}
262+
263+
@Test
264+
@Deprecated
265+
public void testJsonStrictMatchWithDeprecatedBooleanFlag() throws Exception {
266+
String content = "{\n \"foo\": \"bar\", \"foo array\":[\"first\",\"second\"] \n}";
267+
this.request.getBody().write(content.getBytes());
268+
246269
MockRestRequestMatchers
247270
.content()
248271
.json("{\n \"foo array\":[\"first\",\"second\"] , \"foo\": \"bar\" \n}", true)
@@ -259,6 +282,19 @@ public void testJsonLenientNoMatch() throws Exception {
259282
.content()
260283
.json("{\n \"foo\" : \"bar\" \n}")
261284
.match(this.request));
285+
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
286+
MockRestRequestMatchers
287+
.content()
288+
.json("{\n \"foo\" : \"bar\" \n}", JsonCompareMode.LENIENT)
289+
.match(this.request));
290+
}
291+
292+
@Test
293+
@Deprecated
294+
public void testJsonLenientNoMatchWithDeprecatedBooleanFlag() throws Exception {
295+
String content = "{\n \"bar\" : \"foo\" \n}";
296+
this.request.getBody().write(content.getBytes());
297+
262298
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
263299
MockRestRequestMatchers
264300
.content()
@@ -271,6 +307,19 @@ public void testJsonStrictNoMatch() throws Exception {
271307
String content = "{\n \"foo array\":[\"first\",\"second\"] , \"someExtraProperty\": \"which is NOT allowed\" \n}";
272308
this.request.getBody().write(content.getBytes());
273309

310+
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
311+
MockRestRequestMatchers
312+
.content()
313+
.json("{\n \"foo array\":[\"second\",\"first\"] \n}", JsonCompareMode.STRICT)
314+
.match(this.request));
315+
}
316+
317+
@Test
318+
@Deprecated
319+
public void testJsonStrictNoMatchWithDeprecatedBooleanFlag() throws Exception {
320+
String content = "{\n \"foo array\":[\"first\",\"second\"] , \"someExtraProperty\": \"which is NOT allowed\" \n}";
321+
this.request.getBody().write(content.getBytes());
322+
274323
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
275324
MockRestRequestMatchers
276325
.content()

spring-test/src/test/java/org/springframework/test/web/servlet/result/ContentResultMatchersTests.java

+31-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.junit.jupiter.api.Test;
2121

2222
import org.springframework.mock.web.MockHttpServletResponse;
23+
import org.springframework.test.json.JsonCompareMode;
2324
import org.springframework.test.web.servlet.StubMvcResult;
2425

2526
import static java.nio.charset.StandardCharsets.UTF_8;
@@ -80,13 +81,31 @@ void bytesNoMatch() {
8081
@Test
8182
void jsonLenientMatch() throws Exception {
8283
new ContentResultMatchers().json("{\n \"foo\" : \"bar\" \n}").match(getStubMvcResult(CONTENT));
84+
new ContentResultMatchers().json("{\n \"foo\" : \"bar\" \n}",
85+
JsonCompareMode.LENIENT).match(getStubMvcResult(CONTENT));
86+
}
87+
88+
@Test
89+
@Deprecated
90+
void jsonLenientMatchWithDeprecatedBooleanFlag() throws Exception {
8391
new ContentResultMatchers().json("{\n \"foo\" : \"bar\" \n}", false).match(getStubMvcResult(CONTENT));
8492
}
8593

8694
@Test
8795
void jsonStrictMatch() throws Exception {
88-
new ContentResultMatchers().json("{\n \"foo\":\"bar\", \"foo array\":[\"foo\",\"bar\"] \n}", true).match(getStubMvcResult(CONTENT));
89-
new ContentResultMatchers().json("{\n \"foo array\":[\"foo\",\"bar\"], \"foo\":\"bar\" \n}", true).match(getStubMvcResult(CONTENT));
96+
new ContentResultMatchers().json("{\n \"foo\":\"bar\", \"foo array\":[\"foo\",\"bar\"] \n}",
97+
JsonCompareMode.STRICT).match(getStubMvcResult(CONTENT));
98+
new ContentResultMatchers().json("{\n \"foo array\":[\"foo\",\"bar\"], \"foo\":\"bar\" \n}",
99+
JsonCompareMode.STRICT).match(getStubMvcResult(CONTENT));
100+
}
101+
102+
@Test
103+
@Deprecated
104+
void jsonStrictMatchWithDeprecatedBooleanFlag() throws Exception {
105+
new ContentResultMatchers().json("{\n \"foo\":\"bar\", \"foo array\":[\"foo\",\"bar\"] \n}", true)
106+
.match(getStubMvcResult(CONTENT));
107+
new ContentResultMatchers().json("{\n \"foo array\":[\"foo\",\"bar\"], \"foo\":\"bar\" \n}", true)
108+
.match(getStubMvcResult(CONTENT));
90109
}
91110

92111
@Test
@@ -98,7 +117,16 @@ void jsonLenientNoMatch() {
98117
@Test
99118
void jsonStrictNoMatch() {
100119
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
101-
new ContentResultMatchers().json("{\"foo\":\"bar\", \"foo array\":[\"bar\",\"foo\"]}", true).match(getStubMvcResult(CONTENT)));
120+
new ContentResultMatchers().json("{\"foo\":\"bar\", \"foo array\":[\"bar\",\"foo\"]}",
121+
JsonCompareMode.STRICT).match(getStubMvcResult(CONTENT)));
122+
}
123+
124+
@Test
125+
@Deprecated
126+
void jsonStrictNoMatchWithDeprecatedBooleanFlag() {
127+
assertThatExceptionOfType(AssertionError.class).isThrownBy(() ->
128+
new ContentResultMatchers().json("{\"foo\":\"bar\", \"foo array\":[\"bar\",\"foo\"]}", true)
129+
.match(getStubMvcResult(CONTENT)));
102130
}
103131

104132
@Test // gh-23622

0 commit comments

Comments
 (0)