Search in sources :

Example 26 with Owner

use of io.realm.entities.Owner in project realm-java by realm.

the class RealmListTests method remove_byObject.

@Test
public void remove_byObject() {
    Owner owner = realm.where(Owner.class).findFirst();
    RealmList<Dog> dogs = owner.getDogs();
    Dog dog = dogs.get(0);
    realm.beginTransaction();
    boolean result = dogs.remove(dog);
    realm.commitTransaction();
    assertTrue(result);
    assertEquals(TEST_SIZE - 1, dogs.size());
    assertEquals(TEST_SIZE, realm.where(Dog.class).count());
}
Also used : Owner(io.realm.entities.Owner) Dog(io.realm.entities.Dog) Test(org.junit.Test)

Example 27 with Owner

use of io.realm.entities.Owner in project realm-java by realm.

the class RealmListTests method query.

@Test
public void query() {
    Owner owner = realm.where(Owner.class).findFirst();
    RealmList<Dog> dogs = owner.getDogs();
    Dog firstDog = dogs.where().equalTo("name", "Dog 0").findFirst();
    assertNotNull(firstDog);
}
Also used : Owner(io.realm.entities.Owner) Dog(io.realm.entities.Dog) Test(org.junit.Test)

Example 28 with Owner

use of io.realm.entities.Owner in project realm-java by realm.

the class RealmListTests method isValid.

/**
 *******************************************************
 * Managed mode tests                                    *
 ********************************************************
 */
@Test
public void isValid() {
    Owner owner = realm.where(Owner.class).findFirst();
    RealmList<Dog> dogs = owner.getDogs();
    assertTrue(dogs.isValid());
    realm.close();
    assertFalse(dogs.isValid());
}
Also used : Owner(io.realm.entities.Owner) Dog(io.realm.entities.Dog) Test(org.junit.Test)

Example 29 with Owner

use of io.realm.entities.Owner in project realm-java by realm.

the class RealmListTests method size.

@Test
public void size() {
    Owner owner = realm.where(Owner.class).findFirst();
    assertEquals(TEST_SIZE, owner.getDogs().size());
}
Also used : Owner(io.realm.entities.Owner) Test(org.junit.Test)

Example 30 with Owner

use of io.realm.entities.Owner in project realm-java by realm.

the class RealmListTests method createDeletedRealmList.

private RealmList<Dog> createDeletedRealmList() {
    Owner owner = realm.where(Owner.class).findFirst();
    // noinspection ConstantConditions
    RealmList<Dog> dogs = owner.getDogs();
    realm.beginTransaction();
    owner.deleteFromRealm();
    realm.commitTransaction();
    return dogs;
}
Also used : Owner(io.realm.entities.Owner) Dog(io.realm.entities.Dog)

Aggregations

Owner (io.realm.entities.Owner)36 Dog (io.realm.entities.Dog)30 Test (org.junit.Test)27 UiThreadTest (androidx.test.annotation.UiThreadTest)3 CatOwner (io.realm.entities.CatOwner)3 Date (java.util.Date)3 Cat (io.realm.entities.Cat)2 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)2 AllTypes (io.realm.entities.AllTypes)1 DictionaryAllTypes (io.realm.entities.DictionaryAllTypes)1 PrimaryKeyAsString (io.realm.entities.PrimaryKeyAsString)1 RealmBackgroundTask (io.realm.util.RealmBackgroundTask)1 BigDecimal (java.math.BigDecimal)1 SimpleDateFormat (java.text.SimpleDateFormat)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Decimal128 (org.bson.types.Decimal128)1 ObjectId (org.bson.types.ObjectId)1 Before (org.junit.Before)1