CarpaccioHelper { public static Method callMethod(Object object, Method method, String name, View view, Object[] args) { if (method != null && object != null) { CarpaccioLogger.d(TAG, view.getClass().getName() + " call method " + name + " on " + object); try { method.invoke(object, getArgumentsWithView(view, method.getParameterTypes(), args)); return method; } catch (Exception e) { CarpaccioLogger.e(TAG, object.getClass() + " cannot invoke method " + name); } } 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 testCallMethod() throws Exception { TestObject testObject = spy(new TestObject()); View view = mock(View.class); String arg1 = "florent"; Method method = testObject.getClass().getMethod("getName", new Class[]{View.class, String.class}); assertNotNull(CarpaccioHelper.callMethod(testObject, method, "getName", view, new Object[]{arg1})); verify(testObject,atLeastOnce()).getName(eq(view),eq(arg1)); }
@Test public void testCallMethod_fail() throws Exception { TestObject testObject = spy(new TestObject()); View view = mock(View.class); String arg1 = "florent"; Method method = null; assertNull(CarpaccioHelper.callMethod(testObject, method, "getName", view, new Object[]{arg1})); verify(testObject,never()).getName(eq(view), eq(arg1)); }