CarpaccioManager implements MappingManager.MappingManagerCallback { public void executeActionsOnView(View view) { executeActionsOnView(view, null); } CarpaccioManager(MappingManager mappingManager); void addView(View view); boolean isCarpaccioControlledView(View view); void registerController(Object controller); void registerControllers(Context context, String registerString); void executeActionsOnViews(); void executeActionsOnViews(List<View> views, Object mappedObject); void executeActionsOnView(View view); void executeActionsOnView(View view, Object mappedObject); void callActionOnView(CarpaccioAction action, View view); void mapObject(String name, Object object); Object getMappedObject(String name); void mapList(String mappedName, List list); void appendList(String mappedName, List list); List getMappedList(String name); Object registerAdapter(String mapName, Object adapter); T getAdapter(String mappedName); void addChildViews(View view); Object bindView(View view, String mapName, int position); Object bindView(View view, String mapName); void notifyAdapterDataSetChanded(Object adapter); void findCarpaccioControlledViews(View view); void findCarpaccioControlledViews(View view, List<View> listAddTo);  }
@Test public void testExecuteActionsOnView() throws Exception { Controller controller = spy(new Controller()); TextView textView = mock(TextView.class); doReturn("setColor(1)").when(textView).getTag(); carpaccioManager.carpaccioViews.add(textView); carpaccioManager.registerControllers.add(controller); carpaccioManager.executeActionsOnView(textView); verify(controller, atLeastOnce()).setColor(eq(textView), eq(1)); }
@Test public void testExecuteActionsOnView_mapping() throws Exception { Controller controller = spy(new Controller()); TextView textView = mock(TextView.class); doReturn("setText($user.name)").when(textView).getTag(); doNothing().when(mappingManager).callMappingOnView(any(CarpaccioAction.class),any(View.class),anyObject()); carpaccioManager.carpaccioViews.add(textView); carpaccioManager.registerControllers.add(controller); carpaccioManager.executeActionsOnView(textView); verify(mappingManager, atLeastOnce()).callMappingOnView(any(CarpaccioAction.class), any(View.class), anyObject()); verify(controller, never()).setText(eq(textView), anyString()); }
@Test public void testExecuteActionsOnView_mapping_EDIT_MODE() throws Exception { Controller controller = spy(new Controller()); Carpaccio.IN_EDIT_MODE = true; TextView textView = mock(TextView.class); doReturn("setText($user.name)").when(textView).getTag(); doNothing().when(mappingManager).callMappingOnView(any(CarpaccioAction.class), any(View.class), anyObject()); carpaccioManager.carpaccioViews.add(textView); carpaccioManager.registerControllers.add(controller); carpaccioManager.executeActionsOnView(textView); verify(controller, atLeastOnce()).setText(eq(textView), eq("$user.name")); }
@Test public void testExecuteActionsOnView_list() throws Exception { Controller controller = spy(new Controller()); TextView textView = mock(TextView.class); List<CarpaccioAction> carpaccioActionList = new ArrayList<>(); carpaccioActionList.add(new CarpaccioAction("setText(florent)")); doReturn(carpaccioActionList).when(textView).getTag(); carpaccioManager.carpaccioViews.add(textView); carpaccioManager.registerControllers.add(controller); carpaccioManager.executeActionsOnView(textView); verify(controller, atLeastOnce()).setText(eq(textView), eq("florent")); }