JvmOptionsUtils { public static String extractDirectory(String jvmOptions) { if (jvmOptions == null || jvmOptions.trim().length() == 0) { return null; } if (jvmOptions.indexOf(CLOUDUNIT_SHARED_DIR) == -1) { return null; } String subStringFromStart = jvmOptions.substring(jvmOptions.indexOf(CLOUDUNIT_SHARED_DIR)+2); if (subStringFromStart.indexOf("-D") != -1) { subStringFromStart = subStringFromStart.substring(0, subStringFromStart.indexOf("-D")); } String finalValue = subStringFromStart.substring(subStringFromStart.indexOf("=")+1); if (finalValue != null) { finalValue = finalValue.trim(); } if (finalValue != null && finalValue.length() == 0) { finalValue = null; } return finalValue; }  static String extractDirectory(String jvmOptions); final static String CLOUDUNIT_SHARED_DIR; }
@Test public void extractDir() { String dir = JvmOptionsUtils.extractDirectory("-Dcloudunit.shared=tartapion"); Assert.assertEquals("tartapion", dir); }
@Test public void extractDirWithOtherParams() { String dir = JvmOptionsUtils.extractDirectory("-Dkey=value -Dcloudunit.shared=tartapion"); Assert.assertEquals("tartapion", dir); dir = JvmOptionsUtils.extractDirectory("-Dkey=value -Dcloudunit.shared=tartapion -Dkey2=value2"); Assert.assertEquals("tartapion", dir); }
@Test public void missingInput() { String dir = JvmOptionsUtils.extractDirectory("-Dkey=value"); Assert.assertNull(dir); dir = JvmOptionsUtils.extractDirectory("-Dcloudunit.shared="); Assert.assertNull(dir); dir = JvmOptionsUtils.extractDirectory("-Dcloudunit.shared= -Dkey=value"); Assert.assertNull(dir); dir = JvmOptionsUtils.extractDirectory(""); Assert.assertNull(dir); dir = JvmOptionsUtils.extractDirectory(" "); Assert.assertNull(dir); dir = JvmOptionsUtils.extractDirectory(""); Assert.assertNull(dir); dir = JvmOptionsUtils.extractDirectory("-Dkey=value -Dkey2=value2"); Assert.assertNull(dir); }