Search in sources :

Example 31 with Decimal128

use of org.bson.types.Decimal128 in project realm-java by realm.

the class RealmJsonTests method createObjectFromJson_decimal128AsInt.

@Test
public void createObjectFromJson_decimal128AsInt() throws JSONException {
    JSONObject json = new JSONObject();
    json.put("columnDecimal128", -42);
    realm.beginTransaction();
    realm.createObjectFromJson(AllTypes.class, json);
    realm.commitTransaction();
    AllTypes obj = realm.where(AllTypes.class).findFirst();
    assertEquals(new Decimal128(-42), obj.getColumnDecimal128());
}
Also used : JSONObject(org.json.JSONObject) AllTypes(io.realm.entities.AllTypes) Decimal128(org.bson.types.Decimal128) Test(org.junit.Test)

Example 32 with Decimal128

use of org.bson.types.Decimal128 in project realm-java by realm.

the class RealmTests method copyToRealm.

@Test
public void copyToRealm() {
    Date date = new Date();
    Dog dog = new Dog();
    dog.setName("Fido");
    RealmList<Dog> list = new RealmList<Dog>();
    list.add(dog);
    AllTypes allTypes = new AllTypes();
    allTypes.setColumnString("String");
    allTypes.setColumnLong(1L);
    allTypes.setColumnFloat(1F);
    allTypes.setColumnDouble(1D);
    allTypes.setColumnBoolean(true);
    allTypes.setColumnDate(date);
    allTypes.setColumnBinary(new byte[] { 1, 2, 3 });
    allTypes.setColumnDecimal128(new Decimal128(new BigDecimal("12345")));
    allTypes.setColumnObjectId(new ObjectId(TestHelper.generateObjectIdHexString(7)));
    allTypes.setColumnUUID(UUID.fromString(TestHelper.generateUUIDString(7)));
    allTypes.setColumnRealmAny(RealmAny.valueOf(UUID.fromString(TestHelper.generateUUIDString(6))));
    allTypes.setColumnRealmObject(dog);
    allTypes.setColumnRealmList(list);
    allTypes.setColumnStringList(new RealmList<String>("1"));
    allTypes.setColumnBinaryList(new RealmList<byte[]>(new byte[] { 1 }));
    allTypes.setColumnBooleanList(new RealmList<Boolean>(true));
    allTypes.setColumnLongList(new RealmList<Long>(1L));
    allTypes.setColumnDoubleList(new RealmList<Double>(1D));
    allTypes.setColumnFloatList(new RealmList<Float>(1F));
    allTypes.setColumnDateList(new RealmList<Date>(new Date(1L)));
    allTypes.setColumnDecimal128List(new RealmList<Decimal128>(new Decimal128(new BigDecimal("54321"))));
    allTypes.setColumnObjectIdList(new RealmList<ObjectId>(new ObjectId(TestHelper.generateObjectIdHexString(5))));
    allTypes.setColumnUUIDList(new RealmList<>(UUID.fromString(TestHelper.generateUUIDString(5))));
    allTypes.setColumnRealmAnyList(new RealmList<>(RealmAny.valueOf(UUID.fromString(TestHelper.generateUUIDString(7)))));
    realm.beginTransaction();
    AllTypes realmTypes = realm.copyToRealm(allTypes);
    realm.commitTransaction();
    // Objects should not be considered equal.
    assertNotSame(allTypes, realmTypes);
    // But they contain the same data.
    assertEquals(allTypes.getColumnString(), realmTypes.getColumnString());
    assertEquals(allTypes.getColumnLong(), realmTypes.getColumnLong());
    assertEquals(allTypes.getColumnFloat(), realmTypes.getColumnFloat(), 0);
    assertEquals(allTypes.getColumnDouble(), realmTypes.getColumnDouble(), 0);
    assertEquals(allTypes.isColumnBoolean(), realmTypes.isColumnBoolean());
    assertEquals(allTypes.getColumnDate(), realmTypes.getColumnDate());
    assertArrayEquals(allTypes.getColumnBinary(), realmTypes.getColumnBinary());
    assertEquals(allTypes.getColumnDecimal128(), realmTypes.getColumnDecimal128());
    assertEquals(allTypes.getColumnObjectId(), realmTypes.getColumnObjectId());
    assertEquals(allTypes.getColumnUUID(), realmTypes.getColumnUUID());
    assertEquals(allTypes.getColumnRealmAny(), realmTypes.getColumnRealmAny());
    assertEquals(allTypes.getColumnRealmObject().getName(), dog.getName());
    assertEquals(list.size(), realmTypes.getColumnRealmList().size());
    // noinspection ConstantConditions
    assertEquals(list.get(0).getName(), realmTypes.getColumnRealmList().get(0).getName());
    assertEquals(1, realmTypes.getColumnStringList().size());
    assertEquals("1", realmTypes.getColumnStringList().get(0));
    assertEquals(1, realmTypes.getColumnBooleanList().size());
    assertEquals(true, realmTypes.getColumnBooleanList().get(0));
    assertEquals(1, realmTypes.getColumnBinaryList().size());
    assertArrayEquals(new byte[] { 1 }, realmTypes.getColumnBinaryList().get(0));
    assertEquals(1, realmTypes.getColumnLongList().size());
    assertEquals((Long) 1L, realmTypes.getColumnLongList().get(0));
    assertEquals(1, realmTypes.getColumnDoubleList().size());
    assertEquals((Double) 1D, realmTypes.getColumnDoubleList().get(0));
    assertEquals(1, realmTypes.getColumnFloatList().size());
    assertEquals((Float) 1F, realmTypes.getColumnFloatList().get(0));
    assertEquals(1, realmTypes.getColumnDateList().size());
    assertEquals(new Date(1), realmTypes.getColumnDateList().get(0));
    assertEquals(1, realmTypes.getColumnDecimal128List().size());
    assertEquals(new Decimal128(new BigDecimal("54321")), realmTypes.getColumnDecimal128List().get(0));
    assertEquals(1, realmTypes.getColumnObjectIdList().size());
    assertEquals(new ObjectId(TestHelper.generateObjectIdHexString(5)), realmTypes.getColumnObjectIdList().get(0));
    assertEquals(1, realmTypes.getColumnUUIDList().size());
    assertEquals(UUID.fromString(TestHelper.generateUUIDString(5)), realmTypes.getColumnUUIDList().get(0));
    assertEquals(1, realmTypes.getColumnRealmAnyList().size());
    assertEquals(RealmAny.valueOf(UUID.fromString(TestHelper.generateUUIDString(7))), realmTypes.getColumnRealmAnyList().get(0));
}
Also used : ObjectId(org.bson.types.ObjectId) AllTypes(io.realm.entities.AllTypes) Decimal128(org.bson.types.Decimal128) PrimaryKeyRequiredAsString(io.realm.entities.PrimaryKeyRequiredAsString) PrimaryKeyAsString(io.realm.entities.PrimaryKeyAsString) Date(java.util.Date) BigDecimal(java.math.BigDecimal) PrimaryKeyAsLong(io.realm.entities.PrimaryKeyAsLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) PrimaryKeyAsBoxedLong(io.realm.entities.PrimaryKeyAsBoxedLong) PrimaryKeyRequiredAsBoxedLong(io.realm.entities.PrimaryKeyRequiredAsBoxedLong) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Dog(io.realm.entities.Dog) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 33 with Decimal128

