Esempio n. 1
0
 public void testGetItemId() {
   RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();
   RealmAdapter realmAdapter = new RealmAdapter(getContext(), resultList, automaticUpdate);
   for (int i = 0; i < resultList.size(); i++) {
     assertEquals(i, realmAdapter.getItemId(i));
   }
 }
Esempio n. 2
0
  public void testNullToNonNullResults() {
    RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();
    RealmAdapter realmAdapter = new RealmAdapter(getContext(), null, automaticUpdate);
    realmAdapter.updateRealmResults(resultList);

    assertEquals(TEST_DATA_SIZE, realmAdapter.getCount());
  }
Esempio n. 3
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());
 }
Esempio n. 4
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());
  }
Esempio n. 5
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());
  }
Esempio n. 6
0
  public void testGetView() {
    RealmResults<AllTypes> resultList = testRealm.where(AllTypes.class).findAll();
    RealmAdapter realmAdapter = new RealmAdapter(getContext(), resultList, automaticUpdate);
    View view = realmAdapter.getView(0, null, null);

    TextView name = (TextView) view.findViewById(android.R.id.text1);

    assertNotNull(view);
    assertNotNull(name);
    assertEquals(resultList.get(0).getColumnString(), name.getText());
  }
Esempio n. 7
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());
  }
Esempio n. 8
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());
  }
Esempio n. 9
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());
  }
Esempio n. 10
0
  public void testNullResults() {
    RealmAdapter realmAdapter = new RealmAdapter(getContext(), null, automaticUpdate);

    assertEquals(0, realmAdapter.getCount());
  }