Skip to content

Commit 9c755ee

Browse files
yasin3061maibin
authored andcommitted
BAEL-722 Intro to JSONassert (eugenp#1460)
* yasin.bhojawala@gmail.com Evaluation article on Different Types of Bean Injection in Spring * Revert "yasin.bhojawala@gmail.com" This reverts commit 963cc51. * 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
1 parent b95a014 commit 9c755ee

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎libraries/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
<javatuples.version>1.2</javatuples.version>
7878
<javaassist.version>3.21.0-GA</javaassist.version>
7979
<assertj.version>3.6.2</assertj.version>
80-
<jsonassert.version>1.4.0</jsonassert.version>
80+
<jsonassert.version>1.5.0</jsonassert.version>
8181
</properties>
8282

8383
</project>

‎libraries/src/test/java/com/baeldung/jsonassert/JsonAssertTest.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.baeldung.jsonassert;
22

3+
4+
import static org.assertj.core.api.Assertions.assertThat;
5+
36
import org.json.JSONException;
47
import org.json.JSONObject;
58
import org.junit.Test;
@@ -64,6 +67,17 @@ public void givenNestedObjects_whenAssertEquals_thenPass() throws JSONException
6467
JSONAssert.assertEquals("{id:1,name:\"Juergen\", address:{city:\"Hollywood\", "
6568
+ "state:\"LA\", zip:91601}}", result, false);
6669
}
70+
71+
@Test
72+
public void whenMessageUsedInAssertion_thenDisplayMessageOnFailure() throws JSONException {
73+
String actual = "{id:123,name:\"John\"}";
74+
String failureMessage = "Only one field is expected: name";
75+
try {
76+
JSONAssert.assertEquals(failureMessage, "{name:\"John\"}", actual, JSONCompareMode.STRICT);
77+
} catch (AssertionError ae) {
78+
assertThat(ae.getMessage()).containsIgnoringCase(failureMessage);
79+
}
80+
}
6781

6882
@Test
6983
public void givenArray_whenComparing_thenOrderMustMatchForStrict() throws JSONException {

0 commit comments

Comments
 (0)