public void testArrayEnumerationWithDataModification() throws CouchbaseLiteException {
        MutableArray array = new MutableArray();
        for (int i = 0; i < 2; i++)
            array.addValue(i);
        Iterator<Object> itr = array.iterator();
        int count = 0;
        try {
            while (itr.hasNext()) {
                itr.next();
                if (count++ == 0)
                    array.addValue(2);
            }
            fail("Expected ConcurrentModificationException");
        } catch (ConcurrentModificationException e) {
        }
        assertEquals(3, array.count());
        assertEquals(Arrays.asList(0, 1, 2).toString(), array.toList().toString());
        MutableDocument doc = createMutableDocument("doc1");
        doc.setValue("array", array);
        doc = save(doc).toMutable();
        array = doc.getArray("array");
        itr = array.iterator();
        count = 0;
        try {
            while (itr.hasNext()) {
                itr.next();
                if (count++ == 0)
                    array.addValue(3);
            }
            fail("Expected ConcurrentModificationException");
        } catch (ConcurrentModificationException e) {
        }
        assertEquals(4, array.count());
        assertEquals(Arrays.asList(0, 1, 2, 3).toString(), array.toList().toString());
    }
public void testArrayEnumerationWithDataModification() throws CouchbaseLiteException {
        MutableArray array = new MutableArray();
        for (int i = 0; i < 2; i++)
            array.addValue(i);
        Iterator<Object> itr = array.iterator();
        int count = 0;
        try {
            while (itr.hasNext()) {
                itr.next();
                if (count++ == 0)
                    array.addValue(2);
            }
            fail("Expected ConcurrentModificationException");
        } catch (ConcurrentModificationException e) {
        }
        assertEquals(3, array.count());
        assertEquals(Arrays.asList(0, 1, 2).toString(), array.toList().toString());
        MutableDocument doc = createMutableDocument("doc1");
        doc.setValue("array", array);
        doc = save(doc).toMutable();
        array = doc.getArray("array");
        itr = array.iterator();
        count = 0;
        try {
            while (itr.hasNext()) {
                itr.next();
                if (count++ == 0)
                    array.addValue(3);
            }
            fail("Expected ConcurrentModificationException");
        } catch (ConcurrentModificationException e) {
        }
        assertEquals(4, array.count());
        assertEquals(Arrays.asList(0, 1, 2, 3).toString(), array.toList().toString());
    }
public void testarrayenumerationwithdatamodification() throws couchbaseliteexception { mutablearray array = new mutablearray(); for (int i = 0; i < 2; i++) array.addvalue(i); iterator<object> itr = array.iterator(); int count = 0; try { while (itr.hasnext()) { itr.next(); if (count++ == 0) array.addvalue(2); } fail("expected concurrentmodificationexception"); } catch (concurrentmodificationexception e) { } assertequals(3, array.count()); assertequals(arrays.aslist(0, 1, 2).tostring(), array.tolist().tostring()); mutabledocument doc = createmutabledocument("doc1"); doc.setvalue("array", array); doc = save(doc).tomutable(); array = doc.getarray("array"); itr = array.iterator(); count = 0; try { while (itr.hasnext()) { itr.next(); if (count++ == 0) array.addvalue(3); } fail("expected concurrentmodificationexception"); } catch (concurrentmodificationexception e) { } assertequals(4, array.count()); assertequals(arrays.aslist(0, 1, 2, 3).tostring(), array.tolist().tostring()); }