|
25 | 25 | import com.fasterxml.jackson.databind.JsonMappingException;
|
26 | 26 | import com.fasterxml.jackson.databind.ObjectMapper;
|
27 | 27 | import com.fasterxml.jackson.databind.SerializationFeature;
|
28 |
| -import org.junit.Rule; |
29 | 28 | import org.junit.Test;
|
30 |
| -import org.junit.rules.ExpectedException; |
31 | 29 |
|
32 | 30 | import org.springframework.http.MediaType;
|
33 | 31 |
|
34 | 32 | import static org.assertj.core.api.Assertions.assertThat;
|
| 33 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
35 | 34 | import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
36 | 35 |
|
37 | 36 | /**
|
|
41 | 40 | */
|
42 | 41 | public class FieldPathPayloadSubsectionExtractorTests {
|
43 | 42 |
|
44 |
| - @Rule |
45 |
| - public final ExpectedException thrown = ExpectedException.none(); |
46 |
| - |
47 | 43 | @Test
|
48 | 44 | @SuppressWarnings("unchecked")
|
49 | 45 | public void extractMapSubsectionOfJsonMap() throws JsonParseException, JsonMappingException, IOException {
|
@@ -100,27 +96,28 @@ public void extractMapSubsectionWithCommonStructureFromMultiElementArrayInAJsonM
|
100 | 96 |
|
101 | 97 | @Test
|
102 | 98 | public void extractMapSubsectionWithVaryingStructureFromMultiElementArrayInAJsonMap() {
|
103 |
| - this.thrown.expect(PayloadHandlingException.class); |
104 |
| - this.thrown.expectMessage("The following non-optional uncommon paths were found: [a.[].b.d]"); |
105 |
| - new FieldPathPayloadSubsectionExtractor("a.[].b").extractSubsection( |
106 |
| - "{\"a\":[{\"b\":{\"c\":5}},{\"b\":{\"c\":6, \"d\": 7}}]}".getBytes(), MediaType.APPLICATION_JSON); |
| 99 | + assertThatExceptionOfType(PayloadHandlingException.class) |
| 100 | + .isThrownBy(() -> new FieldPathPayloadSubsectionExtractor("a.[].b").extractSubsection( |
| 101 | + "{\"a\":[{\"b\":{\"c\":5}},{\"b\":{\"c\":6, \"d\": 7}}]}".getBytes(), |
| 102 | + MediaType.APPLICATION_JSON)) |
| 103 | + .withMessageContaining("The following non-optional uncommon paths were found: [a.[].b.d]"); |
107 | 104 | }
|
108 | 105 |
|
109 | 106 | @Test
|
110 | 107 | public void extractMapSubsectionWithVaryingStructureFromInconsistentJsonMap() {
|
111 |
| - this.thrown.expect(PayloadHandlingException.class); |
112 |
| - this.thrown.expectMessage("The following non-optional uncommon paths were found: [*.d, *.d.e, *.d.f]"); |
113 |
| - new FieldPathPayloadSubsectionExtractor("*.d").extractSubsection( |
114 |
| - "{\"a\":{\"b\":1},\"c\":{\"d\":{\"e\":1,\"f\":2}}}".getBytes(), MediaType.APPLICATION_JSON); |
| 108 | + assertThatExceptionOfType(PayloadHandlingException.class) |
| 109 | + .isThrownBy(() -> new FieldPathPayloadSubsectionExtractor("*.d").extractSubsection( |
| 110 | + "{\"a\":{\"b\":1},\"c\":{\"d\":{\"e\":1,\"f\":2}}}".getBytes(), MediaType.APPLICATION_JSON)) |
| 111 | + .withMessageContaining("The following non-optional uncommon paths were found: [*.d, *.d.e, *.d.f]"); |
115 | 112 | }
|
116 | 113 |
|
117 | 114 | @Test
|
118 | 115 | public void extractMapSubsectionWithVaryingStructureFromInconsistentJsonMapWhereAllSubsectionFieldsAreOptional() {
|
119 |
| - this.thrown.expect(PayloadHandlingException.class); |
120 |
| - this.thrown.expectMessage("The following non-optional uncommon paths were found: [*.d]"); |
121 |
| - new FieldPathPayloadSubsectionExtractor("*.d").extractSubsection( |
122 |
| - "{\"a\":{\"b\":1},\"c\":{\"d\":{\"e\":1,\"f\":2}}}".getBytes(), MediaType.APPLICATION_JSON, |
123 |
| - Arrays.asList(new FieldDescriptor("e").optional(), new FieldDescriptor("f").optional())); |
| 116 | + assertThatExceptionOfType(PayloadHandlingException.class) |
| 117 | + .isThrownBy(() -> new FieldPathPayloadSubsectionExtractor("*.d").extractSubsection( |
| 118 | + "{\"a\":{\"b\":1},\"c\":{\"d\":{\"e\":1,\"f\":2}}}".getBytes(), MediaType.APPLICATION_JSON, |
| 119 | + Arrays.asList(new FieldDescriptor("e").optional(), new FieldDescriptor("f").optional()))) |
| 120 | + .withMessageContaining("The following non-optional uncommon paths were found: [*.d]"); |
124 | 121 | }
|
125 | 122 |
|
126 | 123 | @Test
|
|
0 commit comments