Search in sources :

Example 81 with AllTypes

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

the class RealmQueryTests method like_caseSensitiveWithNonLatinCharacters.

@Test
public void like_caseSensitiveWithNonLatinCharacters() {
    populateTestRealm();
    String flagEmoji = new StringBuilder().append(Character.toChars(0x1F1E9)).toString();
    String emojis = "ABC" + flagEmoji + "DEF";
    realm.beginTransaction();
    realm.delete(AllTypes.class);
    AllTypes at1 = realm.createObject(AllTypes.class);
    at1.setColumnString("Αλφα");
    AllTypes at2 = realm.createObject(AllTypes.class);
    at2.setColumnString("βήτα");
    AllTypes at3 = realm.createObject(AllTypes.class);
    at3.setColumnString("δέλτα");
    AllTypes at4 = realm.createObject(AllTypes.class);
    at4.setColumnString(emojis);
    realm.commitTransaction();
    RealmResults<AllTypes> resultList = realm.where(AllTypes.class).like("columnString", "*Α*").findAll();
    assertEquals(1, resultList.size());
    resultList = realm.where(AllTypes.class).like("columnString", "*λ*").findAll();
    assertEquals(2, resultList.size());
    resultList = realm.where(AllTypes.class).like("columnString", "*Δ*").findAll();
    assertEquals(0, resultList.size());
    resultList = realm.where(AllTypes.class).like("columnString", "*Α*", Case.INSENSITIVE).findAll();
    // without ASCII-only limitation A matches α
    // assertEquals(3, resultList.size());
    assertEquals(1, resultList.size());
    resultList = realm.where(AllTypes.class).like("columnString", "*λ*", Case.INSENSITIVE).findAll();
    assertEquals(2, resultList.size());
    resultList = realm.where(AllTypes.class).like("columnString", "*Δ*", Case.INSENSITIVE).findAll();
    // without ASCII-only limitation Δ matches δ
    // assertEquals(1, resultList.size());
    assertEquals(0, resultList.size());
    resultList = realm.where(AllTypes.class).like("columnString", "?λ*").findAll();
    assertEquals(1, resultList.size());
    resultList = realm.where(AllTypes.class).like("columnString", "??λ*").findAll();
    assertEquals(1, resultList.size());
    resultList = realm.where(AllTypes.class).like("columnString", "?λ*").findAll();
    assertEquals(1, resultList.size());
    resultList = realm.where(AllTypes.class).like("columnString", "??λ*").findAll();
    assertEquals(1, resultList.size());
    resultList = realm.where(AllTypes.class).like("columnString", "ABC?DEF*").findAll();
    assertEquals(1, resultList.size());
    resultList = realm.where(AllTypes.class).like("columnString", "*" + flagEmoji + "*").findAll();
    assertEquals(1, resultList.size());
}
Also used : AllTypes(io.realm.entities.AllTypes) DictionaryAllTypes(io.realm.entities.DictionaryAllTypes) PrimaryKeyAsString(io.realm.entities.PrimaryKeyAsString) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 82 with AllTypes

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

the class RealmQueryTests method notEqualTo_decimal128.

@Test
public void notEqualTo_decimal128() {
    populateTestRealm(realm, 10);
    RealmResults<AllTypes> resultList = realm.where(AllTypes.class).notEqualTo(AllTypes.FIELD_DECIMAL128, new Decimal128(new BigDecimal("0.23456789"))).sort(AllTypes.FIELD_UUID, Sort.ASCENDING).findAll();
    assertEquals(9, resultList.size());
    for (int i = 1; i < 10; i++) {
        assertNotEquals(new Decimal128(new BigDecimal("0.23456789")), resultList.get(0).getColumnDecimal128());
    }
}
Also used : AllTypes(io.realm.entities.AllTypes) DictionaryAllTypes(io.realm.entities.DictionaryAllTypes) Decimal128(org.bson.types.Decimal128) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 83 with AllTypes

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

the class RealmQueryTests method equalTo_decimal128.

@Test
public void equalTo_decimal128() {
    populateTestRealm(realm, 10);
    for (int i = 0; i < 10; i++) {
        RealmResults<AllTypes> resultList = realm.where(AllTypes.class).equalTo(AllTypes.FIELD_DECIMAL128, new Decimal128(new BigDecimal(i + ".23456789"))).sort(AllTypes.FIELD_DECIMAL128, Sort.ASCENDING).findAll();
        assertEquals(1, resultList.size());
        assertEquals(new Decimal128(new BigDecimal(i + ".23456789")), resultList.get(0).getColumnDecimal128());
    }
}
Also used : AllTypes(io.realm.entities.AllTypes) DictionaryAllTypes(io.realm.entities.DictionaryAllTypes) Decimal128(org.bson.types.Decimal128) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 84 with AllTypes

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

the class RealmQueryTests method between.

@Test
public void between() {
    final int TEST_OBJECTS_COUNT = 200;
    populateTestRealm(realm, TEST_OBJECTS_COUNT);
    RealmResults<AllTypes> resultList = realm.where(AllTypes.class).between(AllTypes.FIELD_LONG, 0, 9).findAll();
    assertEquals(10, resultList.size());
    resultList = realm.where(AllTypes.class).beginsWith(AllTypes.FIELD_STRING, "test data ").findAll();
    assertEquals(TEST_OBJECTS_COUNT, resultList.size());
    resultList = realm.where(AllTypes.class).beginsWith(AllTypes.FIELD_STRING, "test data 1").between(AllTypes.FIELD_LONG, 2, 20).findAll();
    assertEquals(10, resultList.size());
    resultList = realm.where(AllTypes.class).between(AllTypes.FIELD_LONG, 2, 20).beginsWith(AllTypes.FIELD_STRING, "test data 1").findAll();
    assertEquals(10, resultList.size());
    assertEquals(51, realm.where(AllTypes.class).between(AllTypes.FIELD_DATE, new Date(0), new Date(DECADE_MILLIS * 50)).count());
}
Also used : AllTypes(io.realm.entities.AllTypes) DictionaryAllTypes(io.realm.entities.DictionaryAllTypes) Date(java.util.Date) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 85 with AllTypes

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

the class RealmQueryTests method lessThan_Date.

@Test
public void lessThan_Date() {
    final int TEST_OBJECTS_COUNT = 200;
    populateTestRealm(realm, TEST_OBJECTS_COUNT);
    RealmResults<AllTypes> resultList;
    resultList = realm.where(AllTypes.class).lessThan(AllTypes.FIELD_DATE, new Date(Long.MIN_VALUE)).findAll();
    assertEquals(0, resultList.size());
    resultList = realm.where(AllTypes.class).lessThan(AllTypes.FIELD_DATE, new Date(DECADE_MILLIS * -80)).findAll();
    assertEquals(20, resultList.size());
    resultList = realm.where(AllTypes.class).lessThan(AllTypes.FIELD_DATE, new Date(0)).findAll();
    assertEquals(TEST_OBJECTS_COUNT / 2, resultList.size());
    resultList = realm.where(AllTypes.class).lessThan(AllTypes.FIELD_DATE, new Date(DECADE_MILLIS * 80)).findAll();
    assertEquals(180, resultList.size());
    resultList = realm.where(AllTypes.class).lessThan(AllTypes.FIELD_DATE, new Date(Long.MAX_VALUE)).findAll();
    assertEquals(TEST_OBJECTS_COUNT, resultList.size());
}
Also used : AllTypes(io.realm.entities.AllTypes) DictionaryAllTypes(io.realm.entities.DictionaryAllTypes) Date(java.util.Date) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

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