CarpaccioManager implements MappingManager.MappingManagerCallback { public void executeActionsOnViews() { executeActionsOnViews(carpaccioViews, 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 testExecuteActionsOnViews() throws Exception { Controller controller = spy(new Controller()); TextView textView = mock(TextView.class); doReturn("setText(florent)").when(textView).getTag(); doReturn("setText(florent)").when(textView).getTag(); carpaccioManager.carpaccioViews.add(textView); carpaccioManager.registerControllers.add(controller); carpaccioManager.executeActionsOnViews(); verify(controller, atLeastOnce()).setText(eq(textView), eq("florent")); verify(textView, atLeastOnce()).setText(eq("florent")); }
@Test public void testExecuteActionsOnViews_text() throws Exception { Controller controller = spy(new Controller()); TextView textView = mock(TextView.class); doReturn("$user.name").when(textView).getText(); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { tmpTag = invocation.getArguments()[0]; return null; } }).when(textView).setTag(any()); carpaccioManager.carpaccioViews.add(textView); carpaccioManager.registerControllers.add(controller); carpaccioManager.executeActionsOnViews(); assertNotNull(tmpTag); }
@Test public void testExecuteActionsOnViews_text_tagString() throws Exception { Controller controller = spy(new Controller()); TextView textView = mock(TextView.class); doReturn("$user.name").when(textView).getText(); doReturn("setFont(font)").when(textView).getTag(); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { tmpTag = invocation.getArguments()[0]; return null; } }).when(textView).setTag(any()); carpaccioManager.carpaccioViews.add(textView); carpaccioManager.registerControllers.add(controller); carpaccioManager.executeActionsOnViews(); assertEquals("setFont(font);setText($user.name)", tmpTag); }
@Test public void testExecuteActionsOnViews_text_tagList() throws Exception { Controller controller = spy(new Controller()); TextView textView = mock(TextView.class); doReturn("$user.name").when(textView).getText(); List<CarpaccioAction> actions = new ArrayList<>(); actions.add(new CarpaccioAction("setFont(font)")); doReturn(actions).when(textView).getTag(); carpaccioManager.carpaccioViews.add(textView); carpaccioManager.registerControllers.add(controller); carpaccioManager.executeActionsOnViews(); List<CarpaccioAction> expected = new ArrayList<>(); expected.add(new CarpaccioAction("setFont(font)")); expected.add(new CarpaccioAction("setText($user.name)")); assertEquals(expected,textView.getTag()); }
@Test public void testExecuteActionsOnViews2() throws Exception { Controller controller = spy(new Controller()); TextView textView = mock(TextView.class); doReturn("setFont(florent)").when(textView).getTag(); carpaccioManager.carpaccioViews.add(textView); carpaccioManager.registerControllers.add(controller); carpaccioManager.executeActionsOnViews(); verify(controller, never()).setText(eq(textView), eq("florent")); verify(textView, never()).setText(eq("florent")); }