private void validateModule(@NotNull Module module) throws Exception {
    final String importedModulePath = getProject().getBaseDir().getPath();

    final Element actualImlElement = new Element("root");
    ((ModuleRootManagerImpl) ModuleRootManager.getInstance(module))
        .getState()
        .writeExternal(actualImlElement);
    PathMacros.getInstance().setMacro(MODULE_DIR, importedModulePath);
    PathMacroManager.getInstance(module).collapsePaths(actualImlElement);
    PathMacroManager.getInstance(getProject()).collapsePaths(actualImlElement);
    PathMacros.getInstance().removeMacro(MODULE_DIR);

    final String projectPath = getProject().getBaseDir().getPath();
    final File expectedImlFile = new File(projectPath + "/expected/" + module.getName() + ".iml");
    final Document expectedIml = JDOMUtil.loadDocument(expectedImlFile);
    final Element expectedImlElement = expectedIml.getRootElement();

    final String errorMsg =
        "Configuration of module "
            + module.getName()
            + " does not meet expectations.\nExpected:\n"
            + new String(JDOMUtil.printDocument(expectedIml, "\n"))
            + "\nBut got:\n"
            + new String(JDOMUtil.printDocument(new Document(actualImlElement), "\n"));
    Assert.assertTrue(errorMsg, JDOMUtil.areElementsEqual(expectedImlElement, actualImlElement));
    validateFacet(module);
  }
 public static void assertElementsEqual(final Element expected, final Element actual)
     throws IOException {
   if (!JDOMUtil.areElementsEqual(expected, actual)) {
     junit.framework.Assert.assertEquals(printElement(expected), printElement(actual));
   }
 }