Skip to content

Commit 3081b4b

Browse files
committed
Fixes for failing tests due to android integration
1 parent 441fec7 commit 3081b4b

2 files changed

Lines changed: 61 additions & 60 deletions

File tree

src/test/java/org/json/junit/JSONMLTest.java

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ public void emptyXMLException() {
4242
String xmlStr = "";
4343
try {
4444
JSONML.toJSONArray(xmlStr);
45-
assertTrue("Expecting an exception", false);
45+
fail("Expecting an exception");
4646
} catch (JSONException e) {
47-
assertTrue("Expecting an exception message",
48-
"Bad XML at 1 [character 2 line 1]".
49-
equals(e.getMessage()));
47+
assertEquals("Expecting an exception message",
48+
"Bad XML at 0 [character 1 line 1]",
49+
e.getMessage());
5050
}
5151
}
5252

@@ -95,11 +95,11 @@ public void nonXMLException() {
9595
String xmlStr = "{ \"this is\": \"not xml\"}";
9696
try {
9797
JSONML.toJSONArray(xmlStr);
98-
assertTrue("Expecting an exception", false);
98+
fail("Expecting an exception");
9999
} catch (JSONException e) {
100-
assertTrue("Expecting an exception message",
101-
"Bad XML at 25 [character 26 line 1]".
102-
equals(e.getMessage()));
100+
assertEquals("Expecting an exception message",
101+
"Bad XML at 23 [character 24 line 1]",
102+
e.getMessage());
103103
}
104104
}
105105

@@ -198,11 +198,11 @@ public void invalidSlashInTagException() {
198198
"</addresses>";
199199
try {
200200
JSONML.toJSONArray(xmlStr);
201-
assertTrue("Expecting an exception", false);
201+
fail("Expecting an exception");
202202
} catch (JSONException e) {
203-
assertTrue("Expecting an exception message",
204-
"Misshaped tag at 176 [character 14 line 7]".
205-
equals(e.getMessage()));
203+
assertEquals("Expecting an exception message",
204+
"Misshaped tag at 176 [character 14 line 4]",
205+
e.getMessage());
206206
}
207207
}
208208

@@ -223,11 +223,11 @@ public void invalidBangInTagException() {
223223
"</addresses>";
224224
try {
225225
JSONML.toJSONArray(xmlStr);
226-
assertTrue("Expecting an exception", false);
226+
fail("Expecting an exception");
227227
} catch (JSONException e) {
228-
assertTrue("Expecting an exception message",
229-
"Misshaped meta tag at 216 [character 13 line 11]".
230-
equals(e.getMessage()));
228+
assertEquals("Expecting an exception message",
229+
"Misshaped meta tag at 216 [character 13 line 7]",
230+
e.getMessage());
231231
}
232232
}
233233

@@ -253,11 +253,11 @@ public void invalidBangNoCloseInTagException() {
253253
"</addresses>";
254254
try {
255255
JSONML.toJSONArray(xmlStr);
256-
assertTrue("Expecting an exception", false);
256+
fail("Expecting an exception");
257257
} catch (JSONException e) {
258-
assertTrue("Expecting an exception message",
259-
"Misshaped meta tag at 215 [character 13 line 11]".
260-
equals(e.getMessage()));
258+
assertEquals("Expecting an exception message",
259+
"Misshaped meta tag at 215 [character 13 line 7]",
260+
e.getMessage());
261261
}
262262
}
263263

@@ -283,11 +283,11 @@ public void noCloseStartTagException() {
283283
"</addresses>";
284284
try {
285285
JSONML.toJSONArray(xmlStr);
286-
assertTrue("Expecting an exception", false);
286+
fail("Expecting an exception");
287287
} catch (JSONException e) {
288-
assertTrue("Expecting an exception message",
289-
"Misplaced '<' at 194 [character 5 line 10]".
290-
equals(e.getMessage()));
288+
assertEquals("Expecting an exception message",
289+
"Misplaced '<' at 194 [character 5 line 6]",
290+
e.getMessage());
291291
}
292292
}
293293

@@ -343,11 +343,11 @@ public void noCloseEndBraceException() {
343343
"</addresses>";
344344
try {
345345
JSONML.toJSONArray(xmlStr);
346-
assertTrue("Expecting an exception", false);
346+
fail("Expecting an exception");
347347
} catch (JSONException e) {
348-
assertTrue("Expecting an exception message",
349-
"Misplaced '<' at 206 [character 1 line 12]".
350-
equals(e.getMessage()));
348+
assertEquals("Expecting an exception message",
349+
"Misplaced '<' at 206 [character 1 line 7]",
350+
e.getMessage());
351351
}
352352
}
353353

@@ -373,11 +373,11 @@ public void invalidCDATABangInTagException() {
373373
"</addresses>";
374374
try {
375375
JSONML.toJSONArray(xmlStr);
376-
assertTrue("Expecting an exception", false);
376+
fail("Expecting an exception");
377377
} catch (JSONException e) {
378-
assertTrue("Expecting an exception message",
379-
"Expected 'CDATA[' at 204 [character 11 line 9]".
380-
equals(e.getMessage()));
378+
assertEquals("Expecting an exception message",
379+
"Expected 'CDATA[' at 204 [character 11 line 5]",
380+
e.getMessage());
381381
}
382382
}
383383

src/test/java/org/json/junit/XMLTest.java

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.junit.Assert.assertEquals;
44
import static org.junit.Assert.assertNotEquals;
55
import static org.junit.Assert.assertTrue;
6+
import static org.junit.Assert.fail;
67

