XCodeProjectLayoutValidator { static void verifyXcodeFolder(final File xcodeFolder, final String projectName) throws XCodeVerificationException { if (!xcodeFolder.exists()) { throw new XCodeRootFolderDoesNotExistException("The folder \"" + xcodeFolder + "\" that is the root folder of the xcode project \"" + projectName + "\" does not exist."); } final String xcodeProjectFolderName = projectName + XCodeConstants.XCODE_PROJECT_EXTENTION; final Collection<File> xcodeProjectFolders = Arrays.asList(xcodeFolder.listFiles(new FileFilter() { @Override public boolean accept(File f) { return f.isDirectory() && f.getName().equals(xcodeProjectFolderName); } })); if (xcodeProjectFolders.size() == 0) { throw new XCodeProjectNotFoundException( "The folder \"" + xcodeFolder + "\" must contain folder named \"" + xcodeProjectFolderName + "\". This folder is expected to hold the xcode project configuration. The xcode project must have the same name as the maven artifactId"); } for (final File xcodeProjectFolder : xcodeProjectFolders) if (xcodeProjectFolder.listFiles(new FileFilter() { @Override public boolean accept(File f) { return f.getName().equals(XCodeConstants.XCODE_CONFIGURATION_FILE_NAME); } }).length != 1) throw new XCodeProjectFileDoesNotExistException("Folder \"" + xcodeProjectFolders + "\" is expected to contain the file \"" + XCodeConstants.XCODE_CONFIGURATION_FILE_NAME + "\" but that file does not exist."); }    }
@Test public void verifyXCodeFolderStraightForwardTest() throws XCodeException { XCodeProjectLayoutValidator.verifyXcodeFolder(new File(new File(projectDirectory, "MyLibrary"), "src/xcode"), "MyLibrary"); }
@Test(expected = XCodeRootFolderDoesNotExistException.class) public void xCodeRootFolderDoesNotExist() throws XCodeException, IOException { final File projectDirectoryMyLibrary = new File(new File(projectDirectory, "MyLibrary"), "src/xcode"); FileUtils.deleteDirectory(projectDirectoryMyLibrary); XCodeProjectLayoutValidator.verifyXcodeFolder(projectDirectoryMyLibrary, "MyLibrary"); }
@Test(expected = XCodeProjectNotFoundException.class) public void xCodeFolderDoesNotExist() throws XCodeException, IOException { final File projectDirectoryMyLibrary = new File(new File(projectDirectory, "MyLibrary"), "src/xcode"); FileUtils.deleteDirectory(new File(projectDirectoryMyLibrary, "MyLibrary.xcodeproj")); XCodeProjectLayoutValidator.verifyXcodeFolder(projectDirectoryMyLibrary, "MyLibrary"); }
@Test(expected = XCodeProjectFileDoesNotExistException.class) public void xCodeProjectFileDoesNotExist() throws XCodeException { final File projectDirectoryMyLibrary = new File(new File(projectDirectory, "MyLibrary"), "src/xcode"); final File pbxprojFile = new File(new File(projectDirectoryMyLibrary, "MyLibrary.xcodeproj"), "project.pbxproj"); if (!pbxprojFile.delete()) throw new IllegalStateException("Could not delete " + pbxprojFile); XCodeProjectLayoutValidator.verifyXcodeFolder(projectDirectoryMyLibrary, "MyLibrary"); }