@Test
public void testInvalidPath() throws Exception {

    KeySpace root = new KeySpace(
            new KeySpaceDirectory("root",  KeyType.STRING, "production")
                    .addSubdirectory(new KeySpaceDirectory("a", KeyType.STRING)
                            .addSubdirectory(new KeySpaceDirectory("b", KeyType.STRING))));
    final FDBDatabase database = FDBDatabaseFactory.instance().getDatabase();
    try (FDBRecordContext context = database.openContext()) {
        // Building a tuple in the correct order works
        Tuple tuple = root.path("root")
                .add("a", "foo")
                .add("b", "bar").toTuple(context);
        assertEquals(Tuple.from("production", "foo", "bar"), tuple);
        // Walking in the wrong order fails
        assertThrows(NoSuchDirectoryException.class,
                () -> root.path("foo").add("a", "bar").toTuple(context));
    }
}