Skip to content

Commit f177889

Browse files
committed
Test#testExceptions() now fails correctly if expected exceptions are not thrown
1 parent deb701d commit f177889

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Test.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,13 +1481,15 @@ public void testExceptions() throws Exception {
14811481
try {
14821482
array = new JSONArray("[\n\r\n\r}");
14831483
System.out.println(array.toString());
1484+
fail("expecting JSONException here.");
14841485
} catch (JSONException jsone) {
14851486
assertEquals("Missing value at 5 [character 0 line 4]", jsone.getMessage());
14861487
}
14871488

14881489
try {
14891490
array = new JSONArray("<\n\r\n\r ");
14901491
System.out.println(array.toString());
1492+
fail("expecting JSONException here.");
14911493
} catch (JSONException jsone) {
14921494
assertEquals("A JSONArray text must start with '[' at 1 [character 2 line 1]", jsone.getMessage());
14931495
}
@@ -1497,68 +1499,79 @@ public void testExceptions() throws Exception {
14971499
array.put(Double.NEGATIVE_INFINITY);
14981500
array.put(Double.NaN);
14991501
System.out.println(array.toString());
1502+
fail("expecting JSONException here.");
15001503
} catch (JSONException jsone) {
15011504
assertEquals("JSON does not allow non-finite numbers.", jsone.getMessage());
15021505
}
15031506

15041507
json = new JSONObject();
15051508
try {
15061509
System.out.println(json.getDouble("stooge"));
1510+
fail("expecting JSONException here.");
15071511
} catch (JSONException jsone) {
15081512
assertEquals("JSONObject[\"stooge\"] not found.", jsone.getMessage());
15091513
}
15101514

15111515
try {
15121516
System.out.println(json.getDouble("howard"));
1517+
fail("expecting JSONException here.");
15131518
} catch (JSONException jsone) {
15141519
assertEquals("JSONObject[\"howard\"] not found.", jsone.getMessage());
15151520
}
15161521

15171522
try {
15181523
System.out.println(json.put(null, "howard"));
1524+
fail("expecting JSONException here.");
15191525
} catch (JSONException jsone) {
15201526
assertEquals("Null key.", jsone.getMessage());
15211527
}
15221528

15231529
try {
15241530
System.out.println(array.getDouble(0));
1531+
fail("expecting JSONException here.");
15251532
} catch (JSONException jsone) {
15261533
assertEquals("JSONArray[0] not found.", jsone.getMessage());
15271534
}
15281535

15291536
try {
15301537
System.out.println(array.get(-1));
1538+
fail("expecting JSONException here.");
15311539
} catch (JSONException jsone) {
15321540
assertEquals("JSONArray[-1] not found.", jsone.getMessage());
15331541
}
15341542

15351543
try {
15361544
System.out.println(array.put(Double.NaN));
1545+
fail("expecting JSONException here.");
15371546
} catch (JSONException jsone) {
15381547
assertEquals("JSON does not allow non-finite numbers.", jsone.getMessage());
15391548
}
15401549

15411550
try {
15421551
json = XML.toJSONObject("<a><b> ");
1552+
fail("expecting JSONException here.");
15431553
} catch (JSONException jsone) {
15441554
assertEquals("Unclosed tag b at 11 [character 12 line 1]", jsone.getMessage());
15451555
}
15461556

15471557
try {
15481558
json = XML.toJSONObject("<a></b> ");
1559+
fail("expecting JSONException here.");
15491560
} catch (JSONException jsone) {
15501561
assertEquals("Mismatched a and b at 6 [character 7 line 1]", jsone.getMessage());
15511562
}
15521563

15531564
try {
15541565
json = XML.toJSONObject("<a></a ");
1566+
fail("expecting JSONException here.");
15551567
} catch (JSONException jsone) {
15561568
assertEquals("Misshaped element at 11 [character 12 line 1]", jsone.getMessage());
15571569
}
15581570

15591571
try {
15601572
jsonArray = new JSONArray(new Object());
15611573
System.out.println(jsonArray.toString());
1574+
fail("expecting JSONException here.");
15621575
} catch (JSONException jsone) {
15631576
assertEquals("JSONArray initial value should be a string or collection or array.", jsone.getMessage());
15641577
}
@@ -1567,6 +1580,7 @@ public void testExceptions() throws Exception {
15671580
str = "[)";
15681581
array = new JSONArray(str);
15691582
System.out.println(array.toString());
1583+
fail("expecting JSONException here.");
15701584
} catch (JSONException jsone) {
15711585
assertEquals("Expected a ',' or ']' at 3 [character 4 line 1]", jsone.getMessage());
15721586
}
@@ -1575,6 +1589,7 @@ public void testExceptions() throws Exception {
15751589
str = "<xml";
15761590
jsonArray = JSONML.toJSONArray(str);
15771591
System.out.println(jsonArray.toString(4));
1592+
fail("expecting JSONException here.");
15781593
} catch (JSONException jsone) {
15791594
assertEquals("Misshaped element at 6 [character 7 line 1]", jsone.getMessage());
15801595
}
@@ -1583,6 +1598,7 @@ public void testExceptions() throws Exception {
15831598
str = "<right></wrong>";
15841599
jsonArray = JSONML.toJSONArray(str);
15851600
System.out.println(jsonArray.toString(4));
1601+
fail("expecting JSONException here.");
15861602
} catch (JSONException jsone) {
15871603
assertEquals("Mismatched 'right' and 'wrong' at 15 [character 16 line 1]", jsone.getMessage());
15881604
}
@@ -1591,6 +1607,7 @@ public void testExceptions() throws Exception {
15911607
str = "{\"koda\": true, \"koda\": true}";
15921608
json = new JSONObject(str);
15931609
System.out.println(json.toString(4));
1610+
fail("expecting JSONException here.");
15941611
} catch (JSONException jsone) {
15951612
assertEquals("Duplicate key \"koda\"", jsone.getMessage());
15961613
}
@@ -1606,6 +1623,7 @@ public void testExceptions() throws Exception {
16061623
.endObject()
16071624
.toString();
16081625
System.out.println(json.toString(4));
1626+
fail("expecting JSONException here.");
16091627
} catch (JSONException jsone) {
16101628
assertEquals("Duplicate key \"bosanda\"", jsone.getMessage());
16111629
}

0 commit comments

Comments
 (0)