DataUtil { public static String getString(Object value, String defValue) { if (value == null) { return defValue; } String str; if (value instanceof String) { str = (String)value; } else if (value instanceof Number || value instanceof Boolean || value instanceof Character) { str = value.toString(); } else { str = defValue; } return str; }  static boolean getBoolean(Object value, boolean defValue); static Boolean doGetBoolean(Object value, Boolean defValue); static boolean toBoolean(String value, boolean defValue); static Boolean convertToBoolean(String value, Boolean defValue); static boolean toBoolean(String value); static int getInt(Object value, int defValue); static long getLong(Object value, long defValue); static double getDouble(Object value, double defValue); static String getString(Object value, String defValue); static String[] getStringArray(Object object, String[] defValue); static int[] getIntArray(Object object, int[] defValue); static List<String> getStringList(Object object);  }
@Test public void getString() throws Exception { assertEquals(DataUtil.getString(null, ""), ""); assertEquals(DataUtil.getString(Boolean.TRUE, ""), "true"); assertEquals(DataUtil.getString(Boolean.FALSE, ""), "false"); assertEquals(DataUtil.getString("True", ""), "True"); assertEquals(DataUtil.getString("99", ""), "99"); assertEquals(DataUtil.getString(" 88 ", ""), " 88 "); assertEquals(DataUtil.getString("DDDDD", " "), "DDDDD"); assertEquals(DataUtil.getString(new Object(), ""), ""); assertEquals(DataUtil.getString(888l, ""), "888"); assertEquals(DataUtil.getString('a', ""), "a"); }