From d2503340e738289957d39f81569b873fd179fd87 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Fri, 14 Aug 2015 17:52:16 +0200 Subject: [PATCH] Polish assertion msgs in JsonPathExpectationsHelper --- .../test/util/JsonPathExpectationsHelper.java | 20 +++++++++---------- .../util/JsonPathExpectationsHelperTests.java | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/test/util/JsonPathExpectationsHelper.java b/spring-test/src/main/java/org/springframework/test/util/JsonPathExpectationsHelper.java index 59e206611b..38cc799aba 100644 --- a/spring-test/src/main/java/org/springframework/test/util/JsonPathExpectationsHelper.java +++ b/spring-test/src/main/java/org/springframework/test/util/JsonPathExpectationsHelper.java @@ -113,7 +113,7 @@ public class JsonPathExpectationsHelper { @SuppressWarnings("rawtypes") List actualValueList = (List) actualValue; if (actualValueList.isEmpty()) { - fail("No matching value for JSON path \"" + this.expression + "\""); + fail("No matching value at JSON path \"" + this.expression + "\""); } if (actualValueList.size() != 1) { fail("Got a list of values " + actualValue + " instead of the expected single value " + expectedValue); @@ -121,7 +121,7 @@ public class JsonPathExpectationsHelper { actualValue = actualValueList.get(0); } else if (actualValue != null && expectedValue != null) { - assertEquals("For JSON path \"" + this.expression + "\", type of value", + assertEquals("At JSON path \"" + this.expression + "\", type of value", expectedValue.getClass().getName(), actualValue.getClass().getName()); } assertEquals("JSON path \"" + this.expression + "\"", expectedValue, actualValue); @@ -135,7 +135,7 @@ public class JsonPathExpectationsHelper { */ public void assertValueIsString(String content) throws ParseException { Object value = assertExistsAndReturn(content); - String reason = "Expected string at JSON path \"" + this.expression + "\" but found " + value; + String reason = "Expected a string at JSON path \"" + this.expression + "\" but found: " + value; assertThat(reason, value, instanceOf(String.class)); } @@ -147,7 +147,7 @@ public class JsonPathExpectationsHelper { */ public void assertValueIsBoolean(String content) throws ParseException { Object value = assertExistsAndReturn(content); - String reason = "Expected boolean at JSON path \"" + this.expression + "\" but found " + value; + String reason = "Expected a boolean at JSON path \"" + this.expression + "\" but found: " + value; assertThat(reason, value, instanceOf(Boolean.class)); } @@ -159,7 +159,7 @@ public class JsonPathExpectationsHelper { */ public void assertValueIsNumber(String content) throws ParseException { Object value = assertExistsAndReturn(content); - String reason = "Expected number at JSON path \"" + this.expression + "\" but found " + value; + String reason = "Expected a number at JSON path \"" + this.expression + "\" but found: " + value; assertThat(reason, value, instanceOf(Number.class)); } @@ -170,7 +170,7 @@ public class JsonPathExpectationsHelper { */ public void assertValueIsArray(String content) throws ParseException { Object value = assertExistsAndReturn(content); - String reason = "Expected array for JSON path \"" + this.expression + "\" but found " + value; + String reason = "Expected an array at JSON path \"" + this.expression + "\" but found: " + value; assertTrue(reason, value instanceof List); } @@ -182,7 +182,7 @@ public class JsonPathExpectationsHelper { */ public void assertValueIsMap(String content) throws ParseException { Object value = assertExistsAndReturn(content); - String reason = "Expected map at JSON path \"" + this.expression + "\" but found " + value; + String reason = "Expected a map at JSON path \"" + this.expression + "\" but found: " + value; assertThat(reason, value, instanceOf(Map.class)); } @@ -209,7 +209,7 @@ public class JsonPathExpectationsHelper { catch (AssertionError ex) { return; } - String reason = String.format("Expected no value for JSON path: %s but found: %s", this.expression, value); + String reason = "Expected no value at JSON path \"" + this.expression + "\" but found: " + value; if (List.class.isInstance(value)) { assertTrue(reason, ((List) value).isEmpty()); } @@ -219,7 +219,7 @@ public class JsonPathExpectationsHelper { } private Object evaluateJsonPath(String content) throws ParseException { - String message = "No value for JSON path \"" + this.expression + "\", exception: "; + String message = "No value at JSON path \"" + this.expression + "\", exception: "; try { return this.jsonPath.read(content); } @@ -236,7 +236,7 @@ public class JsonPathExpectationsHelper { private Object assertExistsAndReturn(String content) throws ParseException { Object value = evaluateJsonPath(content); - String reason = "No value for JSON path \"" + this.expression + "\""; + String reason = "No value at JSON path \"" + this.expression + "\""; assertTrue(reason, value != null); return value; } diff --git a/spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java b/spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java index eb1310a8e6..58a4e50b15 100644 --- a/spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java +++ b/spring-test/src/test/java/org/springframework/test/util/JsonPathExpectationsHelperTests.java @@ -64,7 +64,7 @@ public class JsonPathExpectationsHelperTests { @Test public void assertValueWithDifferentExpectedType() throws Exception { exception.expect(AssertionError.class); - exception.expectMessage(equalTo("For JSON path \"$.nr\", type of value expected: but was:")); + exception.expectMessage(equalTo("At JSON path \"$.nr\", type of value expected: but was:")); new JsonPathExpectationsHelper("$.nr").assertValue(CONTENT, "5"); } -- GitLab