Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add detailed message when comparison of JSONStrings fails #154

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/org/skyscreamer/jsonassert/JSONCompare.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static JSONCompareResult compareJson(final JSONString expected, final JSO
final String expectedJson = expected.toJSONString();
final String actualJson = actual.toJSONString();
if (!expectedJson.equals(actualJson)) {
result.fail("");
result.fail("\nActual: " +actualJson + "\n" + "Expected: " + expectedJson);
}
return result;
}
Expand Down
15 changes: 14 additions & 1 deletion src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@

import org.json.JSONArray;
import org.json.JSONException;
import java.lang.AssertionError;
import org.json.JSONObject;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.skyscreamer.jsonassert.comparator.CustomComparator;
import org.skyscreamer.jsonassert.comparator.JSONComparator;

Expand Down Expand Up @@ -640,7 +643,17 @@ public void testAssertNotEqualsString2JsonComparator() throws IllegalArgumentExc
new RegularExpressionValueMatcher<Object>("\\d"))
));
}


@Rule
public ExpectedException thrown = ExpectedException.none();

@Test
public void testStringFailWithDetailedMessage() throws JSONException {
thrown.expect(AssertionError.class);
thrown.expectMessage("Actual: \"test2\"\n" + "Expected: \"test1\"");
JSONAssert.assertEquals("\"test1\"", "\"test2\"", true);
}

private void testPass(String expected, String actual, JSONCompareMode compareMode)
throws JSONException
{
Expand Down