GitStatus { public GitStatusResponse status(File repositoryPath, GitStatusOptions options, List<File> paths) throws JavaGitException, IOException { CheckUtilities.checkFileValidity(repositoryPath); IClient client = ClientManager.getInstance().getPreferredClient(); IGitStatus gitStatus = client.getGitStatusInstance(); return gitStatus.status(repositoryPath, options, paths); }  GitStatusResponse status(File repositoryPath, GitStatusOptions options, List<File> paths); GitStatusResponse status(File repositoryPath, List<File> paths); GitStatusResponse status(File repositoryPath, GitStatusOptions options); GitStatusResponse status(File repositoryPath, GitStatusOptions options, File file); GitStatusResponse status(File repositoryPath); GitStatusResponse statusAll(File repositoryPath); GitStatusResponse getSingleFileStatus(File repositoryPath, File path); GitFileSystemObject.Status getFileStatus(File repositoryPath, File path);  }
@Test public void testBranch() throws JavaGitException, IOException { List<File> paths = null; GitStatusResponse response = gitStatus.status(repositoryDirectory, options, paths); String branch = response.getBranch().getName(); assertEquals("Branch does not match", "master", branch); }
@Test public void testUntrackedNewFiles() throws IOException, JavaGitException { List<File> paths = null; GitStatusResponse response = gitStatus.status(repositoryDirectory, options, paths); int noOfUntrackedFiles = response.getUntrackedFilesSize(); assertEquals("Error.No of untracked files does not Match.", 3, noOfUntrackedFiles); assertEquals("Error. Filename does not match.", "foobar01", response.getFileFromUntrackedFiles(0).getName()); assertEquals("Error. Filename does not match.", "foobar02", response.getFileFromUntrackedFiles(1).getName()); assertEquals("Error. Filename does not match.", "testDirectory", response.getFileFromUntrackedFiles(2).getName()); }
@Test public void testReadyToCommitNewFiles() throws IOException, JavaGitException { List<File> filesToAdd = new ArrayList<File>(); filesToAdd.add(file1); filesToAdd.add(file2); filesToAdd.add(new File("testDirectory")); filesToAdd.add(new File( "testDirectory" + File.separator + file3.getPath())); GitAddOptions addOptions = new GitAddOptions(); gitAdd.add(repositoryDirectory, addOptions, filesToAdd); List<File> statusPath = null; GitStatusResponse status = gitStatus.status(repositoryDirectory, options, statusPath); int noOfNewFilesToCommit = status.getNewFilesToCommitSize(); assertEquals("Error. No of New Files to commit does not match", 3, noOfNewFilesToCommit); assertEquals("Error. Filename does not match", "foobar01", status .getFileFromNewFilesToCommit(0).getName()); assertEquals("Error. Filename does not match", "foobar02", status .getFileFromNewFilesToCommit(1).getName()); assertEquals("Error. Filename does not match", repositoryDirectory.getPath() + File.separator + "testDirectory" + File.separator + "foobar03", status.getFileFromNewFilesToCommit(2).toString()); }
@Test public void testModifiedNotUpdatedFiles() throws IOException, JavaGitException { List<File> filesToAdd = new ArrayList<File>(); filesToAdd.add(file1); filesToAdd.add(file2); filesToAdd.add(new File("testDirectory")); filesToAdd.add(new File( "testDirectory" + File.separator + file3.getPath())); GitAddOptions addOptions = new GitAddOptions(); gitAdd.add(repositoryDirectory, addOptions, filesToAdd); gitCommit.commit(repositoryDirectory, "Test commit of two files"); FileUtilities.modifyFileContents(new File(repositoryDirectory.getPath() + File.separator + file1.getPath()), "Test append text\n"); FileUtilities.modifyFileContents(new File(testDir.getPath() + File.separator + file3.getPath()), "Another sample text added to foobar03\n"); List<File> statusPath = null; GitStatusResponse status = gitStatus.status(repositoryDirectory, options, statusPath); int modifiedNotUpdatedFiles = status.getModifiedFilesNotUpdatedSize(); assertEquals("No of modified but not updated files not equal", 2, modifiedNotUpdatedFiles); if (new File(repositoryDirectory.getPath() + File.separator + file2.getPath()).delete()) { status = gitStatus.status(repositoryDirectory, options, statusPath); modifiedNotUpdatedFiles = status.getModifiedFilesNotUpdatedSize(); int deletedFileNotUpdated = status.getDeletedFilesNotUpdatedSize(); assertEquals("No of deleted files not equal", 1, deletedFileNotUpdated); assertEquals("No of modified but not updated files not equal", 2, modifiedNotUpdatedFiles); } else { fail("Failed to delete file \"foobar02\""); } }
@Test public void testIOExceptionThrownForInvalidRepositoryDirectory() throws JavaGitException { File tempRepoDirectory = new File("/_______non_existing_dir_______"); try { gitStatus.status(tempRepoDirectory); fail("IOException not thrown for non-existing repoDirectory"); } catch (IOException expected) { FileUtilities.removeDirectoryRecursivelyAndForcefully(repositoryDirectory); } }
@Test public void testIOExceptionThrownForInvalidRepositoryDirectory2() throws JavaGitException { File tempRepoDirectory = new File("/_______non_existing_dir________"); try { FileUtilities.createFile(tempRepoDirectory, "foobar01", "Sameple Contents"); List<File> paths = null; gitStatus.status(repositoryDirectory, options, paths); fail("Failed to throw JavaGitException"); } catch (IOException expected) { FileUtilities.removeDirectoryRecursivelyAndForcefully(repositoryDirectory); } }