CarpaccioHelper { public static Object stringToNumber(String s, Class destinationClass) { if (Integer.class.equals(destinationClass)) return stringToInt(s); else if (destinationClass.getName().equals("int")) return stringToInt(s); else if (Float.class.equals(destinationClass)) return stringToFloat(s); else if (destinationClass.getName().equals("float")) return stringToFloat(s); else if (Long.class.equals(destinationClass)) return stringToLong(s); else if (destinationClass.getName().equals("long")) return stringToLong(s); else if (Double.class.equals(destinationClass)) return stringToDouble(s); else if (destinationClass.getName().equals("double")) return stringToDouble(s); else 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 testStringToNumber() throws Exception { assertEquals(3,CarpaccioHelper.stringToNumber("3",int.class)); assertEquals(3l,CarpaccioHelper.stringToNumber("3",long.class)); assertEquals(3.f,CarpaccioHelper.stringToNumber("3",float.class)); assertEquals(3.d,CarpaccioHelper.stringToNumber("3",double.class)); assertEquals(Integer.valueOf(3),CarpaccioHelper.stringToNumber("3",Integer.class)); assertEquals(Long.valueOf(3),CarpaccioHelper.stringToNumber("3",Long.class)); assertEquals(Float.valueOf(3),CarpaccioHelper.stringToNumber("3",Float.class)); assertEquals(Double.valueOf(3),CarpaccioHelper.stringToNumber("3",Double.class)); assertEquals(null,CarpaccioHelper.stringToNumber(null,Integer.class)); assertNull(CarpaccioHelper.stringToNumber("3",String.class)); }