Search in sources :

Example 21 with AllTypes

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

the class RealmQueryTests method populateTestRealm.

private void populateTestRealm(Realm testRealm, int dataSize) {
    testRealm.beginTransaction();
    testRealm.deleteAll();
    for (int i = 0; i < dataSize; ++i) {
        AllTypes allTypes = testRealm.createObject(AllTypes.class);
        allTypes.setColumnBoolean((i % 3) == 0);
        allTypes.setColumnBinary(new byte[] { 1, 2, 3 });
        allTypes.setColumnDate(new Date(DECADE_MILLIS * (i - (dataSize / 2))));
        allTypes.setColumnDouble(3.1415);
        allTypes.setColumnFloat(1.234567f + i);
        allTypes.setColumnString("test data " + i);
        allTypes.setColumnLong(i);
        NonLatinFieldNames nonLatinFieldNames = testRealm.createObject(NonLatinFieldNames.class);
        nonLatinFieldNames.set델타(i);
        nonLatinFieldNames.setΔέλτα(i);
        nonLatinFieldNames.set베타(1.234567f + i);
        nonLatinFieldNames.setΒήτα(1.234567f + i);
        Dog dog = testRealm.createObject(Dog.class);
        dog.setAge(i);
        dog.setName("test data " + i);
        allTypes.setColumnRealmObject(dog);
    }
    testRealm.commitTransaction();
}
Also used : NonLatinFieldNames(io.realm.entities.NonLatinFieldNames) AllTypes(io.realm.entities.AllTypes) Dog(io.realm.entities.Dog) Date(java.util.Date)

Example 22 with AllTypes

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

the class RealmQueryTests method lessThanOrEqualTo_date.

@Test
public void lessThanOrEqualTo_date() {
    final int TEST_OBJECTS_COUNT = 200;
    populateTestRealm(realm, TEST_OBJECTS_COUNT);
    RealmResults<AllTypes> resultList;
    resultList = realm.where(AllTypes.class).lessThanOrEqualTo(AllTypes.FIELD_DATE, new Date(Long.MIN_VALUE)).findAll();
    assertEquals(0, resultList.size());
    resultList = realm.where(AllTypes.class).lessThanOrEqualTo(AllTypes.FIELD_DATE, new Date(DECADE_MILLIS * -80)).findAll();
    assertEquals(21, resultList.size());
    resultList = realm.where(AllTypes.class).lessThanOrEqualTo(AllTypes.FIELD_DATE, new Date(0)).findAll();
    assertEquals(TEST_OBJECTS_COUNT / 2 + 1, resultList.size());
    resultList = realm.where(AllTypes.class).lessThanOrEqualTo(AllTypes.FIELD_DATE, new Date(DECADE_MILLIS * 80)).findAll();
    assertEquals(181, resultList.size());
    resultList = realm.where(AllTypes.class).lessThanOrEqualTo(AllTypes.FIELD_DATE, new Date(Long.MAX_VALUE)).findAll();
    assertEquals(TEST_OBJECTS_COUNT, resultList.size());
}
Also used : AllTypes(io.realm.entities.AllTypes) Date(java.util.Date) Test(org.junit.Test)

Example 23 with AllTypes

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

the class RealmTests method copyFromRealm_list_invalidListThrows.

@Test
public void copyFromRealm_list_invalidListThrows() {
    realm.beginTransaction();
    AllTypes object = realm.createObject(AllTypes.class);
    List<AllTypes> list = new RealmList<AllTypes>(object);
    object.deleteFromRealm();
    realm.commitTransaction();
    thrown.expect(IllegalArgumentException.class);
    realm.copyFromRealm(list);
}
Also used : AllTypes(io.realm.entities.AllTypes) Test(org.junit.Test)

Example 24 with AllTypes

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

the class RealmTests method copyFromRealm_dynamicRealmObjectThrows.

@Test
public void copyFromRealm_dynamicRealmObjectThrows() {
    realm.beginTransaction();
    AllTypes obj = realm.createObject(AllTypes.class);
    realm.commitTransaction();
    DynamicRealmObject dObj = new DynamicRealmObject(obj);
    try {
        realm.copyFromRealm(dObj);
        fail();
    } catch (IllegalArgumentException ignored) {
    }
}
Also used : AllTypes(io.realm.entities.AllTypes) Test(org.junit.Test)

Example 25 with AllTypes

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

the class RealmTests method copyToRealmOrUpdate_noPrimaryKeyField.

@Test
public void copyToRealmOrUpdate_noPrimaryKeyField() {
    realm.beginTransaction();
    thrown.expect(IllegalArgumentException.class);
    realm.copyToRealmOrUpdate(new AllTypes());
}
Also used : AllTypes(io.realm.entities.AllTypes) Test(org.junit.Test)

Aggregations

AllTypes (io.realm.entities.AllTypes)134 Test (org.junit.Test)122 UiThreadTest (android.support.test.annotation.UiThreadTest)40 RunTestInLooperThread (io.realm.rule.RunTestInLooperThread)33 Date (java.util.Date)27 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 Action1 (rx.functions.Action1)12 JSONObject (org.json.JSONObject)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 Dog (io.realm.entities.Dog)8 InputStream (java.io.InputStream)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 NonLatinFieldNames (io.realm.entities.NonLatinFieldNames)5 SharedRealm (io.realm.internal.SharedRealm)5 RealmException (io.realm.exceptions.RealmException)4 RunInLooperThread (io.realm.rule.RunInLooperThread)3 IOException (java.io.IOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ExecutionException (java.util.concurrent.ExecutionException)3 JSONException (org.json.JSONException)3