Skip to content

Commit d250334

Browse files
committed
Polish assertion msgs in JsonPathExpectationsHelper
1 parent af8d9ea commit d250334

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ public void assertValue(String content, Object expectedValue) throws ParseExcept
113113
@SuppressWarnings("rawtypes")
114114
List actualValueList = (List) actualValue;
115115
if (actualValueList.isEmpty()) {
116-
fail("No matching value for JSON path \"" + this.expression + "\"");
116+
fail("No matching value at JSON path \"" + this.expression + "\"");
117117
}
118118
if (actualValueList.size() != 1) {
119119
fail("Got a list of values " + actualValue + " instead of the expected single value " + expectedValue);
120120
}
121121
actualValue = actualValueList.get(0);
122122
}
123123
else if (actualValue != null && expectedValue != null) {
124-
assertEquals("For JSON path \"" + this.expression + "\", type of value",
124+
assertEquals("At JSON path \"" + this.expression + "\", type of value",
125125
expectedValue.getClass().getName(), actualValue.getClass().getName());
126126
}
127127
assertEquals("JSON path \"" + this.expression + "\"", expectedValue, actualValue);
@@ -135,7 +135,7 @@ else if (actualValue != null && expectedValue != null) {
135135
*/
136136
public void assertValueIsString(String content) throws ParseException {
137137
Object value = assertExistsAndReturn(content);
138-
String reason = "Expected string at JSON path \"" + this.expression + "\" but found " + value;
138+
String reason = "Expected a string at JSON path \"" + this.expression + "\" but found: " + value;
139139
assertThat(reason, value, instanceOf(String.class));
140140
}
141141

@@ -147,7 +147,7 @@ public void assertValueIsString(String content) throws ParseException {
147147
*/
148148
public void assertValueIsBoolean(String content) throws ParseException {
149149
Object value = assertExistsAndReturn(content);
150-
String reason = "Expected boolean at JSON path \"" + this.expression + "\" but found " + value;
150+
String reason = "Expected a boolean at JSON path \"" + this.expression + "\" but found: " + value;
151151
assertThat(reason, value, instanceOf(Boolean.class));
152152
}
153153

@@ -159,7 +159,7 @@ public void assertValueIsBoolean(String content) throws ParseException {
159159
*/
160160
public void assertValueIsNumber(String content) throws ParseException {
161161
Object value = assertExistsAndReturn(content);
162-
String reason = "Expected number at JSON path \"" + this.expression + "\" but found " + value;
162+
String reason = "Expected a number at JSON path \"" + this.expression + "\" but found: " + value;
163163
assertThat(reason, value, instanceOf(Number.class));
164164
}
165165

@@ -170,7 +170,7 @@ public void assertValueIsNumber(String content) throws ParseException {
170170
*/
171171
public void assertValueIsArray(String content) throws ParseException {
172172
Object value = assertExistsAndReturn(content);
173-
String reason = "Expected array for JSON path \"" + this.expression + "\" but found " + value;
173+
String reason = "Expected an array at JSON path \"" + this.expression + "\" but found: " + value;
174174
assertTrue(reason, value instanceof List);
175175
}
176176

@@ -182,7 +182,7 @@ public void assertValueIsArray(String content) throws ParseException {
182182
*/
183183
public void assertValueIsMap(String content) throws ParseException {
184184
Object value = assertExistsAndReturn(content);
185-
String reason = "Expected map at JSON path \"" + this.expression + "\" but found " + value;
185+
String reason = "Expected a map at JSON path \"" + this.expression + "\" but found: " + value;
186186
assertThat(reason, value, instanceOf(Map.class));
187187
}
188188

@@ -209,7 +209,7 @@ public void doesNotExist(String content) throws ParseException {
209209
catch (AssertionError ex) {
210210
return;
211211
}
212-
String reason = String.format("Expected no value for JSON path: %s but found: %s", this.expression, value);
212+
String reason = "Expected no value at JSON path \"" + this.expression + "\" but found: " + value;
213213
if (List.class.isInstance(value)) {
214214
assertTrue(reason, ((List<?>) value).isEmpty());
215215
}
@@ -219,7 +219,7 @@ public void doesNotExist(String content) throws ParseException {
219219
}
220220

221221
private Object evaluateJsonPath(String content) throws ParseException {
222-
String message = "No value for JSON path \"" + this.expression + "\", exception: ";
222+
String message = "No value at JSON path \"" + this.expression + "\", exception: ";
223223
try {
224224
return this.jsonPath.read(content);
225225
}
@@ -236,7 +236,7 @@ private Object evaluateJsonPath(String content) throws ParseException {
236236

237237
private Object assertExistsAndReturn(String content) throws ParseException {
238238
Object value = evaluateJsonPath(content);
239-
String reason = "No value for JSON path \"" + this.expression + "\"";
239+
String reason = "No value at JSON path \"" + this.expression + "\"";
240240
assertTrue(reason, value != null);
241241
return value;
242242
}

spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void assertValue() throws Exception {
6464
@Test
6565
public void assertValueWithDifferentExpectedType() throws Exception {
6666
exception.expect(AssertionError.class);
67-
exception.expectMessage(equalTo("For JSON path \"$.nr\", type of value expected:<java.lang.String> but was:<java.lang.Integer>"));
67+
exception.expectMessage(equalTo("At JSON path \"$.nr\", type of value expected:<java.lang.String> but was:<java.lang.Integer>"));
6868
new JsonPathExpectationsHelper("$.nr").assertValue(CONTENT, "5");
6969
}
7070

0 commit comments

Comments
 (0)