### Question:
Utils { static String validatePackageName(final String pkg) { if (StringUtils.isBlank(pkg)) { return ""; } String result = pkg.trim(); final String unexpected = "Unexpected character %s at pos %s of package name \"%s\""; boolean next = true; for (int pos = 0; pos < result.length(); pos++) { final char chr = result.charAt(pos); if (next) { next = false; Validate.isTrue(Character.isJavaIdentifierStart(chr), unexpected, chr, pos, result); continue; } if (chr == '/' || chr == '.') { next = true; continue; } Validate.isTrue(Character.isJavaIdentifierPart(chr), unexpected, chr, pos, result); } result = result.replace('.', '/'); final int last = result.length() - 1; if (result.charAt(last) == '/') { result = result.substring(0, last); } return result; } private  Utils();   }### Answer:
@Test public void testValidatePackageName() { assertEquals("", Utils.validatePackageName("")); assertEquals("", Utils.validatePackageName(" ")); assertEquals("foo", Utils.validatePackageName("foo")); assertEquals("foo/bar", Utils.validatePackageName("foo.bar")); assertEquals("foo/bar", Utils.validatePackageName("foo/bar")); assertEquals("foo/bar/baz", Utils.validatePackageName("foo.bar.baz")); assertEquals("foo/bar/baz", Utils.validatePackageName("foo.bar/baz")); assertEquals("foo/bar/baz", Utils.validatePackageName("foo/bar.baz")); assertEquals("foo/bar/baz", Utils.validatePackageName("foo/bar/baz")); assertEquals("$foo", Utils.validatePackageName("$foo")); assertEquals("_foo", Utils.validatePackageName("_foo")); assertEquals("foo2", Utils.validatePackageName("foo2")); }
@Test(expected = IllegalArgumentException.class) public void testValidatePackageNameStartsWithDigit() { Utils.validatePackageName("2foo"); }
@Test(expected = IllegalArgumentException.class) public void testValidatePackageNameEmbeddedWhitespace() { Utils.validatePackageName("foo bar"); }