Search in sources :

Example 21 with AllJavaTypes

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);
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) Pair(android.util.Pair)

Example 22 with AllJavaTypes

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));
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) Test(org.junit.Test)

Example 23 with AllJavaTypes

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();
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test)

Example 24 with AllJavaTypes

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));
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) Test(org.junit.Test)

Example 25 with AllJavaTypes

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());
}
Also used : AllJavaTypes(io.realm.entities.AllJavaTypes) Test(org.junit.Test)

Aggregations

AllJavaTypes (io.realm.entities.AllJavaTypes)90 Test (org.junit.Test)78 UiThreadTest (android.support.test.annotation.UiThreadTest)24 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 Date (java.util.Date)5 RealmException (io.realm.exceptions.RealmException)4 Ignore (org.junit.Ignore)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 ExecutionException (java.util.concurrent.ExecutionException)2 ExecutorService (java.util.concurrent.ExecutorService)2 ExpectedException (org.junit.rules.ExpectedException)2 Pair (android.util.Pair)1 CyclicType (io.realm.entities.CyclicType)1 Dog (io.realm.entities.Dog)1 NonLatinFieldNames (io.realm.entities.NonLatinFieldNames)1 PrimaryKeyAsString (io.realm.entities.PrimaryKeyAsString)1 RealmPrimaryKeyConstraintException (io.realm.exceptions.RealmPrimaryKeyConstraintException)1 RunInLooperThread (io.realm.rule.RunInLooperThread)1 Field (java.lang.reflect.Field)1