use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class OrderedRealmCollectionTests method createCollectionWithMultipleCopies.
private Pair<AllJavaTypes, OrderedRealmCollection<AllJavaTypes>> createCollectionWithMultipleCopies(Realm realm, CollectionClass collectionClass) {
OrderedRealmCollection<AllJavaTypes> orderedCollection;
AllJavaTypes obj;
switch(collectionClass) {
case REALMRESULTS_SNAPSHOT_LIST_BASE:
case MANAGED_REALMLIST:
obj = realm.where(AllJavaTypes.class).equalTo(AllJavaTypes.FIELD_LONG, 1).findFirst();
RealmList<AllJavaTypes> list = obj.getFieldList();
realm.beginTransaction();
list.add(obj);
realm.commitTransaction();
orderedCollection = list;
break;
case UNMANAGED_REALMLIST:
obj = new AllJavaTypes(1);
return new Pair<AllJavaTypes, OrderedRealmCollection<AllJavaTypes>>(obj, new RealmList<AllJavaTypes>(obj, obj));
case REALMRESULTS_SNAPSHOT_RESULTS_BASE:
case REALMRESULTS:
RealmResults<AllJavaTypes> result = realm.where(AllJavaTypes.class).equalTo(AllJavaTypes.FIELD_LONG, 1).findAll();
obj = result.first();
orderedCollection = result;
break;
default:
throw new AssertionError("Unsupported class: " + collectionClass);
}
if (isSnapshot(collectionClass)) {
orderedCollection = orderedCollection.createSnapshot();
}
return new Pair<AllJavaTypes, OrderedRealmCollection<AllJavaTypes>>(obj, orderedCollection);
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class OrderedRealmCollectionTests method first_withDefault.
@Test
public void first_withDefault() {
AllJavaTypes defaultObject = new AllJavaTypes();
collection = createEmptyCollection(realm, collectionClass);
assertEquals(defaultObject, collection.first(defaultObject));
// Null is an acceptable default
assertEquals(null, collection.first(null));
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class RealmObjectTests method setter_changePrimaryKeyThrows.
@Test
public void setter_changePrimaryKeyThrows() {
realm.beginTransaction();
AllJavaTypes allJavaTypes = realm.createObject(AllJavaTypes.class, 42);
thrown.expect(RealmException.class);
allJavaTypes.setFieldId(111);
realm.cancelTransaction();
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class UnManagedRealmCollectionTests method contains.
@Test
public void contains() {
AllJavaTypes obj = collection.iterator().next();
assertTrue(collection.contains(obj));
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class RealmTests method createObjectWithPrimaryKey.
@Test
public void createObjectWithPrimaryKey() {
realm.beginTransaction();
AllJavaTypes obj = realm.createObject(AllJavaTypes.class, 42);
assertEquals(1, realm.where(AllJavaTypes.class).count());
assertEquals(42, obj.getFieldId());
}
Aggregations