Beispiel #1
0
  // Setting a nullable field to null is not an error
  public void testSetNullField() {
    TestHelper.populateTestRealmForNullTests(testRealm);
    RealmResults<NullTypes> list = testRealm.allObjects(NullTypes.class);

    // 1 String
    testRealm.beginTransaction();
    list.first().setFieldStringNull(null);
    testRealm.commitTransaction();
    assertNull(testRealm.allObjects(NullTypes.class).first().getFieldStringNull());

    // 2 Bytes
    testRealm.beginTransaction();
    list.first().setFieldBytesNull(null);
    testRealm.commitTransaction();
    assertNull(testRealm.allObjects(NullTypes.class).first().getFieldBytesNull());

    // 3 Boolean
    testRealm.beginTransaction();
    list.first().setFieldBooleanNull(null);
    testRealm.commitTransaction();
    assertNull(testRealm.allObjects(NullTypes.class).first().getFieldBooleanNull());

    // 4 Byte
    // 5 Short 6 Integer 7 Long are skipped
    testRealm.beginTransaction();
    list.first().setFieldByteNull(null);
    testRealm.commitTransaction();
    assertNull(testRealm.allObjects(NullTypes.class).first().getFieldByteNull());

    // 8 Float
    testRealm.beginTransaction();
    list.first().setFieldFloatNull(null);
    testRealm.commitTransaction();
    assertNull(testRealm.allObjects(NullTypes.class).first().getFieldFloatNull());

    // 9 Double
    testRealm.beginTransaction();
    list.first().setFieldDoubleNull(null);
    testRealm.commitTransaction();
    assertNull(testRealm.allObjects(NullTypes.class).first().getFieldDoubleNull());

    // 10 Date
    testRealm.beginTransaction();
    list.first().setFieldDateNull(null);
    testRealm.commitTransaction();
    assertNull(testRealm.allObjects(NullTypes.class).first().getFieldDateNull());
  }
Beispiel #2
0
  // Setting a not-nullable field to null is an error
  public void testNullFieldNotNullableField() {
    TestHelper.populateTestRealmForNullTests(testRealm);
    RealmResults<NullTypes> list = testRealm.allObjects(NullTypes.class);

    // 1 String
    try {
      testRealm.beginTransaction();
      list.first().setFieldStringNotNull(null);
      fail();
    } catch (IllegalArgumentException ignored) {
    } finally {
      testRealm.cancelTransaction();
    }

    // 2 Bytes
    try {
      testRealm.beginTransaction();
      list.first().setFieldBytesNotNull(null);
      fail();
    } catch (IllegalArgumentException ignored) {
    } finally {
      testRealm.cancelTransaction();
    }

    // 3 Boolean
    try {
      testRealm.beginTransaction();
      list.first().setFieldBooleanNotNull(null);
      fail();
    } catch (IllegalArgumentException ignored) {
    } finally {
      testRealm.cancelTransaction();
    }

    // 4 Byte
    try {
      testRealm.beginTransaction();
      list.first().setFieldBytesNotNull(null);
      fail();
    } catch (IllegalArgumentException ignored) {
    } finally {
      testRealm.cancelTransaction();
    }

    // 5 Short 6 Integer 7 Long are skipped for this case, same with Bytes

    // 8 Float
    try {
      testRealm.beginTransaction();
      list.first().setFieldFloatNotNull(null);
      fail();
    } catch (IllegalArgumentException ignored) {
    } finally {
      testRealm.cancelTransaction();
    }

    // 9 Double
    try {
      testRealm.beginTransaction();
      list.first().setFieldDoubleNotNull(null);
      fail();
    } catch (IllegalArgumentException ignored) {
    } finally {
      testRealm.cancelTransaction();
    }

    // 10 Date
    try {
      testRealm.beginTransaction();
      list.first().setFieldDateNotNull(null);
      fail();
    } catch (IllegalArgumentException ignored) {
    } finally {
      testRealm.cancelTransaction();
    }
  }