public class WorkspaceUtilsTests extends TestCase {
public void testGetWorkspaceHierarchy() {
// Create a list of workspaces.
JsonArray<WorkspaceInfo> workspaces = JsonCollections.createArray();
WorkspaceInfo a = makeWorkspace("a", null);
WorkspaceInfo b = makeWorkspace("b", null);
WorkspaceInfo aa = makeWorkspace("aa", a);
WorkspaceInfo ab = makeWorkspace("ab", a);
WorkspaceInfo ac = makeWorkspace("ac", a);
WorkspaceInfo aaa = makeWorkspace("aaa", aa);
WorkspaceInfo aab = makeWorkspace("aab", aa);
WorkspaceInfo aac = makeWorkspace("aac", aa);
workspaces.add(aa);
workspaces.add(ab);
workspaces.add(aab);
workspaces.add(ac);
workspaces.add(aac);
workspaces.add(b);
workspaces.add(aaa);
workspaces.add(a);
// Add an element with a parent that is not mapped.
WorkspaceInfo zaa = makeWorkspace("zaa", makeWorkspace("unmapped", null));
workspaces.add(zaa);
// Create an unsorted hierarchy.
JsonArray<WorkspaceNode> roots =
WorkspaceUtils.getWorkspaceHierarchy(workspaces, new Comparator<WorkspaceInfo>() {