public void testRemoveLastEmptyList() { RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll(); testRealm.beginTransaction(); resultList.clear(); assertEquals(0, resultList.size()); resultList.removeLast(); testRealm.commitTransaction(); assertEquals(0, resultList.size()); }
public void testRemoveLast() { RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll(); testRealm.beginTransaction(); resultList.removeLast(); testRealm.commitTransaction(); assertEquals( "ResultList.removeLast did not remove record", TEST_DATA_SIZE - 1, resultList.size()); AllTypes allTypes = resultList.get(resultList.size() - 1); assertEquals( "ResultList.removeLast unexpected last record", TEST_DATA_SIZE - 2, allTypes.getColumnLong()); RealmResults<AllTypes> resultListCheck = testRealm.where(AllTypes.class).findAll(); assertEquals("ResultList.removeLast not committed", TEST_DATA_SIZE - 1, resultListCheck.size()); }
// Test that all methods that require a transaction (ie. any function that mutates Realm data) public void testMutableMethodsOutsideTransactions() { RealmResults<AllTypes> result = testRealm.where(AllTypes.class).findAll(); try { result.clear(); fail(); } catch (IllegalStateException ignored) { } try { result.remove(0); fail(); } catch (IllegalStateException ignored) { } try { result.removeLast(); fail(); } catch (IllegalStateException ignored) { } }