CarpaccioHelper { public static Method callFunction(Object object, String name, View view, Object[] args) { if (object != null && name != null && view != null && args != null) { Method method = null; Class viewClass = View.class; for (Method containedMethods : object.getClass().getMethods()) { if (name.equals(containedMethods.getName()) && containedMethods.getParameterTypes().length == args.length + 1) { method = containedMethods; break; } } return callMethod(object, method, name, view, args); } return null; }  static Object construct(String name); static Class[] getClassesWithHeaderClass(Object[] args, Class headerClass); static Class[] getClasses(Object[] args); static Object[] getArgumentsWithView(View view, Class[] parametersType, Object[] args); static String getFunctionName(String tag); static String[] getAttributes(String tag); static Object removeTag(View view, String actionName); static String[] trim(String[] strings); static ObjectAndMethod findObjectWithThisMethod(List<Object> objects, String function, int numberOfParams); static Method callFunction(Object object, String name, View view, Object[] args); static Method callMethod(Object object, Method method, String name, View view, Object[] args); static T callFunction(Object object, String name); static T callFunction(Object object, String name, Object[] args); static Integer stringToInt(String s); static Double stringToDouble(String s); static Long stringToLong(String s); static Float stringToFloat(String s); static boolean isNumber(Class destinationClass); static Object stringToNumber(String s, Class destinationClass); static T findParentOfClass(View view, Class<T> theClass); static Carpaccio findParentCarpaccio(View view); static Carpaccio registerToParentCarpaccio(View view); static String TAG; static boolean LOG_FAILURES; }
@Test public void testCallFunctionOnObjects() throws Exception { View mockView = mock(View.class); TestObject spyObject = spy(new TestObject()); String[] args = new String[]{"value1"}; Method method = CarpaccioHelper.callFunction(spyObject, "getName", mockView, args); assertNotNull(method); verify(spyObject, atLeastOnce()).getName(eq(mockView), eq("value1")); }
@Test public void testCallFunction() throws Exception { TestObject spyObject = spy(new TestObject()); String pseudo = CarpaccioHelper.callFunction(spyObject, "getPseudo"); assertEquals("florent", pseudo); verify(spyObject, atLeastOnce()).getPseudo(); verify(spyObject, never()).getName(any(View.class), anyString()); verify(spyObject, never()).getFamily(anyString()); }
@Test public void testCallFunction_fail() throws Exception { TestObject spyObject = spy(new TestObject()); String pseudo = CarpaccioHelper.callFunction(spyObject, "getEmptyNooooo"); assertNull(pseudo); verify(spyObject, never()).getPseudo(); verify(spyObject, never()).getName(any(View.class), anyString()); verify(spyObject, never()).getFamily(anyString()); }
@Test public void testCallFunction1() throws Exception { TestObject spyObject = spy(new TestObject()); String[] args = new String[]{"florent"}; String pseudo = CarpaccioHelper.callFunction(spyObject, "getFamily", args); assertEquals("hello florent", pseudo); verify(spyObject, atLeastOnce()).getFamily(eq("florent")); verify(spyObject, never()).getPseudo(); verify(spyObject, never()).getName(any(View.class), anyString()); }
@Test public void testCallFunction1_fail() throws Exception { TestObject spyObject = spy(new TestObject()); String[] args = new String[]{"florent", "florent"}; String pseudo = CarpaccioHelper.callFunction(spyObject, "getFamily", args); assertNull(pseudo); verify(spyObject, never()).getFamily(eq("florent")); verify(spyObject, never()).getPseudo(); verify(spyObject, never()).getName(any(View.class), anyString()); }
@Test public void testCallFunction2_fail2() throws Exception { TestObjectFail spyObject = spy(new TestObjectFail()); String[] args = new String[]{"florent", "florent"}; String pseudo = CarpaccioHelper.callFunction(spyObject, "getFamily", args); assertNull(pseudo); verify(spyObject, never()).getPseudo(); verify(spyObject, never()).getName(any(View.class), anyString()); }