MappingManager { public void callMappingOnView(CarpaccioAction action, View view, Object mappedObject) { if (action.isCallMapping()) { CarpaccioLogger.d(TAG, "callMappingOnView mapping=" + mappedObject + " action=" + action.getCompleteCall() + " view=" + view.getClass().getName()); String arg = action.getArgs()[0]; String objectName = null; String call; if (arg.contains(".")) { call = arg.substring(1, arg.length()); objectName = call.substring(0, arg.indexOf(".") - 1); } else { objectName = arg.substring(1, arg.length()); call = objectName; } if (mappedObject != null) { String value = evaluate(mappedObject, call); CarpaccioLogger.d(TAG, "callMappingOnView evaluate(" + call + ")" + " on " + mappedObject.getClass().getName() + " returned " + value); action.setValues(new String[]{value}); mappingManagerCallback.callActionOnView(action, view); } else { List<MappingWaiting> waitings = mappingWaitings.get(objectName); if (waitings == null) waitings = new ArrayList<>(); waitings.add(new MappingWaiting(view, action, call, objectName)); CarpaccioLogger.d(TAG, "added to waiting " + call + " for " + view.getClass().getName()); mappingWaitings.put(objectName, waitings); } } } 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 testCallMapping() throws Exception { View view = mock(View.class); CarpaccioAction carpaccioAction = new CarpaccioAction("setText($user)"); mappingManager.callMappingOnView(carpaccioAction,view,null); assertTrue(mappingManager.mappingWaitings.containsKey("user")); MappingWaiting addedWaiting = mappingManager.mappingWaitings.get("user").get(0); assertNotNull(addedWaiting); assertEquals("user", addedWaiting.objectName); assertEquals("user", addedWaiting.call); assertEquals(carpaccioAction, addedWaiting.carpaccioAction); assertEquals(view, addedWaiting.view); }
@Test public void testCallMapping_withFunction() throws Exception { View view = mock(View.class); CarpaccioAction carpaccioAction = new CarpaccioAction("setText($user.getName())"); mappingManager.callMappingOnView(carpaccioAction,view,null); assertTrue(mappingManager.mappingWaitings.containsKey("user")); MappingWaiting addedWaiting = mappingManager.mappingWaitings.get("user").get(0); assertNotNull(addedWaiting); assertEquals("user", addedWaiting.objectName); assertEquals("user.getName()", addedWaiting.call); assertEquals(carpaccioAction, addedWaiting.carpaccioAction); assertEquals(view, addedWaiting.view); }