FieldUtils { public static void setValue(Object object, Field field, Object value) throws RdfException { if (Modifier.isPublic(field.getModifiers())) { setByField(object, field, value); } else { setBySetter(object, field, value); } } private  FieldUtils(); static Object getValue(Object object, Field field); static void setValue(Object object, Field field, Object value);  }
@Test public void setPublic() throws Exception { TestClass entity = new TestClass(); Field field = TestClass.class.getDeclaredField("publicValue"); FieldUtils.setValue(entity, field, "string"); }
@Test public void setByGetter() throws Exception { TestClass entity = new TestClass(); Field field = TestClass.class.getDeclaredField("protectedValue"); FieldUtils.setValue(entity, field, "string"); }
@Test(expected = RdfException.class) public void setFailed() throws Exception { TestClass entity = new TestClass(); Field field = TestClass.class.getDeclaredField("inaccessible"); FieldUtils.setValue(entity, field, "string"); }