### Question:
ObjectUtils { public static int getInteger(Object v, int defValue) { if (ObjectUtils.isEmpty(v)) return defValue; try { return toInteger(v); } catch (Exception e) { log.warn(String.format("Cannot convert value [%s] to int!", v)); return defValue; } } private  ObjectUtils(); static boolean isEmpty(Object o); static int lengthOf(Object o); @SuppressWarnings("unchecked") static boolean compareEqual(Object o1, Object o2); static boolean compareEqual(Object[] array1, Object[] array2); static T coalesce(T preferred, T alternative); static int toInteger(Object v); static int getInteger(Object v, int defValue); static int getInteger(Object v); static long toLong(Object v); static long getLong(Object v, long defValue); static long getLong(Object v); static double toDouble(Object v); static double getDouble(Object v, double defValue); static double getDouble(Object v); static BigDecimal toDecimal(Object v); static BigDecimal getDecimal(Object v, BigDecimal defValue); static BigDecimal getDecimal(Object v); static boolean getBoolean(Object v); @SuppressWarnings("unchecked") static T getEnum(Class<T> enumType, Object value); static Date getDate(Object v, Locale locale); static Date getDate(Object v); static String formatDate(Date date, boolean withTime); @SuppressWarnings("unchecked") static T convert(Class<T> c, Object v); static boolean isAssignmentCompatible(Class<?> target, Class<?> source); static List<T> convert(Class<T> t, Collection<? extends T> source); static String[] toStringArray(Object[] objArray, String defValue); static boolean contains(T[] array, T item); static synchronized Object getFieldValue(Class<?> clazz, Object object, String property, boolean includePrivateFields); static Object getFieldValue(Object object, String property); static Object getPrivateFieldValue(Object object, String property); static synchronized Object invokeSimpleMethod(Class<?> clazz, Object object, String methodName, boolean includePrivateMethods); static Object invokeSimpleMethod(Object object, String methodName); static Object invokeSimplePrivateMethod(Object object, String methodName); static final NoValue NO_VALUE; }### Answer:
@Test public void testGetIntegerObjectInt() { assertEquals(Integer.MAX_VALUE, ObjectUtils.getInteger(null, Integer.MAX_VALUE)); assertEquals(Integer.MIN_VALUE, ObjectUtils.getInteger("", Integer.MIN_VALUE)); assertEquals(123, ObjectUtils.getInteger("JUnit", 123)); assertEquals(456, ObjectUtils.getInteger(456, 123)); assertEquals(456, ObjectUtils.getInteger("456", 123)); assertEquals(456, ObjectUtils.getInteger(Long.valueOf(456), 123)); assertEquals(456, ObjectUtils.getInteger(Integer.valueOf(456), 123)); assertEquals(456, ObjectUtils.getInteger(Float.valueOf(456), 123)); assertEquals(456, ObjectUtils.getInteger(Double.valueOf(456), 123)); assertEquals(456, ObjectUtils.getInteger(Double.valueOf(456.456), 123)); }
@Test public void testGetIntegerObject() { assertEquals(0, ObjectUtils.getInteger(null)); assertEquals(0, ObjectUtils.getInteger("")); assertEquals(0, ObjectUtils.getInteger("JUnit")); assertEquals(456, ObjectUtils.getInteger("456")); assertEquals(456, ObjectUtils.getInteger(Long.valueOf(456))); assertEquals(456, ObjectUtils.getInteger(Integer.valueOf(456))); assertEquals(456, ObjectUtils.getInteger(Float.valueOf(456))); assertEquals(456, ObjectUtils.getInteger(Double.valueOf(456))); assertEquals(456, ObjectUtils.getInteger(Double.valueOf(456.456))); }