use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class OrderedRealmCollectionIteratorTests method useCase_forEachIterator_modifyQueryResult_innerTransaction_looperThread.
@Test
@UiThreadTest
public void useCase_forEachIterator_modifyQueryResult_innerTransaction_looperThread() {
if (skipTest(CollectionClass.MANAGED_REALMLIST, CollectionClass.UNMANAGED_REALMLIST)) {
return;
}
assertEquals(TEST_SIZE, collection.size());
for (AllJavaTypes obj : collection) {
realm.beginTransaction();
obj.setFieldLong(obj.getFieldLong() + TEST_SIZE);
realm.commitTransaction();
}
// Verifies that all elements were modified.
assertEquals(0, realm.where(AllJavaTypes.class).lessThan(AllJavaTypes.FIELD_LONG, TEST_SIZE).count());
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class OrderedRealmCollectionIteratorTests method listIterator_add.
public void listIterator_add() {
if (skipTest(CollectionClass.REALMRESULTS)) {
return;
}
realm.beginTransaction();
ListIterator<AllJavaTypes> it = collection.listIterator();
// Calling set() before next() should throw.
try {
it.add(new AllJavaTypes());
fail();
} catch (IllegalStateException ignored) {
}
AllJavaTypes obj = it.next();
assertEquals(0, obj.getFieldLong());
it.add(new AllJavaTypes(42));
obj = it.previous();
assertEquals(42, obj.getFieldLong());
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class OrderedRealmCollectionIteratorTests method iterator_outsideChangeToSizeThrowsConcurrentModification.
@Test
public void iterator_outsideChangeToSizeThrowsConcurrentModification() {
if (skipTest(CollectionClass.REALMRESULTS, CollectionClass.REALMRESULTS_SNAPSHOT_RESULTS_BASE, CollectionClass.REALMRESULTS_SNAPSHOT_LIST_BASE)) {
return;
}
// Tests all standard collection methods.
for (CollectionMethod method : CollectionMethod.values()) {
collection = createCollection(realm, collectionClass, TEST_SIZE);
realm.beginTransaction();
Iterator<AllJavaTypes> it = collection.iterator();
switch(method) {
case ADD_OBJECT:
collection.add(new AllJavaTypes(TEST_SIZE));
break;
case ADD_ALL_OBJECTS:
collection.addAll(Collections.singletonList(new AllJavaTypes(TEST_SIZE)));
break;
case CLEAR:
collection.clear();
break;
case REMOVE_OBJECT:
collection.remove(collection.get(0));
break;
case REMOVE_ALL:
collection.removeAll(Collections.singletonList(collection.get(0)));
break;
case RETAIN_ALL:
collection.retainAll(Collections.singletonList(collection.get(0)));
break;
// Does not impact size, so does not trigger ConcurrentModificationException.
case CONTAINS:
case CONTAINS_ALL:
case EQUALS:
case HASHCODE:
case IS_EMPTY:
case ITERATOR:
case SIZE:
case TO_ARRAY:
case TO_ARRAY_INPUT:
realm.cancelTransaction();
continue;
default:
fail("Unknown method: " + method);
}
checkIteratorThrowsConcurrentModification(realm, method.toString(), it);
}
for (ListMethod method : ListMethod.values()) {
collection = createCollection(realm, collectionClass, TEST_SIZE);
realm.beginTransaction();
Iterator<AllJavaTypes> it = collection.iterator();
switch(method) {
case ADD_INDEX:
collection.add(0, new AllJavaTypes(TEST_SIZE));
break;
case ADD_ALL_INDEX:
collection.addAll(0, Collections.singleton(new AllJavaTypes(TEST_SIZE)));
break;
case REMOVE_INDEX:
collection.remove(0);
break;
// Does not impact size, so does not trigger ConcurrentModificationException.
case FIRST:
case LAST:
case GET_INDEX:
case INDEX_OF:
case LAST_INDEX_OF:
case LIST_ITERATOR:
case LIST_ITERATOR_INDEX:
case SET:
case SUBLIST:
realm.cancelTransaction();
continue;
default:
fail("Unknown method: " + method);
}
checkIteratorThrowsConcurrentModification(realm, method.toString(), it);
}
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class OrderedRealmCollectionIteratorTests method listIterator_remove_realmList_doesNotDeleteObject.
@Test
public void listIterator_remove_realmList_doesNotDeleteObject() {
if (skipTest(CollectionClass.REALMRESULTS, CollectionClass.REALMRESULTS_SNAPSHOT_LIST_BASE, CollectionClass.REALMRESULTS_SNAPSHOT_RESULTS_BASE)) {
return;
}
ListIterator<AllJavaTypes> it = collection.listIterator();
AllJavaTypes obj = it.next();
assertEquals("test data 0", obj.getFieldString());
realm.beginTransaction();
it.remove();
assertTrue(obj.isValid());
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class OrderedRealmCollectionIteratorTests method useCase_simpleIterator_modifyQueryResult_innerTransaction_looperThread.
@Test
@UiThreadTest
public void useCase_simpleIterator_modifyQueryResult_innerTransaction_looperThread() {
if (skipTest(CollectionClass.MANAGED_REALMLIST, CollectionClass.UNMANAGED_REALMLIST, CollectionClass.REALMRESULTS)) {
return;
}
assertEquals(TEST_SIZE, collection.size());
for (int i = 0; i < collection.size(); i++) {
realm.beginTransaction();
AllJavaTypes obj = collection.get(i);
obj.setFieldLong(obj.getFieldLong() + TEST_SIZE);
realm.commitTransaction();
}
// Verifies that all elements were modified.
assertEquals(0, realm.where(AllJavaTypes.class).lessThan(AllJavaTypes.FIELD_LONG, TEST_SIZE).count());
}
Aggregations