use of io.realm.entities.CyclicType in project realm-java by realm.
the class RealmTests method copyFromRealm_sameObjectDifferentDepths.
// Tests that depth restriction is calculated from the top-most encountered object, i.e. it is possible for some
// objects to exceed the depth limit.
// A -> B -> C -> D -> E
// A -> D -> E
// D is both at depth 1 and 3. For maxDepth = 3, E should still be copied.
@Test
public void copyFromRealm_sameObjectDifferentDepths() {
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");
CyclicType objD = realm.createObject(CyclicType.class);
objD.setName("D");
CyclicType objE = realm.createObject(CyclicType.class);
objE.setName("E");
objA.setObject(objB);
objB.setObject(objC);
objC.setObject(objD);
objD.setObject(objE);
objA.setOtherObject(objD);
realm.commitTransaction();
// Object is filled before otherObject. (because of field order - WARNING: Not guaranteed)
// This means that the object will be encountered first time at max depth, so E will not be copied.
// If the object cache does not handle this, otherObject will be wrong.
CyclicType copyA = realm.copyFromRealm(objA, 3);
assertEquals("E", copyA.getOtherObject().getObject().getName());
}
use of io.realm.entities.CyclicType in project realm-java by realm.
the class RealmTests method copyFromRealm_cyclicObjectGraph.
// Tests that the object graph is copied as it is and no extra copies are made.
// 1) (A -> B/[B,C])
// 2) (C -> B/[B,A])
// A copy should result in only 3 distinct objects.
@Test
public void copyFromRealm_cyclicObjectGraph() {
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(objB);
objA.getObjects().add(objB);
objA.getObjects().add(objC);
objC.getObjects().add(objB);
objC.getObjects().add(objA);
realm.commitTransaction();
CyclicType copyA = realm.copyFromRealm(objA);
CyclicType copyB = copyA.getObject();
CyclicType copyC = copyA.getObjects().get(1);
assertEquals("A", copyA.getName());
assertEquals("B", copyB.getName());
assertEquals("C", copyC.getName());
// Asserts object equality on the object graph.
assertTrue(copyA.getObject() == copyC.getObject());
assertTrue(copyA.getObjects().get(0) == copyC.getObjects().get(0));
assertTrue(copyA == copyC.getObjects().get(1));
assertTrue(copyC == copyA.getObjects().get(1));
}
use of io.realm.entities.CyclicType in project realm-java by realm.
the class RxJavaTests method wrongGenericClassThrows.
@Test
@RunTestInLooperThread
public void wrongGenericClassThrows() {
realm.beginTransaction();
final AllTypes obj = realm.createObject(AllTypes.class);
realm.commitTransaction();
Flowable<CyclicType> obs = obj.asFlowable();
subscription = obs.subscribe(cyclicType -> fail(), ignoredError -> {
disposeSuccessfulTest(realm);
});
}
use of io.realm.entities.CyclicType in project realm-java by realm.
the class RealmListTests method set_unmanagedObjectToManagedList.
// Tests that set correctly uses Realm.copyToRealm() on unmanaged objects.
@Test
public void set_unmanagedObjectToManagedList() {
realm.beginTransaction();
CyclicType parent = realm.copyToRealm(new CyclicType("Parent"));
RealmList<CyclicType> children = parent.getObjects();
children.add(new CyclicType());
children.add(new CyclicType("original"));
children.add(new CyclicType());
children.set(1, new CyclicType("updated"));
realm.commitTransaction();
RealmList<CyclicType> list = realm.where(CyclicType.class).findFirst().getObjects();
assertEquals(3, list.size());
assertEquals("updated", list.get(1).getName());
assertEquals(5, realm.where(CyclicType.class).count());
}
use of io.realm.entities.CyclicType in project realm-java by realm.
the class RealmObjectTests method setter_list_withClosedObject.
@Test
public void setter_list_withClosedObject() {
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);
RealmList<CyclicType> list = new RealmList<CyclicType>();
list.add(realm.createObject(CyclicType.class));
// List contains a closed object.
list.add(closed);
list.add(realm.createObject(CyclicType.class));
try {
target.setObjects(list);
fail();
} catch (IllegalArgumentException ignored) {
}
} finally {
realm.cancelTransaction();
}
}
Aggregations