Search in sources :

Example 1 with Dog

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

the class RealmListTests method removeAllFromRealm_outsideTransaction.

@Test
public void removeAllFromRealm_outsideTransaction() {
    Owner owner = realm.where(Owner.class).findFirst();
    RealmList<Dog> dogs = owner.getDogs();
    try {
        dogs.deleteAllFromRealm();
        fail("removeAllFromRealm should be called in a transaction.");
    } catch (IllegalStateException e) {
        assertEquals("Changing Realm data can only be done from inside a write transaction.", e.getMessage());
    }
}
Also used : Owner(io.realm.entities.Owner) Dog(io.realm.entities.Dog) Test(org.junit.Test)

Example 2 with Dog

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

the class RealmListTests method removeAllFromRealm.

@Test
public void removeAllFromRealm() {
    Owner owner = realm.where(Owner.class).findFirst();
    RealmList<Dog> dogs = owner.getDogs();
    assertEquals(TEST_SIZE, dogs.size());
    realm.beginTransaction();
    dogs.deleteAllFromRealm();
    realm.commitTransaction();
    assertEquals(0, dogs.size());
    assertEquals(0, realm.where(Dog.class).count());
}
Also used : Owner(io.realm.entities.Owner) Dog(io.realm.entities.Dog) Test(org.junit.Test)

Example 3 with Dog

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

the class RxJavaTests method realmList_closeInDoOnUnsubscribe.

@Test
@UiThreadTest
public void realmList_closeInDoOnUnsubscribe() {
    realm.beginTransaction();
    RealmList<Dog> list = realm.createObject(AllTypes.class).getColumnRealmList();
    realm.commitTransaction();
    Observable<RealmList<Dog>> observable = list.asObservable().doOnUnsubscribe(new Action0() {

        @Override
        public void call() {
            realm.close();
        }
    });
    subscription = observable.subscribe(new Action1<RealmList<Dog>>() {

        @Override
        public void call(RealmList<Dog> dogs) {
        }
    });
    subscription.unsubscribe();
    assertTrue(realm.isClosed());
}
Also used : Action0(rx.functions.Action0) Action1(rx.functions.Action1) AllTypes(io.realm.entities.AllTypes) Dog(io.realm.entities.Dog) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) UiThreadTest(android.support.test.annotation.UiThreadTest)

Example 4 with Dog

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

the class OrderedCollectionChangeSetTests method reorderRealmList.

// Re-adds the dogs so they would be sorted by age in the list.
private void reorderRealmList(Realm realm) {
    RealmResults<Dog> dogs = realm.where(Dog.class).findAllSorted(Dog.FIELD_AGE);
    Owner owner = realm.where(Owner.class).findFirst();
    owner.getDogs().clear();
    for (Dog dog : dogs) {
        owner.getDogs().add(dog);
    }
}
Also used : Owner(io.realm.entities.Owner) Dog(io.realm.entities.Dog)

Example 5 with Dog

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

the class DynamicRealmObjectTests method getList.

// List is not a simple getter, tests separately.
@Test
public void getList() {
    realm.beginTransaction();
    AllTypes obj = realm.createObject(AllTypes.class);
    Dog dog = realm.createObject(Dog.class);
    dog.setName("fido");
    obj.getColumnRealmList().add(dog);
    realm.commitTransaction();
    DynamicRealmObject dynamicAllTypes = new DynamicRealmObject(obj);
    RealmList<DynamicRealmObject> list = dynamicAllTypes.getList(AllTypes.FIELD_REALMLIST);
    DynamicRealmObject listObject = list.get(0);
    assertEquals(1, list.size());
    assertEquals(Dog.CLASS_NAME, listObject.getType());
    assertEquals("fido", listObject.getString(Dog.FIELD_NAME));
}
Also used : AllTypes(io.realm.entities.AllTypes) Dog(io.realm.entities.Dog) Test(org.junit.Test)

Aggregations

Dog (io.realm.entities.Dog)144 Test (org.junit.Test)126 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)50 Owner (io.realm.entities.Owner)32 AllTypes (io.realm.entities.AllTypes)26 UiThreadTest (androidx.test.annotation.UiThreadTest)23 RunInLooperThread (io.realm.rule.RunInLooperThread)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 AllJavaTypes (io.realm.entities.AllJavaTypes)10 CountDownLatch (java.util.concurrent.CountDownLatch)10 AtomicLong (java.util.concurrent.atomic.AtomicLong)10 Before (org.junit.Before)10 SystemClock (android.os.SystemClock)9 AndroidJUnit4 (androidx.test.ext.junit.runners.AndroidJUnit4)9 Flowable (io.reactivex.Flowable)9 Disposable (io.reactivex.disposables.Disposable)9 Consumer (io.reactivex.functions.Consumer)9 Schedulers (io.reactivex.schedulers.Schedulers)9 CyclicType (io.realm.entities.CyclicType)9 Pair (io.realm.internal.util.Pair)9