Search in sources :

Example 31 with Owner

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

the class RealmListTests method move_up.

// Tests move where oldPosition < newPosition.
@Test
public void move_up() {
    Owner owner = realm.where(Owner.class).findFirst();
    Dog dog1 = owner.getDogs().get(0);
    Dog dog2 = owner.getDogs().get(1);
    realm.beginTransaction();
    owner.getDogs().move(0, 1);
    realm.commitTransaction();
    assertEquals(TEST_SIZE, owner.getDogs().size());
    assertEquals(1, owner.getDogs().indexOf(dog1));
    assertEquals(0, owner.getDogs().indexOf(dog2));
}
Also used : Owner(io.realm.entities.Owner) Dog(io.realm.entities.Dog) Test(org.junit.Test)

Example 32 with Owner

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

the class RealmListTests method move_outOfBoundsHigherThrows.

@Test
public void move_outOfBoundsHigherThrows() {
    Owner owner = realm.where(Owner.class).findFirst();
    realm.beginTransaction();
    try {
        int lastIndex = TEST_SIZE - 1;
        int outOfBoundsIndex = TEST_SIZE;
        owner.getDogs().move(lastIndex, outOfBoundsIndex);
        fail("Indexes >= size() should throw an exception");
    } catch (IndexOutOfBoundsException ignored) {
        ignored.printStackTrace();
    } finally {
        realm.cancelTransaction();
    }
}
Also used : Owner(io.realm.entities.Owner) Test(org.junit.Test)

Example 33 with Owner

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

the class RealmListTests method clear_notDeleting.

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

Example 34 with Owner

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

the class RealmListTests method setUp.

@Before
public void setUp() throws Exception {
    RealmConfiguration realmConfig = configFactory.createConfiguration();
    realm = Realm.getInstance(realmConfig);
    realm.beginTransaction();
    Owner owner = realm.createObject(Owner.class);
    owner.setName("Owner");
    for (int i = 0; i < TEST_SIZE; i++) {
        Dog dog = realm.createObject(Dog.class);
        dog.setName("Dog " + i);
        owner.getDogs().add(dog);
    }
    realm.commitTransaction();
    collection = owner.getDogs();
}
Also used : Owner(io.realm.entities.Owner) Dog(io.realm.entities.Dog) Before(org.junit.Before)

Example 35 with Owner

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

the class RealmListTests method move_down.

// Tests move where oldPosition > newPosition.
@Test
public void move_down() {
    Owner owner = realm.where(Owner.class).findFirst();
    Dog dog1 = owner.getDogs().get(1);
    Dog dog2 = owner.getDogs().get(0);
    realm.beginTransaction();
    owner.getDogs().move(1, 0);
    realm.commitTransaction();
    assertEquals(TEST_SIZE, owner.getDogs().size());
    assertEquals(0, owner.getDogs().indexOf(dog1));
    assertEquals(1, owner.getDogs().indexOf(dog2));
}
Also used : Owner(io.realm.entities.Owner) Dog(io.realm.entities.Dog) Test(org.junit.Test)

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