Assert.assertEquals("null", JSONArray.toJSONString(null));
Assert.assertEquals("[null]", JSONArray.toJSONString(Collections.singletonList(null)));
}
public void test_1() throws Exception {
JSONArray array = new JSONArray(3);
Assert.assertEquals(true, array.isEmpty());
array.add(1);
Assert.assertEquals(false, array.isEmpty());
Assert.assertEquals(true, array.contains(1));
Assert.assertEquals(1, array.toArray()[0]);
{
Object[] items = new Object[1];
array.toArray(items);
Assert.assertEquals(1, items[0]);
}
Assert.assertEquals(true, array.containsAll(Collections.singletonList(1)));
Assert.assertEquals(true, array.remove(Integer.valueOf(1)));
Assert.assertEquals(true, array.isEmpty());
array.addAll(Collections.singletonList(1));
Assert.assertEquals(1, array.size());
array.removeAll(Collections.singletonList(1));
Assert.assertEquals(0, array.size());
array.addAll(0, Arrays.asList(1, 2, 3));
Assert.assertEquals(3, array.size());
array.clear();
array.addAll(0, Arrays.asList(1, 2, 3));
Assert.assertEquals(true, array.retainAll(Arrays.asList(1, 2)));
Assert.assertEquals(2, array.size());
Assert.assertEquals(true, array.retainAll(Arrays.asList(2, 4)));
Assert.assertEquals(1, array.size());
array.set(0, 4);
Assert.assertEquals(4, array.toArray()[0]);
array.add(0, 4);
Assert.assertEquals(4, array.toArray()[0]);
array.remove(0);
array.remove(0);
Assert.assertEquals(0, array.size());
array.addAll(Arrays.asList(1, 2, 3, 4, 5, 4, 3));
Assert.assertEquals(2, array.indexOf(3));
Assert.assertEquals(6, array.lastIndexOf(3));
{
AtomicInteger count = new AtomicInteger();
for (ListIterator<Object> iter = array.listIterator(); iter.hasNext(); iter.next()) {
count.incrementAndGet();
}
Assert.assertEquals(7, count.get());
}
{
AtomicInteger count = new AtomicInteger();
for (ListIterator<Object> iter = array.listIterator(2); iter.hasNext(); iter.next()) {
count.incrementAndGet();
}
Assert.assertEquals(5, count.get());
}
{
Assert.assertEquals(2, array.subList(2, 4).size());
}
}