### Question:
SafeCast { public static String toString(Object o, String def) { if (!(o instanceof String)) { return def; } return (String) o; }  static long toLong(Object o, long def); static int toInt(Object o, int def); static byte toByte(Object o, byte def); static float toFloat(Object o, float def); static byte[] toByteArray(Object o, byte[] def); static short[] toShortArray(Object o, short[] def); static int[] toIntArray(Object o, int[] def); static String toString(Object o, String def); static T toGeneric(Object o, U def, Class<T> clazz);  }### Answer:
@Test public void testString() { String string = "Valid string"; String backup = "Backup"; assertTrue("Unable to process valid cast", (SafeCast.toString(string, backup) == null ? string == null : SafeCast.toString(string, backup).equals(string))); assertTrue("Default did not work (wrong type)", (SafeCast.toString(new Integer(22), backup) == null ? backup == null : SafeCast.toString(new Integer(22), backup).equals(backup))); assertTrue("Default did not work (null)", (SafeCast.toString(null, backup) == null ? backup == null : SafeCast.toString(null, backup).equals(backup))); }