RealmList.delete*() must delete target objects in addition to removing them from the list.
Due to a bug introduced our refactoring introduced in 3.7.1, RealmList.delete*() (except for deleteAllFromRealm()) only remove the target objects from the list and target objects still remain in the database.
Following test exposes the bug.
@Test
public void deleteFromRealm() {
Owner owner = realm.where(Owner.class).findFirst();
//noinspection ConstantConditions
RealmList<Dog> dogs = owner.getDogs();
assertEquals(TEST_SIZE, dogs.size());
int expectedSize = TEST_SIZE;
realm.beginTransaction();
dogs.deleteFromRealm(TEST_SIZE / 2);
expectedSize--;
realm.commitTransaction();
assertEquals(expectedSize, dogs.size());
assertEquals(expectedSize, realm.where(Dog.class).count());
realm.beginTransaction();
dogs.deleteFromRealm(0);
expectedSize--;
realm.commitTransaction();
assertEquals(expectedSize, dogs.size());
assertEquals(expectedSize, realm.where(Dog.class).count());
realm.beginTransaction();
dogs.deleteFromRealm(dogs.size() - 1);
expectedSize--;
realm.commitTransaction();
assertEquals(expectedSize, dogs.size());
assertEquals(expectedSize, realm.where(Dog.class).count());
}
@Test
public void deleteFirstFromRealm() {
Owner owner = realm.where(Owner.class).findFirst();
//noinspection ConstantConditions
RealmList<Dog> dogs = owner.getDogs();
assertEquals(TEST_SIZE, dogs.size());
realm.beginTransaction();
dogs.deleteFirstFromRealm();
realm.commitTransaction();
assertEquals(TEST_SIZE - 1, dogs.size());
assertEquals(TEST_SIZE - 1, realm.where(Dog.class).count());
}
@Test
public void deleteLastFromRealm() {
Owner owner = realm.where(Owner.class).findFirst();
//noinspection ConstantConditions
RealmList<Dog> dogs = owner.getDogs();
assertEquals(TEST_SIZE, dogs.size());
realm.beginTransaction();
dogs.deleteLastFromRealm();
realm.commitTransaction();
assertEquals(TEST_SIZE - 1, dogs.size());
assertEquals(TEST_SIZE - 1, realm.where(Dog.class).count());
}
And the result is:
io.realm.RealmListTests > deleteLastFromRealm[Nexus_5X_API_21(AVD) - 5.0.2] FAILED
java.lang.AssertionError: expected:<9> but was:<10>
at org.junit.Assert.fail(Assert.java:88)
io.realm.RealmListTests > deleteFirstFromRealm[Nexus_5X_API_21(AVD) - 5.0.2] FAILED
java.lang.AssertionError: expected:<9> but was:<10>
at org.junit.Assert.fail(Assert.java:88)
io.realm.RealmListTests > deleteFromRealm[Nexus_5X_API_21(AVD) - 5.0.2] FAILED
java.lang.AssertionError: expected:<9> but was:<10>
at org.junit.Assert.fail(Assert.java:88)
RealmList.delete*()must delete target objects in addition to removing them from the list.Due to a bug introduced our refactoring introduced in
3.7.1,RealmList.delete*()(except fordeleteAllFromRealm()) only remove the target objects from the list and target objects still remain in the database.Following test exposes the bug.
And the result is: