Deserializer { public Resource setField(Resource resourceObject, String fieldName, Object data) { Field field = null; try { field = resourceObject.getClass().getDeclaredField(fieldName); field.setAccessible(true); field.set(resourceObject, data); } catch (NoSuchFieldException e) { Logger.debug("Field " + fieldName + " not found."); } catch (IllegalAccessException e) { Logger.debug("Could not access " + field.getName() + " field"); } return resourceObject; }  static void registerResourceClass(String typeName, Class resourceClass); Resource createObjectFromString(String resourceName); Resource setField(Resource resourceObject, String fieldName, Object data); Resource setIdField(Resource resourceObject, Object data); static HashMap<String, Class> getRegisteredClasses(); static void setRegisteredClasses(HashMap<String, Class> registeredClasses);  }
@Test public void testSetField() throws Exception { Deserializer deserializer = new Deserializer(); Article article = new Article(); Resource resource = deserializer.setField(article, "title", "My Title"); article = (Article)resource; assertEquals(article.getTitle(), "My Title"); }
@Test public void testSetFieldNoSuchFieldException() throws Exception { Deserializer deserializer = new Deserializer(); Article article = new Article(); Resource resource = deserializer.setField(article, "asdf", "My Title"); article = (Article)resource; assertNotNull(article); }