use of io.realm.rule.RunTestInLooperThread in project realm-java by realm.
the class RealmObjectTests method removeChangeListener_throwOnUnmanagedObject.
@Test
@RunTestInLooperThread
public void removeChangeListener_throwOnUnmanagedObject() {
Dog dog = new Dog();
RealmChangeListener listener = new RealmChangeListener<Dog>() {
@Override
public void onChange(Dog object) {
}
};
RealmObjectChangeListener objectChangeListener = new RealmObjectChangeListener<Dog>() {
@Override
public void onChange(Dog object, ObjectChangeSet changeSet) {
}
};
try {
dog.removeChangeListener(listener);
fail("Failed to remove a listener from null Realm.");
} catch (IllegalArgumentException ignore) {
}
try {
dog.removeChangeListener(objectChangeListener);
fail("Failed to remove a listener from null Realm.");
} catch (IllegalArgumentException ignore) {
}
looperThread.testComplete();
}
use of io.realm.rule.RunTestInLooperThread in project realm-java by realm.
the class RealmObjectTests method removeChangeListener_throwOnRemovingNullListenerFromLooperThread.
@Test
@RunTestInLooperThread
public void removeChangeListener_throwOnRemovingNullListenerFromLooperThread() {
final Realm realm = looperThread.getRealm();
Dog dog = createManagedDogObjectFromRealmInstance(realm);
try {
dog.removeChangeListener((RealmChangeListener) null);
fail("removing null change listener must throw an exception.");
} catch (IllegalArgumentException ignore) {
}
try {
dog.removeChangeListener((RealmObjectChangeListener) null);
fail("removing null change listener must throw an exception.");
} catch (IllegalArgumentException ignore) {
}
looperThread.testComplete();
}
use of io.realm.rule.RunTestInLooperThread in project realm-java by realm.
the class RealmObjectTests method removeAllChangeListeners.
/**
* This test is to see if RealmObject.removeChangeListeners() works as it is intended.
*/
@Test
@RunTestInLooperThread
public void removeAllChangeListeners() {
final Realm realm = looperThread.getRealm();
realm.beginTransaction();
Dog dog = realm.createObject(Dog.class);
dog.setAge(13);
realm.commitTransaction();
dog.addChangeListener(new RealmChangeListener<Dog>() {
@Override
public void onChange(Dog object) {
fail();
}
});
dog.addChangeListener(new RealmObjectChangeListener<Dog>() {
@Override
public void onChange(Dog object, ObjectChangeSet changeSet) {
fail();
}
});
dog.removeAllChangeListeners();
realm.beginTransaction();
Dog sameDog = realm.where(Dog.class).equalTo(Dog.FIELD_AGE, 13).findFirst();
sameDog.setName("Jesper");
realm.commitTransaction();
// Try to trigger the listeners.
realm.sharedRealm.refresh();
looperThread.testComplete();
}
use of io.realm.rule.RunTestInLooperThread in project realm-java by realm.
the class RealmObjectTests method removeAllChangeListeners_thenAdd.
@Test
@RunTestInLooperThread
public void removeAllChangeListeners_thenAdd() {
final Realm realm = looperThread.getRealm();
realm.beginTransaction();
Dog dog = realm.createObject(Dog.class);
dog.setAge(13);
realm.commitTransaction();
dog.addChangeListener(new RealmChangeListener<Dog>() {
@Override
public void onChange(Dog object) {
fail();
}
});
dog.removeAllChangeListeners();
dog.addChangeListener(new RealmChangeListener<Dog>() {
@Override
public void onChange(Dog dog) {
assertEquals(14, dog.getAge());
looperThread.testComplete();
}
});
realm.beginTransaction();
dog.setAge(14);
realm.commitTransaction();
}
use of io.realm.rule.RunTestInLooperThread in project realm-java by realm.
the class RealmObjectTests method changeListener_triggeredWhenObjectIsDeleted.
@Test
@RunTestInLooperThread
public void changeListener_triggeredWhenObjectIsDeleted() {
final Realm realm = looperThread.getRealm();
realm.beginTransaction();
AllTypes obj = realm.createObject(AllTypes.class);
realm.commitTransaction();
obj.addChangeListener(new RealmChangeListener<AllTypes>() {
@Override
public void onChange(AllTypes obj) {
assertFalse(obj.isValid());
looperThread.testComplete();
}
});
realm.beginTransaction();
obj.deleteFromRealm();
realm.commitTransaction();
}
Aggregations