use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class OrderedRealmCollectionIteratorTests method listIterator_oneElement.
@Test
public void listIterator_oneElement() {
collection = createCollection(realm, collectionClass, 1);
ListIterator<AllJavaTypes> it = collection.listIterator();
// Tests beginning of the list.
assertFalse(it.hasPrevious());
assertTrue(it.hasNext());
assertEquals(-1, it.previousIndex());
assertEquals(0, it.nextIndex());
// Tests end of the list.
AllJavaTypes firstObject = it.next();
assertEquals(0, firstObject.getFieldLong());
assertTrue(it.hasPrevious());
assertFalse(it.hasNext());
assertEquals(0, it.previousIndex());
assertEquals(1, it.nextIndex());
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class OrderedRealmCollectionIteratorTests method listIterator_startIndex.
@Test
public void listIterator_startIndex() {
int i = TEST_SIZE / 2;
ListIterator<AllJavaTypes> it = collection.listIterator(i);
assertTrue(it.hasPrevious());
assertTrue(it.hasNext());
assertEquals(i - 1, it.previousIndex());
assertEquals(i, it.nextIndex());
AllJavaTypes nextObject = it.next();
assertEquals(i, nextObject.getFieldLong());
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class OrderedRealmCollectionIteratorTests method listIterator_manyElements.
@Test
public void listIterator_manyElements() {
ListIterator<AllJavaTypes> it = collection.listIterator();
// Tests beginning of the list.
assertFalse(it.hasPrevious());
assertTrue(it.hasNext());
assertEquals(-1, it.previousIndex());
assertEquals(0, it.nextIndex());
// Tests 1st element in the list.
AllJavaTypes firstObject = it.next();
assertEquals(0, firstObject.getFieldLong());
assertTrue(it.hasPrevious());
assertEquals(0, it.previousIndex());
// Moves to second last element.
for (int i = 1; i < TEST_SIZE - 1; i++) {
it.next();
}
assertTrue(it.hasPrevious());
assertTrue(it.hasNext());
assertEquals(TEST_SIZE - 1, it.nextIndex());
// Tests end of the list.
AllJavaTypes lastObject = it.next();
assertEquals(TEST_SIZE - 1, lastObject.getFieldLong());
assertTrue(it.hasPrevious());
assertFalse(it.hasNext());
assertEquals(TEST_SIZE, it.nextIndex());
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class OrderedRealmCollectionTests method get_validIndex.
@Test
public void get_validIndex() {
AllJavaTypes first = collection.get(0);
assertEquals(0, first.getFieldInt());
AllJavaTypes last = collection.get(TEST_SIZE - 1);
assertEquals(TEST_SIZE - 1, last.getFieldInt());
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class RealmQueryTests method createIsEmptyDataSet.
private void createIsEmptyDataSet(Realm realm) {
realm.beginTransaction();
AllJavaTypes emptyValues = new AllJavaTypes();
emptyValues.setFieldId(1);
emptyValues.setFieldString("");
emptyValues.setFieldBinary(new byte[0]);
emptyValues.setFieldObject(emptyValues);
emptyValues.setFieldList(new RealmList<AllJavaTypes>());
realm.copyToRealm(emptyValues);
AllJavaTypes nonEmpty = new AllJavaTypes();
nonEmpty.setFieldId(2);
nonEmpty.setFieldString("Foo");
nonEmpty.setFieldBinary(new byte[] { 1, 2, 3 });
nonEmpty.setFieldObject(nonEmpty);
nonEmpty.setFieldList(new RealmList<AllJavaTypes>(emptyValues));
realm.copyToRealmOrUpdate(nonEmpty);
realm.commitTransaction();
}
Aggregations