use of org.bson.types.Decimal128 in project realm-java by realm.

the class RealmTests method where_equalTo_wrongFieldTypeAsInput.

// TODO Move to RealmQueryTests?
@Test
public void where_equalTo_wrongFieldTypeAsInput() throws IOException {
    populateTestRealm();
    for (int i = 0; i < columnData.size(); i++) {
        // Realm queries applies coercion on numerical values
        boolean NON_NUMERICAL_COLUMN = (i > 4) && (i != 10);
        // Realm queries applies coercion on objectid and date
        boolean NON_OBJECT_OR_DATE = ((i <= 4) || (i > 6)) && (i != 10);
        // Realm queries applies coercion on string and binary
        boolean NON_STRING_OR_BINARY = ((i <= 6) || (i > 8)) && (i != 10);
        try {
            realm.where(AllTypes.class).equalTo(columnData.get(i), 13.37D).findAll();
            if (NON_NUMERICAL_COLUMN) {
                fail("Realm.where should fail with illegal argument");
            }
        } catch (IllegalArgumentException ignored) {
        }
        try {
            realm.where(AllTypes.class).equalTo(columnData.get(i), 13.3711F).findAll();
            if (NON_NUMERICAL_COLUMN) {
                fail("Realm.where should fail with illegal argument");
            }
        } catch (IllegalArgumentException ignored) {
        }
        try {
            realm.where(AllTypes.class).equalTo(columnData.get(i), 1337).findAll();
            if (NON_NUMERICAL_COLUMN) {
                fail("Realm.where should fail with illegal argument");
            }
        } catch (IllegalArgumentException ignored) {
        }
        try {
            realm.where(AllTypes.class).equalTo(columnData.get(i), new Decimal128(new BigDecimal(i + "12345"))).findAll();
            if (NON_NUMERICAL_COLUMN) {
                fail("Realm.where should fail with illegal argument");
            }
        } catch (IllegalArgumentException ignored) {
        }
        try {
            realm.where(AllTypes.class).equalTo(columnData.get(i), true).findAll();
            if (NON_NUMERICAL_COLUMN) {
                fail("Realm.where should fail with illegal argument");
            }
        } catch (IllegalArgumentException ignored) {
        }
        try {
            realm.where(AllTypes.class).equalTo(columnData.get(i), new Date()).findAll();
            if (NON_OBJECT_OR_DATE) {
                fail("Realm.where should fail with illegal argument");
            }
        } catch (IllegalArgumentException ignored) {
        }
        try {
            realm.where(AllTypes.class).equalTo(columnData.get(i), new ObjectId(TestHelper.generateObjectIdHexString(i))).findAll();
            if (NON_OBJECT_OR_DATE) {
                fail("Realm.where should fail with illegal argument");
            }
        } catch (IllegalArgumentException ignored) {
        }
        try {
            realm.where(AllTypes.class).equalTo(columnData.get(i), "test").findAll();
            if (NON_STRING_OR_BINARY) {
                fail("Realm.where should fail with illegal argument");
            }
        } catch (IllegalArgumentException ignored) {
        }
        try {
            realm.where(AllTypes.class).equalTo(columnData.get(i), new byte[] { 1, 2, 3 }).findAll();
            if (NON_STRING_OR_BINARY) {
                fail("Realm.where should fail with illegal argument");
            }
        } catch (IllegalArgumentException ignored) {
        }
        try {
            realm.where(AllTypes.class).equalTo(columnData.get(i), UUID.fromString(TestHelper.generateUUIDString(i))).findAll();
            if ((i != 9) && (i != 10)) {
                fail("Realm.where should fail with illegal argument");
            }
        } catch (IllegalArgumentException ignored) {
        }
    }
}
Also used : ObjectId(org.bson.types.ObjectId) Decimal128(org.bson.types.Decimal128) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 34 with Decimal128

