### Question:
StringUtil { public static final String[] splitMachineId(String machineId) { if ( machineId == null ) return null; int idx = machineId.indexOf(':'); if ( idx > 0 && idx < machineId.length()-1 ) { String[] results = new String[2]; results[0] = machineId.substring(0, idx); results[1] = machineId.substring(idx+1); return results; } else { return null; } }  static final String substring(String line, String start, String end); static final String substringR(String line, String start, String end); static final String concat(Object ... value ); static final int toInt(String str, int defaultValue); static final float toFloat(String str, float defaultValue); static final boolean checkNotEmpty(String str); static final void padStringRight(StringBuilder buf, String str, int length); static final String bytesToHexString(byte[] bytes); static final byte[] hexStringToBytes(String hexString); static final String[] splitMachineId(String machineId); static final Locale parseLocale(String languageTag, Locale defaultLocale); static final boolean checkValidEmail(String emailAddress); static String encryptSHA1(String data); static String encryptMD5(String data);  }### Answer:
@Test public void testSplitMachineId() { String machineid = "192.168.0.6:2181"; String[] results = StringUtil.splitMachineId(machineid); assertEquals("192.168.0.6", results[0]); assertEquals("2181", results[1]); }
@Test public void testSplitMachineId2() { String machineid = "192.168.0.6"; String[] results = StringUtil.splitMachineId(machineid); assertNull(results); }
@Test public void testSplitMachineId3() { String machineid = ":2181"; String[] results = StringUtil.splitMachineId(machineid); assertNull(results); }
@Test public void testSplitMachineId4() { String machineid = "192.168.0.6:"; String[] results = StringUtil.splitMachineId(machineid); assertNull(results); }
@Test public void testSplitMachineId5() { String machineid = null; String[] results = StringUtil.splitMachineId(machineid); assertNull(results); }
@Test public void testSplitMachineIdPerformance() throws Exception { final String machineid = "192.168.0.6:2181"; int max = 10000; TestUtil.doPerform(new Runnable() { public void run() { String[] results = machineid.split(":"); } }, "Java SplitString", max); TestUtil.doPerform(new Runnable() { public void run() { String[] results = StringUtil.splitMachineId(machineid); } }, "Our splitMachineId", max); }