Search in sources :

Example 31 with CyclicType

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

the class RealmObjectTests method createCyclicData.

private CyclicType createCyclicData(Realm realm) {
    CyclicType foo = realm.createObject(CyclicType.class);
    foo.setName("Foo");
    CyclicType bar = realm.createObject(CyclicType.class);
    bar.setName("Bar");
    // Setups cycle on normal object references.
    foo.setObject(bar);
    bar.setObject(foo);
    return foo;
}
Also used : CyclicType(io.realm.entities.CyclicType)

Example 32 with CyclicType

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

the class RealmObjectTests method equals_afterModification.

@Test
public void equals_afterModification() {
    realm.beginTransaction();
    CyclicType ct = realm.createObject(CyclicType.class);
    ct.setName("Foo");
    realm.commitTransaction();
    CyclicType ct1 = realm.where(CyclicType.class).findFirst();
    CyclicType ct2 = realm.where(CyclicType.class).findFirst();
    realm.beginTransaction();
    ct1.setName("Baz");
    realm.commitTransaction();
    assertTrue(ct1.equals(ct2));
    assertTrue(ct2.equals(ct1));
}
Also used : CyclicType(io.realm.entities.CyclicType) Test(org.junit.Test)

Example 33 with CyclicType

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

the class RealmObjectTests method setter_list_withDeletedObject.

@Test
public void setter_list_withDeletedObject() {
    realm.beginTransaction();
    try {
        CyclicType target = realm.createObject(CyclicType.class);
        CyclicType removed = realm.createObject(CyclicType.class);
        removed.deleteFromRealm();
        RealmList<CyclicType> list = new RealmList<CyclicType>();
        list.add(realm.createObject(CyclicType.class));
        // List contains a deleted object.
        list.add(removed);
        list.add(realm.createObject(CyclicType.class));
        try {
            target.setObjects(list);
            fail();
        } catch (IllegalArgumentException ignored) {
        }
    } finally {
        realm.cancelTransaction();
    }
}
Also used : CyclicType(io.realm.entities.CyclicType) Test(org.junit.Test)

Example 34 with CyclicType

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

the class RealmObjectTests method setter_link_null.

@Test
public void setter_link_null() {
    realm.beginTransaction();
    CyclicType objA = realm.createObject(CyclicType.class);
    objA.setName("Foo");
    CyclicType objB = realm.createObject(CyclicType.class);
    objB.setName("Bar");
    objA.setObject(objB);
    assertNotNull(objA.getObject());
    try {
        objA.setObject(null);
    } catch (NullPointerException nullPointer) {
        fail();
    }
    realm.commitTransaction();
    assertNull(objA.getObject());
}
Also used : CyclicType(io.realm.entities.CyclicType) Test(org.junit.Test)

Aggregations

CyclicType (io.realm.entities.CyclicType)34 Test (org.junit.Test)32 UiThreadTest (androidx.test.annotation.UiThreadTest)7 AllJavaTypes (io.realm.entities.AllJavaTypes)3 RunInLooperThread (io.realm.rule.RunInLooperThread)3 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 SystemClock (android.os.SystemClock)1 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)1 Flowable (io.reactivex.Flowable)1 Disposable (io.reactivex.disposables.Disposable)1 Consumer (io.reactivex.functions.Consumer)1 Schedulers (io.reactivex.schedulers.Schedulers)1 AllTypes (io.realm.entities.AllTypes)1 Dog (io.realm.entities.Dog)1 PrimaryKeyAsString (io.realm.entities.PrimaryKeyAsString)1 Pair (io.realm.internal.util.Pair)1 RealmLog (io.realm.log.RealmLog)1 SimpleDateFormat (java.text.SimpleDateFormat)1