use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class DynamicRealmObjectTests method untypedSetter_illegalImplicitConversionThrows.
@Test
public void untypedSetter_illegalImplicitConversionThrows() {
realm.beginTransaction();
AllJavaTypes obj = realm.createObject(AllJavaTypes.class, 0);
DynamicRealmObject dObj = new DynamicRealmObject(obj);
try {
for (SupportedType type : SupportedType.values()) {
try {
switch(type) {
case SHORT:
dObj.set(AllJavaTypes.FIELD_SHORT, "foo");
break;
case INT:
dObj.set(AllJavaTypes.FIELD_INT, "foo");
break;
case LONG:
dObj.set(AllJavaTypes.FIELD_ID, "foo");
break;
case FLOAT:
dObj.set(AllJavaTypes.FIELD_FLOAT, "foo");
break;
case DOUBLE:
dObj.set(AllJavaTypes.FIELD_DOUBLE, "foo");
break;
case DATE:
dObj.set(AllJavaTypes.FIELD_DATE, "foo");
break;
// Boolean is special as it returns false for all strings != "true"
case BOOLEAN:
case BYTE:
case OBJECT:
case LIST:
case STRING:
case BINARY:
continue;
default:
fail("Unknown type: " + type);
}
fail(type + " failed");
} catch (IllegalArgumentException ignored) {
} catch (RealmException e) {
if (!(e.getCause() instanceof ParseException)) {
// Providing "foo" to the date parser will blow up with a RealmException
// and the cause will be a ParseException.
fail(type + " failed");
}
}
}
} finally {
realm.cancelTransaction();
}
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class DynamicRealmObjectTests method equals_standardAndDynamicObjectsNotEqual.
@Test
public void equals_standardAndDynamicObjectsNotEqual() {
AllJavaTypes standardObj = realm.where(AllJavaTypes.class).findFirst();
//noinspection EqualsBetweenInconvertibleTypes
assertFalse(dObjTyped.equals(standardObj));
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class DynamicRealmObjectTests method equals.
@Test
public void equals() {
AllJavaTypes obj1 = realm.where(AllJavaTypes.class).findFirst();
AllJavaTypes obj2 = realm.where(AllJavaTypes.class).findFirst();
DynamicRealmObject dObj1 = new DynamicRealmObject(obj1);
DynamicRealmObject dObj2 = new DynamicRealmObject(obj2);
assertTrue(dObj1.equals(dObj2));
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class DynamicRealmObjectTests method typedGettersAndSetters.
// Tests all typed setters/setters.
@Test
public void typedGettersAndSetters() {
realm.beginTransaction();
AllJavaTypes obj = realm.createObject(AllJavaTypes.class, 0);
DynamicRealmObject dObj = new DynamicRealmObject(obj);
try {
for (SupportedType type : SupportedType.values()) {
switch(type) {
case BOOLEAN:
dObj.setBoolean(AllJavaTypes.FIELD_BOOLEAN, true);
assertTrue(dObj.getBoolean(AllJavaTypes.FIELD_BOOLEAN));
break;
case SHORT:
dObj.setShort(AllJavaTypes.FIELD_SHORT, (short) 42);
assertEquals(42, dObj.getShort(AllJavaTypes.FIELD_SHORT));
break;
case INT:
dObj.setInt(AllJavaTypes.FIELD_INT, 42);
assertEquals(42, dObj.getInt(AllJavaTypes.FIELD_INT));
break;
case LONG:
dObj.setLong(AllJavaTypes.FIELD_LONG, 42L);
assertEquals(42, dObj.getLong(AllJavaTypes.FIELD_LONG));
break;
case BYTE:
dObj.setByte(AllJavaTypes.FIELD_BYTE, (byte) 4);
assertEquals(4, dObj.getByte(AllJavaTypes.FIELD_BYTE));
break;
case FLOAT:
dObj.setFloat(AllJavaTypes.FIELD_FLOAT, 1.23f);
assertEquals(1.23f, dObj.getFloat(AllJavaTypes.FIELD_FLOAT), 0f);
break;
case DOUBLE:
dObj.setDouble(AllJavaTypes.FIELD_DOUBLE, 1.234d);
assertEquals(1.234d, dObj.getDouble(AllJavaTypes.FIELD_DOUBLE), 0d);
break;
case STRING:
dObj.setString(AllJavaTypes.FIELD_STRING, "str");
assertEquals("str", dObj.getString(AllJavaTypes.FIELD_STRING));
break;
case BINARY:
dObj.setBlob(AllJavaTypes.FIELD_BINARY, new byte[] { 1, 2, 3 });
assertArrayEquals(new byte[] { 1, 2, 3 }, dObj.getBlob(AllJavaTypes.FIELD_BINARY));
break;
case DATE:
dObj.setDate(AllJavaTypes.FIELD_DATE, new Date(1000));
assertEquals(new Date(1000), dObj.getDate(AllJavaTypes.FIELD_DATE));
break;
case OBJECT:
dObj.setObject(AllJavaTypes.FIELD_OBJECT, dObj);
assertEquals(dObj, dObj.getObject(AllJavaTypes.FIELD_OBJECT));
break;
case LIST:
// Ignores. See testGetList/testSetList.
break;
default:
fail();
}
}
} finally {
realm.cancelTransaction();
}
}
use of io.realm.entities.AllJavaTypes in project realm-java by realm.
the class LinkingObjectsManagedTests method basic_singleBacklinkList.
// Setting a linked list field creates the correct backlink
@Test
public void basic_singleBacklinkList() {
realm.beginTransaction();
AllJavaTypes child = realm.createObject(AllJavaTypes.class, 1);
AllJavaTypes parent = realm.createObject(AllJavaTypes.class, 2);
parent.getFieldList().add(child);
realm.commitTransaction();
assertEquals(1, child.getListParents().size());
assertTrue(child.getListParents().contains(parent));
}
Aggregations