MappingManager { public void mapObject(String name, Object object) { mappedObjects.put(name, object); CarpaccioLogger.d(TAG, "map object [" + name + "," + object.getClass().getName() + "]"); List<MappingWaiting> waitingsForThisName = mappingWaitings.get(name); if (waitingsForThisName != null) { for (MappingWaiting mappingWaiting : waitingsForThisName) { CarpaccioLogger.d(TAG, "call waiting mapped " + mappingWaiting.getCarpaccioAction().getCompleteCall()); String value = evaluate(object, mappingWaiting.getCall()); CarpaccioLogger.d(TAG, "call waiting value = " + value); if (value != null && mappingManagerCallback != null) { mappingWaiting.getCarpaccioAction().setValues(new String[]{value}); mappingManagerCallback.callActionOnView(mappingWaiting.getCarpaccioAction(), mappingWaiting.getView()); } } waitingsForThisName.clear(); mappingWaitings.remove(name); } } 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 testMapObject() throws Exception { User user = new User("florent"); String name = "user"; CarpaccioAction carpaccioAction = new CarpaccioAction("setText($user.getName())"); View view = mock(View.class); { ArrayList list = new ArrayList(); list.add(new MappingWaiting(view,carpaccioAction,"user.getName()","user")); mappingManager.mappingWaitings.put("user", list); } mappingManager.mapObject(name,user); assertTrue(mappingManager.mappedObjects.containsKey(name)); assertEquals(user, mappingManager.mappedObjects.get(name)); verify(callback,atLeastOnce()).callActionOnView(eq(carpaccioAction), eq(view)); assertEquals("florent", carpaccioAction.getValues()[0]); }
@Test public void testMapObject2() throws Exception { User user = new User("florent"); String name = "user"; View view = mock(View.class); CarpaccioAction carpaccioAction = new CarpaccioAction("setText($user.name)"); { ArrayList list = new ArrayList(); list.add(new MappingWaiting(view,carpaccioAction,"user.getName()","user")); mappingManager.mappingWaitings.put("user", list); } mappingManager.mapObject(name, user); assertTrue(mappingManager.mappedObjects.containsKey(name)); assertEquals(user, mappingManager.mappedObjects.get(name)); verify(callback,atLeastOnce()).callActionOnView(eq(carpaccioAction), eq(view)); assertEquals("florent", carpaccioAction.getValues()[0]); }
@Test public void testMapObject_noFunction() throws Exception { User user = new User("florent"); String name = "user"; View view = mock(View.class); CarpaccioAction carpaccioAction = new CarpaccioAction("setText($user)"); { ArrayList list = new ArrayList(); list.add(new MappingWaiting(view,carpaccioAction,"user","user")); mappingManager.mappingWaitings.put("user", list); } mappingManager.mapObject(name,user); assertTrue(mappingManager.mappedObjects.containsKey(name)); assertEquals(user, mappingManager.mappedObjects.get(name)); verify(callback,atLeastOnce()).callActionOnView(eq(carpaccioAction), eq(view)); verify(callback,atLeastOnce()).callActionOnView(eq(carpaccioAction), eq(view)); assertEquals("nameToString", carpaccioAction.getValues()[0]); }
@Test public void testMapObject_fail() throws Exception { User user = new User("florent"); String name = "user"; View view = mock(View.class); CarpaccioAction carpaccioAction = new CarpaccioAction("setTexteu($user.getName())"); { ArrayList list = new ArrayList(); list.add(new MappingWaiting(view,carpaccioAction,"setTexteu","user")); mappingManager.mappingWaitings.put("user", list); } mappingManager.mapObject(name, user); assertTrue(mappingManager.mappedObjects.containsKey(name)); assertEquals(user, mappingManager.mappedObjects.get(name)); verify(callback,atLeastOnce()).callActionOnView(eq(carpaccioAction), eq(view)); }