예제 #1
0
  public void testRemove() {
    RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();
    testRealm.beginTransaction();
    resultList.remove(0);
    testRealm.commitTransaction();

    assertEquals(TEST_DATA_SIZE - 1, resultList.size());

    AllTypes allTypes = resultList.get(0);
    assertEquals(1, allTypes.getColumnLong());
  }
예제 #2
0
  // 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) {
    }
  }