Search in sources :

Example 1 with RealmObjectWithRealmListOfRealmModel

use of io.realm.entities.pojo.RealmObjectWithRealmListOfRealmModel in project realm-java by realm.

the class RealmModelTests method realmObjectWithRealmListOfRealmModel.

// Tests the behaviour of a RealmObject, containing a RealmList
// of RealmModel, in managed and unmanaged mode.
@Test
public void realmObjectWithRealmListOfRealmModel() {
    RealmList<AllTypesRealmModel> allTypesRealmModel = new RealmList<AllTypesRealmModel>();
    AllTypesRealmModel allTypePojo;
    for (int i = 0; i < 10; i++) {
        allTypePojo = new AllTypesRealmModel();
        allTypePojo.columnLong = i;
        allTypesRealmModel.add(allTypePojo);
    }
    AllTypesRealmModel pojo1 = allTypesRealmModel.get(1);
    assertEquals(1, pojo1.columnLong);
    allTypesRealmModel.move(1, 0);
    assertEquals(0, allTypesRealmModel.indexOf(pojo1));
    RealmObjectWithRealmListOfRealmModel model = new RealmObjectWithRealmListOfRealmModel();
    model.setColumnRealmList(allTypesRealmModel);
    realm.beginTransaction();
    realm.copyToRealm(model);
    realm.commitTransaction();
    RealmResults<RealmObjectWithRealmListOfRealmModel> all = realm.where(RealmObjectWithRealmListOfRealmModel.class).findAll();
    assertEquals(1, all.size());
    assertEquals(10, all.first().getColumnRealmList().size());
    assertEquals(1, all.first().getColumnRealmList().first().columnLong);
}
Also used : AllTypesRealmModel(io.realm.entities.pojo.AllTypesRealmModel) RealmObjectWithRealmListOfRealmModel(io.realm.entities.pojo.RealmObjectWithRealmListOfRealmModel) Test(org.junit.Test)

Aggregations

AllTypesRealmModel (io.realm.entities.pojo.AllTypesRealmModel)1 RealmObjectWithRealmListOfRealmModel (io.realm.entities.pojo.RealmObjectWithRealmListOfRealmModel)1 Test (org.junit.Test)1