Search in sources :

Example 1 with DefaultValueSetter

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

the class RealmTests method createObject_defaultValueSetterInConstructor.

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

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