MappingManager { public String evaluate(Object object, String call) { if (!call.contains(".")) { CarpaccioLogger.d(TAG, "call " + call + " on " + object.getClass().getName()); return object.toString(); } else { String function = call.substring(call.indexOf('.') + 1); String callToGetObject; if (function.contains(".")) { callToGetObject = function.substring(0, function.indexOf('.')); } else { callToGetObject = function; } String realCallToGetObject = getFunctionName(callToGetObject); Object newObject = CarpaccioHelper.callFunction(object, realCallToGetObject); if (newObject != null) { CarpaccioLogger.d(TAG, "call " + realCallToGetObject + " return =" + newObject.getClass().getName()); if (newObject instanceof String) { return (String) newObject; } else if (newObject instanceof Number) { return String.valueOf(newObject); } else return evaluate(newObject, function); } else { CarpaccioLogger.d(TAG, "call " + realCallToGetObject + " return = NULL"); return null; } } } MappingManager(); static boolean isCallMapping(String[] args); String evaluate(Object object, String call); void mapObject(String name, Object object); void mapList(String name, List list); void appendList(String mappedName, List list); List getMappedList(String name); void callMappingOnView(CarpaccioAction action, View view, Object mappedObject); MappingManagerCallback getMappingManagerCallback(); void setMappingManagerCallback(MappingManagerCallback mappingManagerCallback); Object getMappedListsObject(String name, int position); Object getMappedObject(String name);  }
@Test public void testEvaluateExpression(){ ObjectToEvaluate object = new ObjectToEvaluate(); String value = mappingManager.evaluate(object, "object.getName()"); assertEquals("florent",value); }
@Test public void testEvaluateExpression_reduce(){ ObjectToEvaluate object = new ObjectToEvaluate(); String value = mappingManager.evaluate(object, "object.name"); assertEquals("florent",value); }
@Test public void testEvaluateExpression_toString(){ ObjectToEvaluate object = new ObjectToEvaluate(); String value = mappingManager.evaluate(object,"object"); assertEquals("ThisIsMyToString",value); }
@Test public void testEvaluateExpression_multiple_toString(){ ObjectToEvaluate object = new ObjectToEvaluate(); String value = mappingManager.evaluate(object, "object.image"); assertEquals("IamAnImage",value); }
@Test public void testEvaluateExpression_multiple_value(){ ObjectToEvaluate object = new ObjectToEvaluate(); String value = mappingManager.evaluate(object, "object.image.getUrl()"); assertEquals("www.MyImage",value); }
@Test public void testEvaluateExpression_int(){ ObjectToEvaluate object = new ObjectToEvaluate(); String value = mappingManager.evaluate(object, "object.count"); assertEquals("3",value); }