Search in sources :

Example 6 with AllJavaTypes

use of io.realm.entities.AllJavaTypes in project realm-java by realm.

the class RealmCollectionTests method contains.

@Test
public void contains() {
    AllJavaTypes obj = collection.iterator().next();
    assertTrue(collection.contains(obj));
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) Test(org.junit.Test)

Example 7 with AllJavaTypes

use of io.realm.entities.AllJavaTypes in project realm-java by realm.

the class RealmCollectionTests method contains_realmObjectFromOtherRealm.

@Test
public void contains_realmObjectFromOtherRealm() {
    Realm realm2 = Realm.getInstance(configFactory.createConfiguration("other_realm.realm"));
    populateRealm(realm2, TEST_SIZE);
    AllJavaTypes otherRealmObj = realm2.where(AllJavaTypes.class).equalTo(AllJavaTypes.FIELD_LONG, 0).findFirst();
    try {
        assertFalse(collection.contains(otherRealmObj));
    } finally {
        realm2.close();
    }
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) Test(org.junit.Test)

Example 8 with AllJavaTypes

use of io.realm.entities.AllJavaTypes in project realm-java by realm.

the class OrderedRealmCollectionIteratorTests method listIterator_remove_nonRealmList_throwUnsupported.

@Test
public void listIterator_remove_nonRealmList_throwUnsupported() {
    if (skipTest(CollectionClass.MANAGED_REALMLIST, CollectionClass.UNMANAGED_REALMLIST)) {
        return;
    }
    ListIterator<AllJavaTypes> it = collection.listIterator();
    AllJavaTypes obj = it.next();
    assertEquals("test data 0", obj.getFieldString());
    realm.beginTransaction();
    thrown.expect(UnsupportedOperationException.class);
    it.remove();
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 9 with AllJavaTypes

use of io.realm.entities.AllJavaTypes in project realm-java by realm.

the class OrderedRealmCollectionIteratorTests method iterator.

@Test
public void iterator() {
    Iterator<AllJavaTypes> it = collection.iterator();
    int i = 0;
    while (it.hasNext()) {
        AllJavaTypes item = it.next();
        assertEquals("Failed at index: " + i, i, item.getFieldLong());
        i++;
    }
    assertEquals(TEST_SIZE, collection.size());
    assertEquals(TEST_SIZE, i);
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 10 with AllJavaTypes

use of io.realm.entities.AllJavaTypes in project realm-java by realm.

the class OrderedRealmCollectionIteratorTests method useCase_forEachIterator_modifyQueryResult_outerTransaction.

@Test
public void useCase_forEachIterator_modifyQueryResult_outerTransaction() {
    if (skipTest(CollectionClass.MANAGED_REALMLIST, CollectionClass.UNMANAGED_REALMLIST)) {
        return;
    }
    assertEquals(TEST_SIZE, collection.size());
    realm.beginTransaction();
    for (AllJavaTypes obj : collection) {
        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());
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

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