### Question:
HatchejImlAction { public boolean addLibraryFiles(final Project project, final HatchejModel hatchejModel) { boolean added = false; File ideaLibrariesDir = new File(project.getRootDir(), ".idea/libraries"); if (!ideaLibrariesDir.isDirectory() || !ideaLibrariesDir.exists()) { return added; } for (String dependency : hatchejModel.getLibraryDependencies()) { added |= createLibraryFileIfNotExists(ideaLibrariesDir, dependency); } return added; } HatchejImlAction(); boolean addLibraryFiles(final Project project, final HatchejModel hatchejModel); @SuppressWarnings("unchecked") void modifyImlFile(final Project project, final HatchejModel hatchejModel);  }### Answer:
@Test public void testLibrariesDirDoesntExistNoUpdates() throws Exception { Project project = ProjectBuilder.builder().withGradleUserHomeDir(temporaryFolder.newFolder("gradleUserHome")) .withProjectDir(temporaryFolder.getRoot()).build(); TestUtils.setupGenericExtensions(project).getPluginManager().apply(TestableBazelLeafPlugin.class); HatchejModel hatchejModel = new HatchejModel(); hatchejModel.getLibraryDependencies().add("library1"); HatchejImlAction hatchejImlAction = new HatchejImlAction(); File librariesFile = new File(project.getRootDir().getCanonicalFile(), ".idea/libraries"); assertThat(librariesFile.exists(), Is.is(false)); boolean added = hatchejImlAction.addLibraryFiles(project, hatchejModel); assertThat(added, Is.is(false)); assertThat(librariesFile.exists(), Is.is(false)); assertThat(temporaryFolder.getRoot().list(), IsArrayWithSize.arrayWithSize(1)); assertThat(temporaryFolder.getRoot().list(), IsArrayContaining.hasItemInArray("gradleUserHome")); }
@Test public void testAddLibraryFilesLibraryDirExists() throws Exception { Project project = ProjectBuilder.builder().withGradleUserHomeDir(temporaryFolder.newFolder("gradleUserHome")) .withProjectDir(temporaryFolder.getRoot()).build(); File ideaFolder = temporaryFolder.newFolder(".idea"); File librariesFolder = new File(ideaFolder, "libraries"); Files.createDirectories(librariesFolder.toPath()); TestUtils.setupGenericExtensions(project).getPluginManager().apply(TestableBazelLeafPlugin.class); HatchejModel hatchejModel = new HatchejModel(); hatchejModel.getLibraryDependencies().add("librarydep1"); hatchejModel.getLibraryDependencies().add("librarydep2"); HatchejImlAction hatchejImlAction = new HatchejImlAction(); boolean added = hatchejImlAction.addLibraryFiles(project, hatchejModel); assertThat(added, Is.is(true)); assertThat(temporaryFolder.getRoot().list(), IsArrayWithSize.arrayWithSize(2)); assertThat(librariesFolder.list(), IsArrayContainingInAnyOrder .arrayContainingInAnyOrder("librarydep1!.xml", "librarydep2!.xml")); String libraryDep1Xml = FileUtils.readFileToString(new File(librariesFolder, "librarydep1!.xml"), "UTF-8"); assertThat(StringUtils.deleteWhitespace(libraryDep1Xml), IsEqual.equalTo(StringUtils.deleteWhitespace(getLibraryXmlContent("librarydep1")))); String libraryDep2Xml = FileUtils.readFileToString(new File(librariesFolder, "librarydep2!.xml"), "UTF-8"); assertThat(StringUtils.deleteWhitespace(libraryDep2Xml), IsEqual.equalTo(StringUtils.deleteWhitespace(getLibraryXmlContent("librarydep2")))); }