### Question:
HatchejImlAction { static boolean createLibraryFileIfNotExists(File ideaLibrariesDir, String dependency) { final boolean created; final String path = getJarUrl(dependency); final String name = getFilenameWithoutExtension(path); final String normalizedName = normalizePath(name); final File ideaLibraryFile = new File(ideaLibrariesDir, normalizedName + ".xml"); if (!ideaLibraryFile.exists()) { final Node componentRootNode = createNode("component", "name", "libraryTable"); final Node libraryNode = createLibraryNode(name); componentRootNode.append(libraryNode); Node classes = libraryNode.appendNode("CLASSES"); classes.append(createRootNode(path)); libraryNode.appendNode("JAVADOC"); libraryNode.appendNode("SOURCES"); try (final FileWriter fileWriter = new FileWriter(ideaLibraryFile)) { new XmlNodePrinter(new PrintWriter(fileWriter)).print(componentRootNode); created = true; } catch (IOException e) { throw new RuntimeException(e); } } else { LOGGER.debug("IDEA library file {} already exists", ideaLibraryFile.getAbsolutePath()); created = false; } return created; } HatchejImlAction(); boolean addLibraryFiles(final Project project, final HatchejModel hatchejModel); @SuppressWarnings("unchecked") void modifyImlFile(final Project project, final HatchejModel hatchejModel);  }### Answer:
@Test public void testCreateLibraryFileIfNotExists() throws IOException { File ideaLibrariesDir = new File(temporaryFolder.getRoot(), ".idea/libraries"); ideaLibrariesDir.mkdirs(); boolean created = HatchejImlAction.createLibraryFileIfNotExists( ideaLibrariesDir, "dep1"); File dep1LibraryXml = new File(ideaLibrariesDir, "dep1!.xml"); assertThat(dep1LibraryXml.exists(), IsEqual.equalTo(true)); String s = FileUtils.readFileToString(dep1LibraryXml, "UTF-8"); assertThat(s, IsEqualIgnoringWhiteSpace.equalToIgnoringWhiteSpace("<component name=\"libraryTable\">\n" + " <library name=\"dep1!\">\n" + " <CLASSES>\n" + " <root url=\"jar: + " </CLASSES>\n" + " <JAVADOC/>\n" + " <SOURCES/>\n" + " </library>\n" + "</component>\n")); assertThat(created, Matchers.is(true)); }
@Test public void testCreateLibraryFileExists() throws IOException { File ideaLibrariesDir = new File(temporaryFolder.getRoot(), ".idea/libraries"); ideaLibrariesDir.mkdirs(); File dep1LibraryXml = new File(ideaLibrariesDir, "dep1!.xml"); FileUtils.touch(dep1LibraryXml); dep1LibraryXml.setLastModified(0L); boolean created = HatchejImlAction.createLibraryFileIfNotExists( ideaLibrariesDir, "dep1"); assertThat(dep1LibraryXml.exists(), IsEqual.equalTo(true)); assertThat(dep1LibraryXml.length(), IsEqual.equalTo(0L)); assertThat(dep1LibraryXml.lastModified(), IsEqual.equalTo(0L)); assertThat(created, Matchers.is(false)); }