78
import org.json.JSONArray;
89
import org.json.JSONException;
@@ -74,11 +75,11 @@ public void shouldHandleInvalidSlashInTag() {
7475
"</addresses>";
7576
try {
7677
XML.toJSONObject(xmlStr);
77-
assertTrue("Expecting a JSONException", false);
78+
fail("Expecting a JSONException");
7879
} catch (JSONException e) {
79-
assertTrue("Expecting an exception message",
80-
"Misshaped tag at 176 [character 14 line 5]".
81-
equals(e.getMessage()));
80+
assertEquals("Expecting an exception message",
81+
"Misshaped tag at 176 [character 14 line 4]",
82+
e.getMessage());
8283
}
8384
}
8485

@@ -99,11 +100,11 @@ public void shouldHandleInvalidBangInTag() {
99100
"</addresses>";
100101
try {
101102
XML.toJSONObject(xmlStr);
102-
assertTrue("Expecting a JSONException", false);
103+
fail("Expecting a JSONException");
103104
} catch (JSONException e) {
104-
assertTrue("Expecting an exception message",
105-
"Misshaped meta tag at 215 [character 13 line 8]".
106-
equals(e.getMessage()));
105+
assertEquals("Expecting an exception message",
106+
"Misshaped meta tag at 215 [character 13 line 7]",
107+
e.getMessage());
107108
}
108109
}
109110

@@ -124,11 +125,11 @@ public void shouldHandleInvalidBangNoCloseInTag() {
124125
"</addresses>";
125126
try {
126127
XML.toJSONObject(xmlStr);
127-
assertTrue("Expecting a JSONException", false);
128+
fail("Expecting a JSONException");
128129
} catch (JSONException e) {
129-
assertTrue("Expecting an exception message",
130-
"Misshaped meta tag at 214 [character 13 line 8]".
131-
equals(e.getMessage()));
130+
assertEquals("Expecting an exception message",
131+
"Misshaped meta tag at 214 [character 13 line 7]",
132+
e.getMessage());
132133
}
133134
}
134135

@@ -149,11 +150,11 @@ public void shouldHandleNoCloseStartTag() {
149150
"</addresses>";
150151
try {
151152
XML.toJSONObject(xmlStr);
152-
assertTrue("Expecting a JSONException", false);
153+
fail("Expecting a JSONException");
153154
} catch (JSONException e) {
154-
assertTrue("Expecting an exception message",
155-
"Misplaced '<' at 193 [character 4 line 7]".
156-
equals(e.getMessage()));
155+
assertEquals("Expecting an exception message",
156+
"Misplaced '<' at 193 [character 4 line 6]",
157+
e.getMessage());
157158
}
158159
}
159160

@@ -174,11 +175,11 @@ public void shouldHandleInvalidCDATABangInTag() {
174175
"</addresses>";
175176
try {
176177
XML.toJSONObject(xmlStr);
177-
assertTrue("Expecting a JSONException", false);
178+
fail("Expecting a JSONException");
178179
} catch (JSONException e) {
179-
assertTrue("Expecting an exception message",
180-
"Expected 'CDATA[' at 204 [character 11 line 6]".
181-
equals(e.getMessage()));
180+
assertEquals("Expecting an exception message",
181+
"Expected 'CDATA[' at 204 [character 11 line 5]",
182+
e.getMessage());
182183
}
183184
}
184185

@@ -397,9 +398,9 @@ public void shouldHandleEmptyArray(){
397398

398399
final String expected = "<jo></jo>";
399400
String output1 = XML.toString(jo1,"jo");
400-
assertTrue("Expected an empty root tag", expected.equals(output1));
401+
assertEquals("Expected an empty root tag", expected, output1);
401402
String output2 = XML.toString(jo2,"jo");
402-
assertTrue("Expected an empty root tag", expected.equals(output2));
403+
assertEquals("Expected an empty root tag", expected, output2);
403404
}
404405

405406
/**
@@ -414,9 +415,9 @@ public void shouldHandleEmptyMultiArray(){
414415

415416
final String expected = "<jo><arr>One</arr><arr></arr><arr>Four</arr></jo>";
416417
String output1 = XML.toString(jo1,"jo");
417-
assertTrue("Expected a matching array", expected.equals(output1));
418+
assertEquals("Expected a matching array", expected, output1);
418419
String output2 = XML.toString(jo2,"jo");
419-
assertTrue("Expected a matching array", expected.equals(output2));
420+
assertEquals("Expected a matching array", expected, output2);
420421
}
421422

422423
/**
@@ -431,9 +432,9 @@ public void shouldHandleNonEmptyArray(){
431432

432433
final String expected = "<jo><arr>One</arr><arr>Two</arr><arr>Three</arr></jo>";
433434
String output1 = XML.toString(jo1,"jo");
434-
assertTrue("Expected a non empty root tag", expected.equals(output1));
435+
assertEquals("Expected a non empty root tag", expected, output1);
435436
String output2 = XML.toString(jo2,"jo");
436-
assertTrue("Expected a non empty root tag", expected.equals(output2));
437+
assertEquals("Expected a non empty root tag", expected, output2);
437438
}
438439

439440
/**
@@ -448,9 +449,9 @@ public void shouldHandleMultiArray(){
448449

449450
final String expected = "<jo><arr>One</arr><arr><array>Two</array><array>Three</array></arr><arr>Four</arr></jo>";
450451
String output1 = XML.toString(jo1,"jo");
451-
assertTrue("Expected a matching array", expected.equals(output1));
452+
assertEquals("Expected a matching array", expected, output1);
452453
String output2 = XML.toString(jo2,"jo");
453-
assertTrue("Expected a matching array", expected.equals(output2));
454+
assertEquals("Expected a matching array", expected, output2);
454455
}
455456

456457
/**

0 commit comments

Comments
 (0)