Search in sources :

Example 1 with CyclicType

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

the class DynamicRealmObjectTests method untypedSetter_listMixedTypesThrows.

@Test
public void untypedSetter_listMixedTypesThrows() {
    realm.beginTransaction();
    AllJavaTypes obj1 = realm.createObject(AllJavaTypes.class, 2);
    CyclicType obj2 = realm.createObject(CyclicType.class);
    RealmList<DynamicRealmObject> list = new RealmList<DynamicRealmObject>();
    list.add(new DynamicRealmObject(obj1));
    list.add(new DynamicRealmObject(obj2));
    thrown.expect(IllegalArgumentException.class);
    dObjTyped.set(AllJavaTypes.FIELD_LIST, list);
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) CyclicType(io.realm.entities.CyclicType) Test(org.junit.Test)

Example 2 with CyclicType

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

the class DynamicRealmObjectTests method untypedSetter_listRealmAnyTypesThrows.

@Test
public void untypedSetter_listRealmAnyTypesThrows() {
    realm.beginTransaction();
    AllJavaTypes obj1 = realm.createObject(AllJavaTypes.class, 2);
    CyclicType obj2 = realm.createObject(CyclicType.class);
    RealmList<DynamicRealmObject> list = new RealmList<DynamicRealmObject>();
    list.add(new DynamicRealmObject(obj1));
    list.add(new DynamicRealmObject(obj2));
    thrown.expect(IllegalArgumentException.class);
    dObjTyped.set(AllJavaTypes.FIELD_LIST, list);
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) CyclicType(io.realm.entities.CyclicType) Test(org.junit.Test)

Example 3 with CyclicType

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

the class BulkInsertTests method insert_cyclicType.

@Test
public void insert_cyclicType() {
    CyclicType oneCyclicType = new CyclicType();
    oneCyclicType.setName("One");
    CyclicType anotherCyclicType = new CyclicType();
    anotherCyclicType.setName("Two");
    oneCyclicType.setObject(anotherCyclicType);
    anotherCyclicType.setObject(oneCyclicType);
    realm.beginTransaction();
    realm.insert(Arrays.asList(oneCyclicType, anotherCyclicType));
    realm.commitTransaction();
    RealmResults<CyclicType> realmObjects = realm.where(CyclicType.class).sort(CyclicType.FIELD_NAME).findAll();
    assertNotNull(realmObjects);
    assertEquals(2, realmObjects.size());
    assertEquals("One", realmObjects.get(0).getName());
    assertEquals("Two", realmObjects.get(0).getObject().getName());
}
Also used : CyclicType(io.realm.entities.CyclicType) Test(org.junit.Test)

Example 4 with CyclicType

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

the class RealmListTests method setList_clearsOldItems.

@Test
public void setList_clearsOldItems() {
    realm.beginTransaction();
    CyclicType one = realm.copyToRealm(new CyclicType());
    CyclicType two = realm.copyToRealm(new CyclicType());
    assertEquals(0, two.getObjects().size());
    two.setObjects(new RealmList<CyclicType>(one));
    assertEquals(1, two.getObjects().size());
    two.setObjects(new RealmList<CyclicType>(one, two));
    assertEquals(2, two.getObjects().size());
}
Also used : CyclicType(io.realm.entities.CyclicType) Test(org.junit.Test)

Example 5 with CyclicType

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

the class RealmListTests method add_unmanagedObjectToManagedList.

// Tests that add correctly uses Realm.copyToRealm() on unmanaged objects.
@Test
public void add_unmanagedObjectToManagedList() {
    realm.beginTransaction();
    CyclicType parent = realm.createObject(CyclicType.class);
    RealmList<CyclicType> children = parent.getObjects();
    children.add(new CyclicType());
    realm.commitTransaction();
    assertEquals(1, realm.where(CyclicType.class).findFirst().getObjects().size());
}
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