Пример #1
0
  public void testContainsDoesNotContainAnItem() {
    RealmConfiguration realmConfig =
        TestHelper.createConfiguration(getContext(), "contains_test.realm");
    Realm.deleteRealm(realmConfig);
    Realm testRealmTwo = Realm.getInstance(realmConfig);
    try {

      testRealmTwo.beginTransaction();
      testRealmTwo.allObjects(AllTypes.class).clear();
      testRealmTwo.allObjects(NonLatinFieldNames.class).clear();

      for (int i = 0; i < TEST_DATA_SIZE; ++i) {
        AllTypes allTypes = testRealmTwo.createObject(AllTypes.class);
        allTypes.setColumnBoolean((i % 2) == 0);
        allTypes.setColumnBinary(new byte[] {1, 2, 3});
        allTypes.setColumnDate(new Date(YEAR_MILLIS * (i - TEST_DATA_SIZE / 2)));
        allTypes.setColumnDouble(3.1415 + i);
        allTypes.setColumnFloat(1.234567f + i);
        allTypes.setColumnString("test data " + i);
        allTypes.setColumnLong(i);
        Dog d = testRealmTwo.createObject(Dog.class);
        d.setName("Foo " + i);
        allTypes.setColumnRealmObject(d);
        allTypes.getColumnRealmList().add(d);
        NonLatinFieldNames nonLatinFieldNames = testRealmTwo.createObject(NonLatinFieldNames.class);
        nonLatinFieldNames.set델타(i);
        nonLatinFieldNames.setΔέλτα(i);
      }
      testRealmTwo.commitTransaction();

      final AllTypes item = testRealmTwo.where(AllTypes.class).findFirst();

      assertFalse(
          "Should not be able to find one object in another Realm via RealmResults#contains",
          testRealm.where(AllTypes.class).findAll().contains(item));

    } finally {
      if (testRealmTwo != null && !testRealmTwo.isClosed()) {
        testRealmTwo.close();
      }
    }
  }
Пример #2
0
  private void populateTestRealm(int objects) {
    testRealm.beginTransaction();
    testRealm.allObjects(AllTypes.class).clear();
    testRealm.allObjects(NonLatinFieldNames.class).clear();

    for (int i = 0; i < objects; ++i) {
      AllTypes allTypes = testRealm.createObject(AllTypes.class);
      allTypes.setColumnBoolean((i % 2) == 0);
      allTypes.setColumnBinary(new byte[] {1, 2, 3});
      allTypes.setColumnDate(new Date(YEAR_MILLIS * (i - objects / 2)));
      allTypes.setColumnDouble(3.1415 + i);
      allTypes.setColumnFloat(1.234567f + i);
      allTypes.setColumnString("test data " + i);
      allTypes.setColumnLong(i);
      Dog d = testRealm.createObject(Dog.class);
      d.setName("Foo " + i);
      allTypes.setColumnRealmObject(d);
      allTypes.getColumnRealmList().add(d);
      NonLatinFieldNames nonLatinFieldNames = testRealm.createObject(NonLatinFieldNames.class);
      nonLatinFieldNames.set델타(i);
      nonLatinFieldNames.setΔέλτα(i);
    }
    testRealm.commitTransaction();
  }