use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class OrderedRealmCollectionIteratorTests method useCase_simpleIterator_modifyQueryResult_innerTransaction.
@Test
public void useCase_simpleIterator_modifyQueryResult_innerTransaction() {
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());
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class OrderedRealmCollectionIteratorTests method useCase_simpleIterator_modifyQueryResult_outerTransaction_looperThread.
@Test
@UiThreadTest
public void useCase_simpleIterator_modifyQueryResult_outerTransaction_looperThread() {
if (skipTest(CollectionClass.MANAGED_REALMLIST, CollectionClass.UNMANAGED_REALMLIST, CollectionClass.REALMRESULTS)) {
return;
}
assertEquals(TEST_SIZE, collection.size());
realm.beginTransaction();
for (int i = 0; i < collection.size(); i++) {
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());
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class OrderedRealmCollectionIteratorTests method listIterator_unsupportedMethods.
@Test
public void listIterator_unsupportedMethods() {
ListIterator<AllJavaTypes> it = collection.listIterator();
try {
it.remove();
fail();
} catch (UnsupportedOperationException e) {
assertResultsOrSnapshot();
} catch (IllegalStateException e) {
assertRealmList();
}
try {
it.add(null);
fail();
} catch (UnsupportedOperationException e) {
assertResultsOrSnapshot();
} catch (IllegalArgumentException e) {
assertRealmList();
}
try {
it.set(new AllJavaTypes());
fail();
} catch (UnsupportedOperationException e) {
assertResultsOrSnapshot();
} catch (IllegalStateException e) {
assertRealmList();
}
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class OrderedRealmCollectionIteratorTests method listIterator_transactionBeforeNextItem.
@Test
public void listIterator_transactionBeforeNextItem() {
Iterator<AllJavaTypes> it = collection.listIterator();
int i = 0;
while (it.hasNext()) {
AllJavaTypes item = it.next();
assertEquals("Failed at index: " + i, i, item.getFieldLong());
i++;
// Committing transactions while iterating should not effect the current iterator if on a looper thread.
createNewObject();
}
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class OrderedRealmCollectionIteratorTests method iterator_unrelatedTransactionBeforeNextItem.
@Test
public void iterator_unrelatedTransactionBeforeNextItem() {
Iterator<AllJavaTypes> it = collection.iterator();
int i = 0;
while (it.hasNext()) {
AllJavaTypes item = it.next();
assertEquals("Failed at index: " + i, i, item.getFieldLong());
i++;
// Committing unrelated transactions while iterating should not effect the current iterator.
createNewObject();
}
}
Aggregations