StatePath { public void mkdir(String key) throws IOException { key = key.replace(" ", ""); if (key.endsWith("/") && !key.equals("/")) { throw new InvalidParameterException("Trailing slash not allowed in zookeeper path"); } String[] split = key.split("/"); StringBuilder builder = new StringBuilder(); for (String s : split) { builder.append(s); if (!s.isEmpty() && !exists(builder.toString())) { zkState.set(builder.toString(), null); } builder.append("/"); } } StatePath(SerializableState zkState); void mkdir(String key); Boolean exists(String key); void rm(String key);  }
@Test public void testMkDirJustSlashShouldNotCrash() throws InterruptedException, ExecutionException, ClassNotFoundException, IOException { statePath.mkdir("/"); }
@Test(expected = Exception.class) public void testMkDirTrailingSlash() throws InterruptedException, ExecutionException, ClassNotFoundException, IOException { statePath.mkdir("/mesos/"); }
@Test public void testMkDirOk() throws InterruptedException, ExecutionException, ClassNotFoundException, IOException { statePath.mkdir("/mesos"); }