コード例 #1
0
  public void testGetItem() {
    RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();
    RealmAdapter realmAdapter = new RealmAdapter(getContext(), resultList, automaticUpdate);

    assertEquals(resultList.get(0).getColumnString(), realmAdapter.getItem(0).getColumnString());
    assertEquals(resultList.size(), realmAdapter.getRealmResults().size());
    assertEquals(
        resultList.last().getColumnString(),
        realmAdapter.getRealmResults().last().getColumnString());
  }
コード例 #2
0
 public void testEmptyRealmResult() {
   RealmResults<AllTypes> resultList =
       testRealm.where(AllTypes.class).equalTo(FIELD_STRING, "Not there").findAll();
   RealmAdapter realmAdapter = new RealmAdapter(getContext(), resultList, automaticUpdate);
   assertEquals(0, realmAdapter.getRealmResults().size());
   assertEquals(0, realmAdapter.getCount());
 }
コード例 #3
0
  public void testSortWithAdapter() {
    RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();
    resultList.sort(FIELD_STRING, RealmResults.SORT_ORDER_DESCENDING);
    RealmAdapter realmAdapter = new RealmAdapter(getContext(), resultList, automaticUpdate);
    assertEquals(
        resultList.first().getColumnString(),
        realmAdapter.getRealmResults().first().getColumnString());
    assertEquals(resultList.size(), realmAdapter.getRealmResults().size());

    resultList.sort(FIELD_STRING);

    assertEquals(
        resultList.last().getColumnString(),
        realmAdapter.getRealmResults().last().getColumnString());
    assertEquals(
        resultList.get(TEST_DATA_SIZE / 2).getColumnString(),
        realmAdapter.getRealmResults().get(TEST_DATA_SIZE / 2).getColumnString());
    assertEquals(resultList.size(), realmAdapter.getRealmResults().size());
  }
コード例 #4
0
  public void testClearFromAdapter() {
    RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();
    RealmAdapter realmAdapter = new RealmAdapter(getContext(), resultList, automaticUpdate);

    testRealm.beginTransaction();
    realmAdapter.getRealmResults().clear();
    testRealm.commitTransaction();

    assertEquals(0, realmAdapter.getCount());
    assertEquals(0, resultList.size());
  }
コード例 #5
0
  public void testRemoveFromAdapter() {
    RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();
    RealmAdapter realmAdapter = new RealmAdapter(getContext(), resultList, automaticUpdate);

    testRealm.beginTransaction();
    realmAdapter.getRealmResults().remove(0);
    testRealm.commitTransaction();
    assertEquals(TEST_DATA_SIZE - 1, realmAdapter.getCount());

    resultList = testRealm.where(AllTypes.class).equalTo(FIELD_STRING, "test data 0").findAll();
    assertEquals(0, resultList.size());
  }
コード例 #6
0
  public void testUpdateRealmResultInAdapter() {
    RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();
    resultList.sort(FIELD_STRING);
    RealmAdapter realmAdapter = new RealmAdapter(getContext(), resultList, false);
    assertEquals(
        resultList.first().getColumnString(),
        realmAdapter.getRealmResults().first().getColumnString());
    assertEquals(resultList.size(), realmAdapter.getRealmResults().size());

    testRealm.beginTransaction();
    AllTypes allTypes = testRealm.createObject(AllTypes.class);
    allTypes.setColumnString("test data " + TEST_DATA_SIZE);
    testRealm.commitTransaction();
    assertEquals(
        resultList.last().getColumnString(),
        realmAdapter.getRealmResults().last().getColumnString());
    assertEquals(resultList.size(), realmAdapter.getRealmResults().size());

    RealmResults<AllTypes> emptyResultList =
        testRealm.where(AllTypes.class).equalTo(FIELD_STRING, "Not there").findAll();
    realmAdapter.updateRealmResults(emptyResultList);
    assertEquals(emptyResultList.size(), realmAdapter.getRealmResults().size());
  }