Search in sources :

Example 6 with PrimaryKeyAsBoxedShort

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

the class RealmTests method createObjectWithPrimaryKey_null.

@Test
public void createObjectWithPrimaryKey_null() {
    // Byte
    realm.beginTransaction();
    PrimaryKeyAsBoxedByte primaryKeyAsBoxedByte = realm.createObject(PrimaryKeyAsBoxedByte.class, null);
    realm.commitTransaction();
    assertEquals(1, realm.where(PrimaryKeyAsBoxedByte.class).count());
    assertNull(primaryKeyAsBoxedByte.getId());
    // Short
    realm.beginTransaction();
    PrimaryKeyAsBoxedShort primaryKeyAsBoxedShort = realm.createObject(PrimaryKeyAsBoxedShort.class, null);
    realm.commitTransaction();
    assertEquals(1, realm.where(PrimaryKeyAsBoxedShort.class).count());
    assertNull(primaryKeyAsBoxedShort.getId());
    // Integer
    realm.beginTransaction();
    PrimaryKeyAsBoxedInteger primaryKeyAsBoxedInteger = realm.createObject(PrimaryKeyAsBoxedInteger.class, null);
    realm.commitTransaction();
    assertEquals(1, realm.where(PrimaryKeyAsBoxedInteger.class).count());
    assertNull(primaryKeyAsBoxedInteger.getId());
    // Long
    realm.beginTransaction();
    PrimaryKeyAsBoxedLong primaryKeyAsBoxedLong = realm.createObject(PrimaryKeyAsBoxedLong.class, null);
    realm.commitTransaction();
    assertEquals(1, realm.where(PrimaryKeyAsBoxedLong.class).count());
    assertNull(primaryKeyAsBoxedLong.getId());
    // String
    realm.beginTransaction();
    PrimaryKeyAsString primaryKeyAsString = realm.createObject(PrimaryKeyAsString.class, null);
    realm.commitTransaction();
    assertEquals(1, realm.where(PrimaryKeyAsString.class).count());
    assertNull(primaryKeyAsString.getName());
}
Also used : PrimaryKeyAsBoxedShort(io.realm.entities.PrimaryKeyAsBoxedShort) PrimaryKeyAsBoxedByte(io.realm.entities.PrimaryKeyAsBoxedByte) PrimaryKeyAsBoxedInteger(io.realm.entities.PrimaryKeyAsBoxedInteger) PrimaryKeyAsString(io.realm.entities.PrimaryKeyAsString) PrimaryKeyAsBoxedLong(io.realm.entities.PrimaryKeyAsBoxedLong) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest)

Aggregations

PrimaryKeyAsBoxedShort (io.realm.entities.PrimaryKeyAsBoxedShort)6 PrimaryKeyAsString (io.realm.entities.PrimaryKeyAsString)4 Test (org.junit.Test)4 UiThreadTest (androidx.test.annotation.UiThreadTest)3 PrimaryKeyAsBoxedByte (io.realm.entities.PrimaryKeyAsBoxedByte)2 PrimaryKeyAsBoxedInteger (io.realm.entities.PrimaryKeyAsBoxedInteger)2 PrimaryKeyAsBoxedLong (io.realm.entities.PrimaryKeyAsBoxedLong)2 PrimaryKeyRequiredAsString (io.realm.entities.PrimaryKeyRequiredAsString)2 RealmPrimaryKeyConstraintException (io.realm.exceptions.RealmPrimaryKeyConstraintException)1