From 9c755ee39c9401f32c3592f9dc664e84a6669aad Mon Sep 17 00:00:00 2001 From: Yasin Date: Mon, 20 Mar 2017 23:43:42 +0530 Subject: [PATCH] BAEL-722 Intro to JSONassert (#1460) * yasin.bhojawala@gmail.com Evaluation article on Different Types of Bean Injection in Spring * Revert "yasin.bhojawala@gmail.com" This reverts commit 963cc51a7a15b75b550108fe4e198cd65a274032. * Fixing compilation error and removing unused import * Introduction to Java9 StackWalking API - yasin.bhojawala@gmail.com Code examples for the article "Introduction to Java9 StackWalking API" * BAEL-608 Introduction to Java9 StackWalking API * BAEL-608 Introduction to Java9 StackWalking API changing the test names to BDD style * BAEL-608 Introduction to Java9 StackWalking API correcting the typo * BAEL-608 Introduction to Java9 StackWalking API improving method names * BAEL-608 Introduction to Java9 StackWalking API test method names improvements * BAEL-718 Quick intro to javatuples * merging pom from master * BAEL-722 Intro to JSONassert * BAEL-722 Intro to JSONassert Updated to 1.5.0 --- libraries/pom.xml | 2 +- .../com/baeldung/jsonassert/JsonAssertTest.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/libraries/pom.xml b/libraries/pom.xml index 85c777b12c..71d0e76c8a 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -77,7 +77,7 @@ 1.2 3.21.0-GA 3.6.2 - 1.4.0 + 1.5.0 \ No newline at end of file diff --git a/libraries/src/test/java/com/baeldung/jsonassert/JsonAssertTest.java b/libraries/src/test/java/com/baeldung/jsonassert/JsonAssertTest.java index c169d83897..b70703cc08 100644 --- a/libraries/src/test/java/com/baeldung/jsonassert/JsonAssertTest.java +++ b/libraries/src/test/java/com/baeldung/jsonassert/JsonAssertTest.java @@ -1,5 +1,8 @@ package com.baeldung.jsonassert; + +import static org.assertj.core.api.Assertions.assertThat; + import org.json.JSONException; import org.json.JSONObject; import org.junit.Test; @@ -64,6 +67,17 @@ public class JsonAssertTest { JSONAssert.assertEquals("{id:1,name:\"Juergen\", address:{city:\"Hollywood\", " + "state:\"LA\", zip:91601}}", result, false); } + + @Test + public void whenMessageUsedInAssertion_thenDisplayMessageOnFailure() throws JSONException { + String actual = "{id:123,name:\"John\"}"; + String failureMessage = "Only one field is expected: name"; + try { + JSONAssert.assertEquals(failureMessage, "{name:\"John\"}", actual, JSONCompareMode.STRICT); + } catch (AssertionError ae) { + assertThat(ae.getMessage()).containsIgnoringCase(failureMessage); + } + } @Test public void givenArray_whenComparing_thenOrderMustMatchForStrict() throws JSONException {