@Test public void testSetFieldValueForId() { TestRecord record = new TestRecord(); record.setName("Bla bla"); ReflectionUtil.setFieldValueForId(record, 1L); Assert.assertEquals(1L, record.getId().longValue()); }
@Test(expected = NoSuchFieldException.class) public void testSetFieldValueFromCursor() throws NoSuchFieldException { final TestRecord record = new TestRecord().setName("bla bla"); Long id = record.save(); record.setId(id); Cursor cursor = Select.from(TestRecord.class).getCursor(); TestRecord testRecord = new TestRecord(); Field field = TestRecord.class.getField("name"); ReflectionUtil.setFieldValueFromCursor(cursor, field, testRecord); }
@Test(expected = NoSuchFieldException.class) public void testAddFieldValueToColumn() throws NoSuchFieldException { SugarContext context = SugarContext.getSugarContext(); TestRecord record = new TestRecord(); record.setName("lala"); Field column = TestRecord.class.getField("name"); ContentValues values = new ContentValues(); ReflectionUtil.addFieldValueToColumn(values, column, record, context.getEntitiesMap()); Assert.assertEquals(record.getName(), values.getAsString("NAME")); }