use of io.realm.entities.NullTypes in project realm-java by realm.
the class TestHelper method populateAllNullRowsForNumericTesting.
public static void populateAllNullRowsForNumericTesting(Realm realm) {
NullTypes nullTypes1 = new NullTypes();
nullTypes1.setId(1);
NullTypes nullTypes2 = new NullTypes();
nullTypes2.setId(2);
realm.beginTransaction();
realm.copyToRealm(nullTypes1);
realm.copyToRealm(nullTypes2);
realm.commitTransaction();
}
use of io.realm.entities.NullTypes in project realm-java by realm.
the class RealmObjectTests method set_nullValuesToNonNullableFields.
// Tries to store null values in non-nullable fields.
@Test
public void set_nullValuesToNonNullableFields() {
try {
realm.beginTransaction();
NullTypes nullTypes = realm.createObject(NullTypes.class, 0);
// 1 String
try {
nullTypes.setFieldStringNotNull(null);
fail();
} catch (IllegalArgumentException ignored) {
}
// 2 Bytes
try {
nullTypes.setFieldBytesNotNull(null);
fail();
} catch (IllegalArgumentException ignored) {
}
// 3 Boolean
try {
nullTypes.setFieldBooleanNotNull(null);
fail();
} catch (IllegalArgumentException ignored) {
}
// 4 Byte
try {
nullTypes.setFieldByteNotNull(null);
fail();
} catch (IllegalArgumentException ignored) {
}
// 5 Short
try {
nullTypes.setFieldShortNotNull(null);
fail();
} catch (IllegalArgumentException ignored) {
}
// 6 Integer
try {
nullTypes.setFieldIntegerNotNull(null);
fail();
} catch (IllegalArgumentException ignored) {
}
// 7 Long
try {
nullTypes.setFieldLongNotNull(null);
fail();
} catch (IllegalArgumentException ignored) {
}
// 8 Float
try {
nullTypes.setFieldFloatNotNull(null);
fail();
} catch (IllegalArgumentException ignored) {
}
// 9 Double
try {
nullTypes.setFieldDoubleNotNull(null);
fail();
} catch (IllegalArgumentException ignored) {
}
// 10 Date
try {
nullTypes.setFieldDateNotNull(null);
fail();
} catch (IllegalArgumentException ignored) {
}
} finally {
realm.cancelTransaction();
}
}
use of io.realm.entities.NullTypes in project realm-java by realm.
the class RealmQueryTests method isNull_differentThanEmpty.
@Test
public void isNull_differentThanEmpty() {
// Make sure that isNull doesn't match empty string ""
realm.executeTransaction(r -> {
r.delete(NullTypes.class);
NullTypes obj = new NullTypes();
obj.setId(1);
obj.setFieldStringNull(null);
r.insert(obj);
obj = new NullTypes();
obj.setId(2);
obj.setFieldStringNull("");
r.insert(obj);
obj = new NullTypes();
obj.setId(3);
obj.setFieldStringNull("foo");
r.insert(obj);
});
assertEquals(3, realm.where(NullTypes.class).findAll().size());
RealmResults<NullTypes> results = realm.where(NullTypes.class).isNull(NullTypes.FIELD_STRING_NULL).findAll();
assertEquals(1, results.size());
assertNull(results.first().getFieldStringNull());
results = realm.where(NullTypes.class).isEmpty(NullTypes.FIELD_STRING_NULL).findAll();
assertEquals(1, results.size());
assertEquals("", results.first().getFieldStringNull());
}
use of io.realm.entities.NullTypes in project realm-java by realm.
the class RealmObjectTests method set_get_nullOnNullableFields.
// Stores and retrieves null values for nullable fields.
@Test
public void set_get_nullOnNullableFields() {
realm.beginTransaction();
NullTypes nullTypes = realm.createObject(NullTypes.class, 0);
// 1 String
nullTypes.setFieldStringNull(null);
// 2 Bytes
nullTypes.setFieldBytesNull(null);
// 3 Boolean
nullTypes.setFieldBooleanNull(null);
// 4 Byte
nullTypes.setFieldByteNull(null);
// 5 Short
nullTypes.setFieldShortNull(null);
// 6 Integer
nullTypes.setFieldIntegerNull(null);
// 7 Long
nullTypes.setFieldLongNull(null);
// 8 Float
nullTypes.setFieldFloatNull(null);
// 9 Double
nullTypes.setFieldDoubleNull(null);
// 10 Date
nullTypes.setFieldDateNull(null);
realm.commitTransaction();
nullTypes = realm.where(NullTypes.class).findFirst();
// 1 String
assertNull(nullTypes.getFieldStringNull());
// 2 Bytes
assertNull(nullTypes.getFieldBytesNull());
// 3 Boolean
assertNull(nullTypes.getFieldBooleanNull());
// 4 Byte
assertNull(nullTypes.getFieldByteNull());
// 5 Short
assertNull(nullTypes.getFieldShortNull());
// 6 Integer
assertNull(nullTypes.getFieldIntegerNull());
// 7 Long
assertNull(nullTypes.getFieldLongNull());
// 8 Float
assertNull(nullTypes.getFieldFloatNull());
// 9 Double
assertNull(nullTypes.getFieldDoubleNull());
// 10 Date
assertNull(nullTypes.getFieldDateNull());
}
use of io.realm.entities.NullTypes in project realm-java by realm.
the class RealmObjectTests method defaultValuesForNewObject.
@Test
public void defaultValuesForNewObject() {
realm.beginTransaction();
NullTypes nullTypes = realm.createObject(NullTypes.class, 0);
realm.commitTransaction();
assertNotNull(nullTypes);
assertEquals(0, nullTypes.getId());
// 1 String
assertEquals("", nullTypes.getFieldStringNotNull());
assertNull(nullTypes.getFieldStringNull());
// 2 Bytes
assertArrayEquals(new byte[0], nullTypes.getFieldBytesNotNull());
assertNull(nullTypes.getFieldByteNull());
// 3 Boolean
assertFalse(nullTypes.getFieldBooleanNotNull());
assertNull(nullTypes.getFieldBooleanNull());
// 4 Byte
assertEquals(0, nullTypes.getFieldByteNotNull().byteValue());
assertNull(nullTypes.getFieldByteNull());
// 5 Short
assertEquals(0, nullTypes.getFieldShortNotNull().shortValue());
assertNull(nullTypes.getFieldShortNull());
// 6 Integer
assertEquals(0, nullTypes.getFieldIntegerNotNull().intValue());
assertNull(nullTypes.getFieldIntegerNull());
// 7 Long
assertEquals(0, nullTypes.getFieldLongNotNull().longValue());
assertNull(nullTypes.getFieldLongNull());
// 8 Float
assertEquals(0F, nullTypes.getFieldFloatNotNull(), 0.0F);
assertNull(nullTypes.getFieldFloatNull());
// 9 Double
assertEquals(0D, nullTypes.getFieldDoubleNotNull(), 0.0D);
assertNull(nullTypes.getFieldDoubleNull());
// 10 Date
assertEquals(new Date(0), nullTypes.getFieldDateNotNull());
assertNull(nullTypes.getFieldDateNull());
}
Aggregations