@Test
public void testSortByDependencies() throws CycleDetectedException {

    Map<String, PackagedModule> modules = new LinkedHashMap<>();
    Attributes attrs = new Attributes();
    attrs.put(Constants.ATTR_NAME_JAHIA_DEPENDS, "default,moduleb");
    PackagedModule pkg = new ModulesPackage.PackagedModule("modulec", attrs, null);
    modules.put(pkg.getName(), pkg);
    attrs = new Attributes();
    attrs.put(Constants.ATTR_NAME_JAHIA_DEPENDS, "default,assets");
    attrs.putValue(org.osgi.framework.Constants.IMPORT_PACKAGE,
            "org.jahia.modules.external;resolution:=optional;version=\"[3.0,4)\"");
    pkg = new ModulesPackage.PackagedModule("moduleb", attrs, null);
    modules.put(pkg.getName(), pkg);
    attrs = new Attributes();
    attrs.put(Constants.ATTR_NAME_JAHIA_DEPENDS, "default,assets");
    attrs.putValue(org.osgi.framework.Constants.EXPORT_PACKAGE,
            "org.jahia.modules.external;uses:=\"javax.jcr,javax.jcr.lock,javax.jcr.nodetype,javax.jcr.observation,javax.jcr.query,javax.jcr.query.qom,"
                    + "javax.jcr.retention,javax.jcr.security,javax.jcr.version,org.apache.jackrabbit.spi.commons.conversion,org.jahia.exceptions,"
                    + "org.jahia.modules.external.acl,org.jahia.services.content,org.jahia.services.content.nodetypes,org.jahia.utils.security,"
                    + "org.springframework.beans.factory,org.xml.sax\";version=\"3.1.1\",org.jahia.modules.external.query;uses:=\"javax.jcr"
                    + ",javax.jcr.query,javax.jcr.query.qom,org.jahia.modules.external\";version=\"3.1.1\"");
    pkg = new ModulesPackage.PackagedModule("modulea", attrs, null);
    modules.put(pkg.getName(), pkg);
    ModulesPackage.sortByDependencies(modules);
    String[] keys = modules.keySet().toArray(new String[] {});
    assertEquals("modulea", keys[0]);
    assertEquals("moduleb", keys[1]);
    assertEquals("modulec", keys[2]);
}