Skip to content

Commit 728a548

Browse files
committed
Consistent use of JDK 7 AssertionError with root cause
Issue: SPR-13188
1 parent 655097a commit 728a548

File tree

5 files changed

+9
-10
lines changed

5 files changed

+9
-10
lines changed

spring-test/src/main/java/org/springframework/test/util/JsonPathExpectationsHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,22 +237,22 @@ private String failureReason(String expectedDescription, Object value) {
237237
}
238238

239239
private Object evaluateJsonPath(String content) {
240-
String message = "No value at JSON path \"" + this.expression + "\", exception: ";
240+
String message = "No value at JSON path \"" + this.expression + "\"";
241241
try {
242242
return this.jsonPath.read(content);
243243
}
244244
catch (Throwable ex) {
245-
throw new AssertionError(message + ex.getMessage());
245+
throw new AssertionError(message, ex);
246246
}
247247
}
248248

249249
private Object evaluateJsonPath(String content, Class<?> targetType) {
250-
String message = "No value at JSON path \"" + this.expression + "\", exception: ";
250+
String message = "No value at JSON path \"" + this.expression + "\"";
251251
try {
252252
return JsonPath.parse(content).read(this.expression, targetType);
253253
}
254254
catch (Throwable ex) {
255-
throw new AssertionError(message + ex.getMessage());
255+
throw new AssertionError(message, ex);
256256
}
257257
}
258258

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public final void match(ClientHttpRequest request) throws IOException, Assertion
223223
matchInternal(mockRequest);
224224
}
225225
catch (Exception ex) {
226-
throw new AssertionError("Failed to parse expected or actual XML request content: " + ex.getMessage());
226+
throw new AssertionError("Failed to parse expected or actual XML request content", ex);
227227
}
228228
}
229229

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public final void match(ClientHttpRequest request) throws IOException, Assertion
252252
matchInternal(mockRequest);
253253
}
254254
catch (ParseException ex) {
255-
throw new AssertionError("Failed to parse JSON request content: " + ex.getMessage());
255+
throw new AssertionError("Failed to parse JSON request content", ex);
256256
}
257257
}
258258

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public final void match(ClientHttpRequest request) throws IOException, Assertion
194194
matchInternal(mockRequest);
195195
}
196196
catch (Exception ex) {
197-
throw new AssertionError("Failed to parse XML request content: " + ex.getMessage());
197+
throw new AssertionError("Failed to parse XML request content", ex);
198198
}
199199
}
200200

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,8 @@ private String getContent(MvcResult result) throws UnsupportedEncodingException
258258
MatcherAssert.assertThat(reason, content, StringStartsWith.startsWith(this.prefix));
259259
return content.substring(this.prefix.length());
260260
}
261-
catch (StringIndexOutOfBoundsException oobe) {
262-
throw new AssertionError(
263-
"JSON prefix \"" + this.prefix + "\" not found, exception: " + oobe.getMessage());
261+
catch (StringIndexOutOfBoundsException ex) {
262+
throw new AssertionError("JSON prefix \"" + this.prefix + "\" not found", ex);
264263
}
265264
}
266265
else {

0 commit comments

Comments
 (0)