use of org.bson.types.Decimal128 in project realm-java by realm.

the class RealmResultsTests method setValue_specificType_modelClassNameOnTypedRealms.

@Test
public void setValue_specificType_modelClassNameOnTypedRealms() {
    populateMappedAllJavaTypes(5);
    RealmResults<MappedAllJavaTypes> collection = realm.where(MappedAllJavaTypes.class).findAll();
    realm.beginTransaction();
    for (BulkSetMethods type : BulkSetMethods.values()) {
        switch(type) {
            case STRING:
                collection.setString("fieldString", "foo");
                assertElements(collection, obj -> assertEquals("foo", obj.fieldString));
                break;
            case BOOLEAN:
                collection.setBoolean("fieldBoolean", true);
                assertElements(collection, obj -> assertTrue(obj.fieldBoolean));
                break;
            case BYTE:
                collection.setByte("fieldByte", (byte) 1);
                assertElements(collection, obj -> assertEquals((byte) 1, obj.fieldByte));
                break;
            case SHORT:
                collection.setShort("fieldShort", (short) 2);
                assertElements(collection, obj -> assertEquals((short) 2, obj.fieldShort));
                break;
            case INTEGER:
                collection.setInt("fieldInt", 3);
                assertElements(collection, obj -> assertEquals(3, obj.fieldInt));
                break;
            case LONG:
                collection.setLong("fieldLong", 4L);
                assertElements(collection, obj -> assertEquals(4L, obj.fieldLong));
                break;
            case FLOAT:
                collection.setFloat("fieldFloat", 1.23F);
                assertElements(collection, obj -> assertEquals(1.23F, obj.fieldFloat, 0F));
                break;
            case DOUBLE:
                collection.setDouble("fieldDouble", 1.234);
                assertElements(collection, obj -> assertEquals(1.234, obj.fieldDouble, 0F));
                break;
            case BINARY:
                collection.setBlob("fieldBinary", new byte[] { 1, 2, 3 });
                assertElements(collection, obj -> assertArrayEquals(new byte[] { 1, 2, 3 }, obj.fieldBinary));
                break;
            case DATE:
                collection.setDate("fieldDate", new Date(1000));
                assertElements(collection, obj -> assertEquals(new Date(1000), obj.fieldDate));
                break;
            case DECIMAL128:
                collection.setDecimal128("fieldDecimal128", new Decimal128(1000));
                assertElements(collection, obj -> assertEquals(new Decimal128(1000), obj.fieldDecimal128));
                break;
            case OBJECT_ID:
                {
                    String hex = TestHelper.randomObjectIdHexString();
                    collection.setObjectId("fieldObjectId", new ObjectId(hex));
                    assertElements(collection, obj -> assertEquals(new ObjectId(hex), obj.fieldObjectId));
                    break;
                }
            case UUID:
                {
                    String uuid = UUID.randomUUID().toString();
                    collection.setUUID("fieldUUID", UUID.fromString(uuid));
                    assertElements(collection, obj -> assertEquals(UUID.fromString(uuid), obj.fieldUUID));
                    break;
                }
            case OBJECT:
                {
                    MappedAllJavaTypes childObj = realm.createObject(MappedAllJavaTypes.class, 42);
                    collection.setObject("fieldObject", childObj);
                    assertElements(collection, obj -> assertEquals(childObj, obj.fieldObject));
                    break;
                }
            case MODEL_LIST:
                {
                    MappedAllJavaTypes childObj = realm.createObject(MappedAllJavaTypes.class, 43);
                    collection.setList("fieldList", new RealmList<>(childObj));
                    assertElements(collection, obj -> {
                        assertEquals(1, obj.fieldList.size());
                        assertEquals(childObj, obj.fieldList.first());
                    });
                    break;
                }
            case STRING_VALUE_LIST:
                collection.setList("fieldStringList", new RealmList<>("Foo"));
                assertElements(collection, obj -> {
                    assertEquals(1, obj.fieldStringList.size());
                    assertEquals("Foo", obj.fieldStringList.first());
                });
                break;
            case BOOLEAN_VALUE_LIST:
                collection.setList("fieldBooleanList", new RealmList<>(true));
                assertElements(collection, obj -> {
                    assertEquals(1, obj.fieldBooleanList.size());
                    assertEquals(true, obj.fieldBooleanList.first());
                });
                break;
            case BYTE_VALUE_LIST:
                collection.setList("fieldByteList", new RealmList<>((byte) 1));
                assertElements(collection, obj -> {
                    assertEquals(1, obj.fieldByteList.size());
                    assertEquals(Byte.valueOf((byte) 1), obj.fieldByteList.first());
                });
                break;
            case SHORT_VALUE_LIST:
                collection.setList("fieldShortList", new RealmList<>((short) 1));
                assertElements(collection, obj -> {
                    assertEquals(1, obj.fieldShortList.size());
                    assertEquals(Short.valueOf((short) 1), obj.fieldShortList.first());
                });
                break;
            case INTEGER_VALUE_LIST:
                collection.setList("fieldIntegerList", new RealmList<>(1));
                assertElements(collection, obj -> {
                    assertEquals(1, obj.fieldIntegerList.size());
                    assertEquals(Integer.valueOf(1), obj.fieldIntegerList.first());
                });
                break;
            case LONG_VALUE_LIST:
                collection.setList("fieldLongList", new RealmList<>(1L));
                assertElements(collection, obj -> {
                    assertEquals(1, obj.fieldLongList.size());
                    assertEquals(Long.valueOf((byte) 1), obj.fieldLongList.first());
                });
                break;
            case FLOAT_VALUE_LIST:
                collection.setList("fieldFloatList", new RealmList<>(1.1F));
                assertElements(collection, obj -> {
                    assertEquals(1, obj.fieldFloatList.size());
                    assertEquals(1.1F, obj.fieldFloatList.first(), 0F);
                });
                break;
            case DOUBLE_VALUE_LIST:
                collection.setList("fieldDoubleList", new RealmList<>(1.1D));
                assertElements(collection, obj -> {
                    assertEquals(1, obj.fieldDoubleList.size());
                    assertEquals(1.1D, obj.fieldDoubleList.first(), 0F);
                });
                break;
            case BINARY_VALUE_LIST:
                collection.setList("fieldBinaryList", new RealmList<>(new byte[] { 1, 2, 3 }));
                assertElements(collection, obj -> {
                    assertEquals(1, obj.fieldBinaryList.size());
                    assertArrayEquals(new byte[] { 1, 2, 3 }, obj.fieldBinaryList.first());
                });
                break;
            case DATE_VALUE_LIST:
                collection.setList("fieldDateList", new RealmList<>(new Date(1000)));
                assertElements(collection, obj -> {
                    assertEquals(1, obj.fieldDateList.size());
                    assertEquals(new Date(1000), obj.fieldDateList.first());
                });
                break;
            case DECIMAL128_VALUE_LIST:
                collection.setList("fieldDecimalList", new RealmList<>(new Decimal128(1000)));
                assertElements(collection, obj -> {
                    assertEquals(1, obj.fieldDecimalList.size());
                    assertEquals(new Decimal128(1000), obj.fieldDecimalList.first());
                });
                break;
            case OBJECT_ID_VALUE_LIST:
                {
                    String hex = TestHelper.randomObjectIdHexString();
                    collection.setList("fieldObjectIdList", new RealmList<>(new ObjectId(hex)));
                    assertElements(collection, obj -> {
                        assertEquals(1, obj.fieldObjectIdList.size());
                        assertEquals(new ObjectId(hex), obj.fieldObjectIdList.first());
                    });
                    break;
                }
            case UUID_VALUE_LIST:
                {
                    String uuid = UUID.randomUUID().toString();
                    collection.setList("fieldUUIDList", new RealmList<>(UUID.fromString(uuid)));
                    assertElements(collection, obj -> {
                        assertEquals(1, obj.fieldUUIDList.size());
                        assertEquals(UUID.fromString(uuid), obj.fieldUUIDList.first());
                    });
                    break;
                }
            default:
                fail("Unknown type: " + type);
        }
    }
}
Also used : Arrays(java.util.Arrays) AllJavaTypes(io.realm.entities.AllJavaTypes) Date(java.util.Date) Dog(io.realm.entities.Dog) AndroidJUnit4(androidx.test.ext.junit.runners.AndroidJUnit4) BigDecimal(java.math.BigDecimal) JSONException(org.json.JSONException) RunInLooperThread(io.realm.rule.RunInLooperThread) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StringOnly(io.realm.entities.StringOnly) After(org.junit.After) Assert.fail(org.junit.Assert.fail) DefaultValueOfField(io.realm.entities.DefaultValueOfField) NonLatinFieldNames(io.realm.entities.NonLatinFieldNames) TimeZone(java.util.TimeZone) Collection(java.util.Collection) Set(java.util.Set) UUID(java.util.UUID) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) RandomPrimaryKey(io.realm.entities.RandomPrimaryKey) RunWith(org.junit.runner.RunWith) SimpleDateFormat(java.text.SimpleDateFormat) JSONAssert(org.skyscreamer.jsonassert.JSONAssert) MappedAllJavaTypes(io.realm.entities.MappedAllJavaTypes) Calendar(java.util.Calendar) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) ExpectedException(org.junit.rules.ExpectedException) Decimal128(org.bson.types.Decimal128) Before(org.junit.Before) RunTestInLooperThread(io.realm.rule.RunTestInLooperThread) PrimaryKeyAsLong(io.realm.entities.PrimaryKeyAsLong) RealmLog(io.realm.log.RealmLog) Assert.assertNotNull(org.junit.Assert.assertNotNull) AllTypes(io.realm.entities.AllTypes) DictionaryAllTypes(io.realm.entities.DictionaryAllTypes) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) CyclicType(io.realm.entities.CyclicType) TimeUnit(java.util.concurrent.TimeUnit) OsResults(io.realm.internal.OsResults) Mockito(org.mockito.Mockito) PrimaryKeyAsString(io.realm.entities.PrimaryKeyAsString) Rule(org.junit.Rule) Assert.assertNull(org.junit.Assert.assertNull) Owner(io.realm.entities.Owner) UiThreadTest(androidx.test.annotation.UiThreadTest) ObjectId(org.bson.types.ObjectId) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ObjectId(org.bson.types.ObjectId) Decimal128(org.bson.types.Decimal128) PrimaryKeyAsString(io.realm.entities.PrimaryKeyAsString) Date(java.util.Date) MappedAllJavaTypes(io.realm.entities.MappedAllJavaTypes) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 35 with Decimal128

