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));
}
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();
}
}
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();
}
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();
}
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));
}
Aggregations