Search in sources :

Example 1 with DefaultValueConstructor

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

the class RealmTests method createObject_defaultValueFromModelConstructor.

@Test
public void createObject_defaultValueFromModelConstructor() {
    realm.executeTransaction(new Realm.Transaction() {

        @Override
        public void execute(Realm realm) {
            // Creates a DefaultValueConstructor with non-default primary key value.
            realm.createObject(DefaultValueConstructor.class, DefaultValueConstructor.FIELD_LONG_PRIMARY_KEY_DEFAULT_VALUE * 3);
        }
    });
    final String createdRandomString = DefaultValueConstructor.lastRandomStringValue;
    testOneObjectFound(realm, DefaultValueConstructor.class, DefaultValueConstructor.FIELD_STRING, DefaultValueConstructor.FIELD_STRING_DEFAULT_VALUE);
    testOneObjectFound(realm, DefaultValueConstructor.class, DefaultValueConstructor.FIELD_RANDOM_STRING, createdRandomString);
    testOneObjectFound(realm, DefaultValueConstructor.class, DefaultValueConstructor.FIELD_SHORT, DefaultValueConstructor.FIELD_SHORT_DEFAULT_VALUE);
    testOneObjectFound(realm, DefaultValueConstructor.class, DefaultValueConstructor.FIELD_INT, DefaultValueConstructor.FIELD_INT_DEFAULT_VALUE);
    // Default value for pk must be ignored.
    testNoObjectFound(realm, DefaultValueConstructor.class, DefaultValueConstructor.FIELD_LONG_PRIMARY_KEY, DefaultValueConstructor.FIELD_LONG_PRIMARY_KEY_DEFAULT_VALUE);
    testOneObjectFound(realm, DefaultValueConstructor.class, DefaultValueConstructor.FIELD_LONG_PRIMARY_KEY, DefaultValueConstructor.FIELD_LONG_PRIMARY_KEY_DEFAULT_VALUE * 3);
    testOneObjectFound(realm, DefaultValueConstructor.class, DefaultValueConstructor.FIELD_LONG, DefaultValueConstructor.FIELD_LONG_DEFAULT_VALUE);
    testOneObjectFound(realm, DefaultValueConstructor.class, DefaultValueConstructor.FIELD_BYTE, DefaultValueConstructor.FIELD_BYTE_DEFAULT_VALUE);
    testOneObjectFound(realm, DefaultValueConstructor.class, DefaultValueConstructor.FIELD_FLOAT, DefaultValueConstructor.FIELD_FLOAT_DEFAULT_VALUE);
    testOneObjectFound(realm, DefaultValueConstructor.class, DefaultValueConstructor.FIELD_DOUBLE, DefaultValueConstructor.FIELD_DOUBLE_DEFAULT_VALUE);
    testOneObjectFound(realm, DefaultValueConstructor.class, DefaultValueConstructor.FIELD_BOOLEAN, DefaultValueConstructor.FIELD_BOOLEAN_DEFAULT_VALUE);
    testOneObjectFound(realm, DefaultValueConstructor.class, DefaultValueConstructor.FIELD_DATE, DefaultValueConstructor.FIELD_DATE_DEFAULT_VALUE);
    testOneObjectFound(realm, DefaultValueConstructor.class, DefaultValueConstructor.FIELD_BINARY, DefaultValueConstructor.FIELD_BINARY_DEFAULT_VALUE);
    testOneObjectFound(realm, DefaultValueConstructor.class, DefaultValueConstructor.FIELD_OBJECT + "." + RandomPrimaryKey.FIELD_INT, RandomPrimaryKey.FIELD_INT_DEFAULT_VALUE);
    testOneObjectFound(realm, DefaultValueConstructor.class, DefaultValueConstructor.FIELD_LIST + "." + RandomPrimaryKey.FIELD_INT, RandomPrimaryKey.FIELD_INT_DEFAULT_VALUE);
}
Also used : DefaultValueConstructor(io.realm.entities.DefaultValueConstructor) PrimaryKeyRequiredAsString(io.realm.entities.PrimaryKeyRequiredAsString) PrimaryKeyAsString(io.realm.entities.PrimaryKeyAsString) OsSharedRealm(io.realm.internal.OsSharedRealm) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Aggregations

UiThreadTest (androidx.test.annotation.UiThreadTest)1 DefaultValueConstructor (io.realm.entities.DefaultValueConstructor)1 PrimaryKeyAsString (io.realm.entities.PrimaryKeyAsString)1 PrimaryKeyRequiredAsString (io.realm.entities.PrimaryKeyRequiredAsString)1 OsSharedRealm (io.realm.internal.OsSharedRealm)1 Test (org.junit.Test)1