Search in sources :

Example 61 with AllJavaTypes

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());
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 62 with AllJavaTypes

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());
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 63 with AllJavaTypes

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());
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 64 with AllJavaTypes

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());
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) Test(org.junit.Test)

Example 65 with AllJavaTypes

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();
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes)

Aggregations

AllJavaTypes (io.realm.entities.AllJavaTypes)90 Test (org.junit.Test)78 UiThreadTest (android.support.test.annotation.UiThreadTest)24 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 Date (java.util.Date)5 RealmException (io.realm.exceptions.RealmException)4 Ignore (org.junit.Ignore)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutionException (java.util.concurrent.ExecutionException)2 ExecutorService (java.util.concurrent.ExecutorService)2 ExpectedException (org.junit.rules.ExpectedException)2 Pair (android.util.Pair)1 CyclicType (io.realm.entities.CyclicType)1 Dog (io.realm.entities.Dog)1 NonLatinFieldNames (io.realm.entities.NonLatinFieldNames)1 PrimaryKeyAsString (io.realm.entities.PrimaryKeyAsString)1 RealmPrimaryKeyConstraintException (io.realm.exceptions.RealmPrimaryKeyConstraintException)1 RunInLooperThread (io.realm.rule.RunInLooperThread)1 Field (java.lang.reflect.Field)1