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));
}
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();
}
}
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();
}
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();
}
}
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));
}
Aggregations