Skip to content

Commit dedb044

Browse files
authored
Merge pull request #86 from strkkk/add-isEmpty-method-usage
add usage of isEmpty method
2 parents 20d90bf + d00501e commit dedb044

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void malFormedCookieListException() {
6565
public void emptyStringCookieList() {
6666
String cookieStr = "";
6767
JSONObject jsonObject = CookieList.toJSONObject(cookieStr);
68-
assertTrue(jsonObject.length() == 0);
68+
assertTrue(jsonObject.isEmpty());
6969
}
7070

7171
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void jsonObjectFromEnum() {
3535
// If there are no getters then the object is empty.
3636
MyEnum myEnum = MyEnum.VAL2;
3737
JSONObject jsonObject = new JSONObject(myEnum);
38-
assertTrue("simple enum has no getters", jsonObject.length() == 0);
38+
assertTrue("simple enum has no getters", jsonObject.isEmpty());
3939

4040
// enum with a getters should create a non-empty object
4141
MyEnumField myEnumField = MyEnumField.VAL2;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ public void remove() {
691691
JSONArray jsonArray = new JSONArray(arrayStr1);
692692
jsonArray.remove(0);
693693
assertTrue("array should be empty", null == jsonArray.remove(5));
694-
assertTrue("jsonArray should be empty", jsonArray.length() == 0);
694+
assertTrue("jsonArray should be empty", jsonArray.isEmpty());
695695
}
696696

697697
/**

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public void testLongFromString(){
141141
@Test
142142
public void emptyJsonObject() {
143143
JSONObject jsonObject = new JSONObject();
144-
assertTrue("jsonObject should be empty", jsonObject.length() == 0);
144+
assertTrue("jsonObject should be empty", jsonObject.isEmpty());
145145
}
146146

147147
/**
@@ -184,7 +184,7 @@ public void jsonObjectByNames() {
184184
public void jsonObjectByNullMap() {
185185
Map<String, Object> map = null;
186186
JSONObject jsonObject = new JSONObject(map);
187-
assertTrue("jsonObject should be empty", jsonObject.length() == 0);
187+
assertTrue("jsonObject should be empty", jsonObject.isEmpty());
188188
}
189189

190190
/**
@@ -1122,7 +1122,7 @@ public void bigNumberOperations() {
11221122
BigDecimal bigDecimal = new BigDecimal(
11231123
"123456789012345678901234567890.12345678901234567890123456789");
11241124
jsonObject = new JSONObject(bigDecimal);
1125-
assertTrue("large bigDecimal is not stored", jsonObject.length() == 0);
1125+
assertTrue("large bigDecimal is not stored", jsonObject.isEmpty());
11261126

11271127
/**
11281128
* JSONObject put(String, Object) method stores and serializes
@@ -2244,11 +2244,11 @@ public void jsonObjectParsingErrors() {
22442244
public void jsonObjectPutOnceNull() {
22452245
JSONObject jsonObject = new JSONObject();
22462246
jsonObject.putOnce(null, null);
2247-
assertTrue("jsonObject should be empty", jsonObject.length() == 0);
2247+
assertTrue("jsonObject should be empty", jsonObject.isEmpty());
22482248
jsonObject.putOnce("", null);
2249-
assertTrue("jsonObject should be empty", jsonObject.length() == 0);
2249+
assertTrue("jsonObject should be empty", jsonObject.isEmpty());
22502250
jsonObject.putOnce(null, "");
2251-
assertTrue("jsonObject should be empty", jsonObject.length() == 0);
2251+
assertTrue("jsonObject should be empty", jsonObject.isEmpty());
22522252
}
22532253

22542254
/**
@@ -2424,11 +2424,11 @@ public void jsonObjectputNull() {
24242424
String str = "{\"myKey\": \"myval\"}";
24252425
JSONObject jsonObjectRemove = new JSONObject(str);
24262426
jsonObjectRemove.remove("myKey");
2427-
assertEquals("jsonObject should be empty",0 ,jsonObjectRemove.length());
2427+
assertTrue("jsonObject should be empty", jsonObjectRemove.isEmpty());
24282428

24292429
JSONObject jsonObjectPutNull = new JSONObject(str);
24302430
jsonObjectPutNull.put("myKey", (Object) null);
2431-
assertEquals("jsonObject should be empty",0 ,jsonObjectPutNull.length());
2431+
assertTrue("jsonObject should be empty", jsonObjectPutNull.isEmpty());
24322432

24332433

24342434
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class PropertyTest {
2121
public void shouldHandleNullProperties() {
2222
Properties properties = null;
2323
JSONObject jsonObject = Property.toJSONObject(properties);
24-
assertTrue("jsonObject should be empty", jsonObject.length() == 0);
24+
assertTrue("jsonObject should be empty", jsonObject.isEmpty());
2525
}
2626

2727
/**
@@ -32,7 +32,7 @@ public void shouldHandleNullProperties() {
3232
public void shouldHandleEmptyProperties() {
3333
Properties properties = new Properties();
3434
JSONObject jsonObject = Property.toJSONObject(properties);
35-
assertTrue("jsonObject should be empty", jsonObject.length() == 0);
35+
assertTrue("jsonObject should be empty", jsonObject.isEmpty());
3636
}
3737

3838
/**

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class XMLTest {
3434
public void shouldHandleNullXML() {
3535
String xmlStr = null;
3636
JSONObject jsonObject = XML.toJSONObject(xmlStr);
37-
assertTrue("jsonObject should be empty", jsonObject.length() == 0);
37+
assertTrue("jsonObject should be empty", jsonObject.isEmpty());
3838
}
3939

4040
/**
@@ -45,7 +45,7 @@ public void shouldHandleEmptyXML() {
4545

4646
String xmlStr = "";
4747
JSONObject jsonObject = XML.toJSONObject(xmlStr);
48-
assertTrue("jsonObject should be empty", jsonObject.length() == 0);
48+
assertTrue("jsonObject should be empty", jsonObject.isEmpty());
4949
}
5050

5151
/**
@@ -55,7 +55,7 @@ public void shouldHandleEmptyXML() {
5555
public void shouldHandleNonXML() {
5656
String xmlStr = "{ \"this is\": \"not xml\"}";
5757
JSONObject jsonObject = XML.toJSONObject(xmlStr);
58-
assertTrue("xml string should be empty", jsonObject.length() == 0);
58+
assertTrue("xml string should be empty", jsonObject.isEmpty());
5959
}
6060

6161
/**
@@ -200,7 +200,7 @@ public void shouldHandleNullJSONXML() {
200200
public void shouldHandleEmptyJSONXML() {
201201
JSONObject jsonObject= new JSONObject();
202202
String xmlStr = XML.toString(jsonObject);
203-
assertTrue("xml string should be empty", xmlStr.length() == 0);
203+
assertTrue("xml string should be empty", xmlStr.isEmpty());
204204
}
205205

206206
/**

0 commit comments

Comments
 (0)