use of org.bson.types.Decimal128 in project realm-java by realm.

the class RealmResultsTests method setValue_specificType_wrongFieldNameThrows.

@Test
public void setValue_specificType_wrongFieldNameThrows() {
    populateAllJavaTypes(5);
    RealmResults<AllTypes> collection = realm.where(AllTypes.class).findAll();
    realm.beginTransaction();
    for (BulkSetMethods type : BulkSetMethods.values()) {
        try {
            switch(type) {
                case STRING:
                    collection.setString("foo", "bar");
                    break;
                case BOOLEAN:
                    collection.setBoolean("foo", true);
                    break;
                case BYTE:
                    collection.setByte("foo", (byte) 1);
                    break;
                case SHORT:
                    collection.setShort("foo", (short) 2);
                    break;
                case INTEGER:
                    collection.setInt("foo", 3);
                    break;
                case LONG:
                    collection.setLong("foo", 4L);
                    break;
                case FLOAT:
                    collection.setFloat("foo", 1.23F);
                    break;
                case DOUBLE:
                    collection.setDouble("foo", 1.234);
                    break;
                case BINARY:
                    collection.setBlob("foo", new byte[] { 1, 2, 3 });
                    break;
                case DATE:
                    collection.setDate("foo", new Date(1000));
                    break;
                case DECIMAL128:
                    collection.setDecimal128("foo", new Decimal128(1000));
                    break;
                case OBJECT_ID:
                    collection.setObjectId("foo", new ObjectId(TestHelper.randomObjectIdHexString()));
                    break;
                case UUID:
                    collection.setUUID("foo", UUID.randomUUID());
                    break;
                case OBJECT:
                    collection.setObject("foo", realm.createObject(AllTypes.class));
                    break;
                case MODEL_LIST:
                    collection.setList("foo", new RealmList<>());
                    break;
                case STRING_VALUE_LIST:
                    collection.setList("foo", new RealmList<>("Foo"));
                    break;
                case BOOLEAN_VALUE_LIST:
                    collection.setList("foo", new RealmList<>(true));
                    break;
                case BYTE_VALUE_LIST:
                    collection.setList("foo", new RealmList<>((byte) 1));
                    break;
                case SHORT_VALUE_LIST:
                    collection.setList("foo", new RealmList<>((short) 1));
                    break;
                case INTEGER_VALUE_LIST:
                    collection.setList("foo", new RealmList<>(1));
                    break;
                case LONG_VALUE_LIST:
                    collection.setList("foo", new RealmList<>(1L));
                    break;
                case FLOAT_VALUE_LIST:
                    collection.setList("foo", new RealmList<>(1.1F));
                    break;
                case DOUBLE_VALUE_LIST:
                    collection.setList("foo", new RealmList<>(1.1D));
                    break;
                case BINARY_VALUE_LIST:
                    collection.setList("foo", new RealmList<>(new byte[] {}));
                    break;
                case DATE_VALUE_LIST:
                    collection.setList("foo", new RealmList<>(new Date()));
                    break;
                case DECIMAL128_VALUE_LIST:
                    collection.setList("foo", new RealmList<>(new Decimal128(1000)));
                    break;
                case OBJECT_ID_VALUE_LIST:
                    collection.setList("foo", new RealmList<>(new ObjectId(TestHelper.randomObjectIdHexString())));
                    break;
                case UUID_VALUE_LIST:
                    collection.setList("foo", new RealmList<>(UUID.randomUUID()));
                    break;
                default:
                    fail("Unknown type: " + type);
            }
            fail(type + " should have thrown an exception");
        } catch (IllegalArgumentException e) {
            assertTrue(e.getMessage().contains("does not exist"));
        }
    }
}
Also used : ObjectId(org.bson.types.ObjectId) AllTypes(io.realm.entities.AllTypes) DictionaryAllTypes(io.realm.entities.DictionaryAllTypes) Decimal128(org.bson.types.Decimal128) Date(java.util.Date) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Aggregations

Decimal128 (org.bson.types.Decimal128)83 ObjectId (org.bson.types.ObjectId)50 Date (java.util.Date)46 Test (org.junit.Test)46 AllTypes (io.realm.entities.AllTypes)22 BigDecimal (java.math.BigDecimal)20 UUID (java.util.UUID)17 UiThreadTest (androidx.test.annotation.UiThreadTest)12 PrimaryKeyAsString (io.realm.entities.PrimaryKeyAsString)11 AllJavaTypes (io.realm.entities.AllJavaTypes)10 DictionaryAllTypes (io.realm.entities.DictionaryAllTypes)10 Dog (io.realm.entities.Dog)9 PrimaryKeyAsObjectId (io.realm.entities.PrimaryKeyAsObjectId)8 JSONObject (org.json.JSONObject)8 MappedAllJavaTypes (io.realm.entities.MappedAllJavaTypes)7 NonLatinFieldNames (io.realm.entities.NonLatinFieldNames)6 PrimaryKeyAsLong (io.realm.entities.PrimaryKeyAsLong)6 SimpleDateFormat (java.text.SimpleDateFormat)6 Calendar (java.util.Calendar)6 DefaultValueOfField (io.realm.entities.DefaultValueOfField)5