Search in sources :

Example 96 with AllTypes

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

the class RealmObjectTests method getRealm_closedObjectThrows.

@Test
public void getRealm_closedObjectThrows() {
    realm.beginTransaction();
    AllTypes object = realm.createObject(AllTypes.class);
    realm.commitTransaction();
    realm.close();
    realm = null;
    try {
        object.getRealm();
        fail();
    } catch (IllegalStateException e) {
        assertEquals(BaseRealm.CLOSED_REALM_MESSAGE, e.getMessage());
    }
    try {
        RealmObject.getRealm(object);
        fail();
    } catch (IllegalStateException e) {
        assertEquals(BaseRealm.CLOSED_REALM_MESSAGE, e.getMessage());
    }
}
Also used : AllTypes(io.realm.entities.AllTypes) Test(org.junit.Test)

Example 97 with AllTypes

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

the class RealmObjectTests method isValid_unmanagedObject.

@Test
public void isValid_unmanagedObject() {
    AllTypes allTypes = new AllTypes();
    assertTrue(allTypes.isValid());
}
Also used : AllTypes(io.realm.entities.AllTypes) Test(org.junit.Test)

Example 98 with AllTypes

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

the class RealmObjectTests method changeListener_triggeredWhenObjectIsDeleted.

@Test
@RunTestInLooperThread
public void changeListener_triggeredWhenObjectIsDeleted() {
    final Realm realm = looperThread.getRealm();
    realm.beginTransaction();
    AllTypes obj = realm.createObject(AllTypes.class);
    realm.commitTransaction();
    obj.addChangeListener(new RealmChangeListener<AllTypes>() {

        @Override
        public void onChange(AllTypes obj) {
            assertFalse(obj.isValid());
            looperThread.testComplete();
        }
    });
    realm.beginTransaction();
    obj.deleteFromRealm();
    realm.commitTransaction();
}
Also used : AllTypes(io.realm.entities.AllTypes) RunTestInLooperThread(io.realm.rule.RunTestInLooperThread) Test(org.junit.Test)

Example 99 with AllTypes

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

the class RealmObjectTests method float_double_NaN.

// Tests NaN value on float and double columns.
@Test
public void float_double_NaN() {
    realm.beginTransaction();
    AllTypes allTypes = realm.createObject(AllTypes.class);
    allTypes.setColumnFloat(Float.NaN);
    allTypes.setColumnDouble(Double.NaN);
    realm.commitTransaction();
    assertEquals(Float.NaN, realm.where(AllTypes.class).findFirst().getColumnFloat(), 0.0F);
    assertEquals(Double.NaN, realm.where(AllTypes.class).findFirst().getColumnDouble(), 0.0D);
    // NaN != NaN !!!
    assertEquals(0, realm.where(AllTypes.class).equalTo("columnFloat", Float.NaN).count());
    assertEquals(0, realm.where(AllTypes.class).equalTo("columnDouble", Double.NaN).count());
}
Also used : AllTypes(io.realm.entities.AllTypes) Test(org.junit.Test)

Example 100 with AllTypes

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

the class RealmObjectTests method getRealmConfiguration_deletedObjectThrows.

@Test
public void getRealmConfiguration_deletedObjectThrows() {
    realm.beginTransaction();
    AllTypes object = realm.createObject(AllTypes.class);
    object.deleteFromRealm();
    realm.commitTransaction();
    try {
        object.getRealm();
        fail();
    } catch (IllegalStateException e) {
        assertEquals(RealmObject.MSG_DELETED_OBJECT, e.getMessage());
    }
    try {
        RealmObject.getRealm(object);
        fail();
    } catch (IllegalStateException e) {
        assertEquals(RealmObject.MSG_DELETED_OBJECT, e.getMessage());
    }
}
Also used : AllTypes(io.realm.entities.AllTypes) Test(org.junit.Test)

Aggregations

AllTypes (io.realm.entities.AllTypes)225 Test (org.junit.Test)210 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)70 UiThreadTest (androidx.test.annotation.UiThreadTest)54 Date (java.util.Date)36 DictionaryAllTypes (io.realm.entities.DictionaryAllTypes)32 Dog (io.realm.entities.Dog)27 JSONObject (org.json.JSONObject)26 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)22 RunInLooperThread (io.realm.rule.RunInLooperThread)20 InputStream (java.io.InputStream)19 Decimal128 (org.bson.types.Decimal128)19 ByteArrayInputStream (java.io.ByteArrayInputStream)17 ObjectId (org.bson.types.ObjectId)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)11 UiThreadTest (android.support.test.annotation.UiThreadTest)10 AtomicLong (java.util.concurrent.atomic.AtomicLong)10 OsSharedRealm (io.realm.internal.OsSharedRealm)9 BigDecimal (java.math.BigDecimal)9 NonLatinFieldNames (io.realm.entities.NonLatinFieldNames)8