Search in sources :

Example 11 with CyclicType

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

the class RealmObjectTests method setter_link_deletedObject.

@Test
public void setter_link_deletedObject() {
    realm.beginTransaction();
    try {
        CyclicType target = realm.createObject(CyclicType.class);
        CyclicType removed = realm.createObject(CyclicType.class);
        removed.deleteFromRealm();
        try {
            target.setObject(removed);
            fail();
        } catch (IllegalArgumentException ignored) {
        }
    } finally {
        realm.cancelTransaction();
    }
}
Also used : CyclicType(io.realm.entities.CyclicType) Test(org.junit.Test)

Example 12 with CyclicType

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

the class RealmObjectTests method toString_cyclicObject.

@Test
public void toString_cyclicObject() {
    realm.beginTransaction();
    CyclicType foo = createCyclicData();
    realm.commitTransaction();
    assertEquals("CyclicType = proxy[{id:0},{name:Foo},{date:null},{object:CyclicType},{otherObject:null},{objects:RealmList<CyclicType>[0]}]", foo.toString());
}
Also used : CyclicType(io.realm.entities.CyclicType) Test(org.junit.Test)

Example 13 with CyclicType

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

the class RealmObjectTests method setter_link_closedObject.

@Test
public void setter_link_closedObject() {
    realm.beginTransaction();
    CyclicType closed = realm.createObject(CyclicType.class);
    realm.commitTransaction();
    realm.close();
    assertTrue(realm.isClosed());
    realm = Realm.getInstance(realmConfig);
    realm.beginTransaction();
    try {
        CyclicType target = realm.createObject(CyclicType.class);
        try {
            target.setObject(closed);
            fail();
        } catch (IllegalArgumentException ignored) {
        }
    } finally {
        realm.cancelTransaction();
    }
}
Also used : CyclicType(io.realm.entities.CyclicType) Test(org.junit.Test)

Example 14 with CyclicType

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

the class CollectionTests method populateCollectionOnDeletedLinkView.

// Creates a collection that is based on a RealmList that was deleted.
protected OrderedRealmCollection<CyclicType> populateCollectionOnDeletedLinkView(Realm realm, ManagedCollection collectionClass) {
    realm.beginTransaction();
    CyclicType parent = realm.createObject(CyclicType.class);
    for (int i = 0; i < 10; i++) {
        CyclicType child = new CyclicType();
        child.setName("name_" + i);
        child.setObject(parent);
        parent.getObjects().add(child);
    }
    realm.commitTransaction();
    OrderedRealmCollection<CyclicType> result;
    switch(collectionClass) {
        case MANAGED_REALMLIST:
            result = parent.getObjects();
            break;
        case REALMRESULTS:
            result = parent.getObjects().where().equalTo(CyclicType.FIELD_NAME, "name_0").findAll();
            break;
        default:
            throw new AssertionError("Unknown collection: " + collectionClass);
    }
    realm.beginTransaction();
    parent.deleteFromRealm();
    realm.commitTransaction();
    return result;
}
Also used : CyclicType(io.realm.entities.CyclicType)

Example 15 with CyclicType

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

the class RealmTests method copyFromRealm_checkMaxDepth.

// Tests that for (A -> B -> C) for maxDepth = 1, result is (A -> B -> null).
@Test
public void copyFromRealm_checkMaxDepth() {
    realm.beginTransaction();
    CyclicType objA = realm.createObject(CyclicType.class);
    objA.setName("A");
    CyclicType objB = realm.createObject(CyclicType.class);
    objB.setName("B");
    CyclicType objC = realm.createObject(CyclicType.class);
    objC.setName("C");
    objA.setObject(objB);
    objC.setObject(objC);
    objA.getObjects().add(objB);
    objA.getObjects().add(objC);
    realm.commitTransaction();
    CyclicType copyA = realm.copyFromRealm(objA, 1);
    assertNull(copyA.getObject().getObject());
}
Also used : CyclicType(io.realm.entities.CyclicType) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

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