Search in sources :

Example 21 with CyclicType

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

the class RealmObjectTests method equals_unmanagedObject.

@Test
public void equals_unmanagedObject() {
    realm.beginTransaction();
    CyclicType ct1 = realm.createObject(CyclicType.class);
    ct1.setName("Foo");
    realm.commitTransaction();
    CyclicType ct2 = new CyclicType();
    ct2.setName("Bar");
    assertFalse(ct1.equals(ct2));
    assertFalse(ct2.equals(ct1));
}
Also used : CyclicType(io.realm.entities.CyclicType) Test(org.junit.Test)

Example 22 with CyclicType

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

the class RealmObjectTests method setter_list_withObjectFromAnotherRealm.

@Test
public void setter_list_withObjectFromAnotherRealm() {
    RealmConfiguration config = configFactory.createConfiguration("another.realm");
    Realm anotherRealm = Realm.getInstance(config);
    // noinspection TryFinallyCanBeTryWithResources
    try {
        anotherRealm.beginTransaction();
        CyclicType objFromAnotherRealm = anotherRealm.createObject(CyclicType.class);
        anotherRealm.commitTransaction();
        realm.beginTransaction();
        try {
            CyclicType target = realm.createObject(CyclicType.class);
            RealmList<CyclicType> list = new RealmList<CyclicType>();
            list.add(realm.createObject(CyclicType.class));
            // List contains an object from another Realm.
            list.add(objFromAnotherRealm);
            list.add(realm.createObject(CyclicType.class));
            try {
                target.setObjects(list);
                fail();
            } catch (IllegalArgumentException ignored) {
            }
        } finally {
            realm.cancelTransaction();
        }
    } finally {
        anotherRealm.close();
    }
}
Also used : CyclicType(io.realm.entities.CyclicType) Test(org.junit.Test)

Example 23 with CyclicType

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

the class RealmObjectTests method setter_link_objectFromAnotherThread.

@Test
public void setter_link_objectFromAnotherThread() throws InterruptedException {
    final CountDownLatch createLatch = new CountDownLatch(1);
    final CountDownLatch testEndLatch = new CountDownLatch(1);
    final AtomicReference<CyclicType> objFromAnotherThread = new AtomicReference<CyclicType>();
    java.lang.Thread thread = new java.lang.Thread() {

        @Override
        public void run() {
            Realm realm = Realm.getInstance(realmConfig);
            // 1. Creates an object.
            realm.beginTransaction();
            objFromAnotherThread.set(realm.createObject(CyclicType.class));
            realm.commitTransaction();
            createLatch.countDown();
            TestHelper.awaitOrFail(testEndLatch);
            // 3. Closes Realm in this thread and finishes.
            realm.close();
        }
    };
    thread.start();
    TestHelper.awaitOrFail(createLatch);
    // 2. Sets created object to target.
    realm.beginTransaction();
    try {
        CyclicType target = realm.createObject(CyclicType.class);
        try {
            target.setObject(objFromAnotherThread.get());
            fail();
        } catch (IllegalArgumentException ignored) {
        }
    } finally {
        testEndLatch.countDown();
        realm.cancelTransaction();
    }
    // Waits for finishing the thread.
    thread.join();
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) CyclicType(io.realm.entities.CyclicType) RunInLooperThread(io.realm.rule.RunInLooperThread) RunTestInLooperThread(io.realm.rule.RunTestInLooperThread) Test(org.junit.Test)

Example 24 with CyclicType

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

the class RealmObjectTests method setter_link_unmanagedObject.

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

Example 25 with CyclicType

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

the class RealmObjectTests method equals_differentObjects.

@Test
public void equals_differentObjects() {
    realm.beginTransaction();
    CyclicType objA = realm.createObject(CyclicType.class);
    objA.setName("Foo");
    CyclicType objB = realm.createObject(CyclicType.class);
    objB.setName("Bar");
    realm.commitTransaction();
    assertFalse(objA.equals(objB));
    assertFalse(objB.equals(objA));
}
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