Browse Source

StatusCommandTest: Open Git in try-with-resource

Change-Id: Id13ad9fa3157d0479da12fb8184437be3ca8c948
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
stable-4.2
David Pursehouse 9 years ago
parent
commit
6aa619ec5c
  1. 190
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java

190
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java

@ -61,109 +61,111 @@ public class StatusCommandTest extends RepositoryTestCase {
@Test @Test
public void testEmptyStatus() throws NoWorkTreeException, public void testEmptyStatus() throws NoWorkTreeException,
GitAPIException { GitAPIException {
Git git = new Git(db); try (Git git = new Git(db)) {
Status stat = git.status().call();
Status stat = git.status().call(); assertEquals(0, stat.getAdded().size());
assertEquals(0, stat.getAdded().size()); assertEquals(0, stat.getChanged().size());
assertEquals(0, stat.getChanged().size()); assertEquals(0, stat.getMissing().size());
assertEquals(0, stat.getMissing().size()); assertEquals(0, stat.getModified().size());
assertEquals(0, stat.getModified().size()); assertEquals(0, stat.getRemoved().size());
assertEquals(0, stat.getRemoved().size()); assertEquals(0, stat.getUntracked().size());
assertEquals(0, stat.getUntracked().size()); }
} }
@Test @Test
public void testDifferentStates() throws IOException, public void testDifferentStates() throws IOException,
NoFilepatternException, GitAPIException { NoFilepatternException, GitAPIException {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "content of a"); writeTrashFile("a", "content of a");
writeTrashFile("b", "content of b"); writeTrashFile("b", "content of b");
writeTrashFile("c", "content of c"); writeTrashFile("c", "content of c");
git.add().addFilepattern("a").addFilepattern("b").call(); git.add().addFilepattern("a").addFilepattern("b").call();
Status stat = git.status().call(); Status stat = git.status().call();
assertEquals(Sets.of("a", "b"), stat.getAdded()); assertEquals(Sets.of("a", "b"), stat.getAdded());
assertEquals(0, stat.getChanged().size()); assertEquals(0, stat.getChanged().size());
assertEquals(0, stat.getMissing().size()); assertEquals(0, stat.getMissing().size());
assertEquals(0, stat.getModified().size()); assertEquals(0, stat.getModified().size());
assertEquals(0, stat.getRemoved().size()); assertEquals(0, stat.getRemoved().size());
assertEquals(Sets.of("c"), stat.getUntracked()); assertEquals(Sets.of("c"), stat.getUntracked());
git.commit().setMessage("initial").call(); git.commit().setMessage("initial").call();
writeTrashFile("a", "modified content of a"); writeTrashFile("a", "modified content of a");
writeTrashFile("b", "modified content of b"); writeTrashFile("b", "modified content of b");
writeTrashFile("d", "content of d"); writeTrashFile("d", "content of d");
git.add().addFilepattern("a").addFilepattern("d").call(); git.add().addFilepattern("a").addFilepattern("d").call();
writeTrashFile("a", "again modified content of a"); writeTrashFile("a", "again modified content of a");
stat = git.status().call(); stat = git.status().call();
assertEquals(Sets.of("d"), stat.getAdded()); assertEquals(Sets.of("d"), stat.getAdded());
assertEquals(Sets.of("a"), stat.getChanged()); assertEquals(Sets.of("a"), stat.getChanged());
assertEquals(0, stat.getMissing().size()); assertEquals(0, stat.getMissing().size());
assertEquals(Sets.of("b", "a"), stat.getModified()); assertEquals(Sets.of("b", "a"), stat.getModified());
assertEquals(0, stat.getRemoved().size()); assertEquals(0, stat.getRemoved().size());
assertEquals(Sets.of("c"), stat.getUntracked()); assertEquals(Sets.of("c"), stat.getUntracked());
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
git.commit().setMessage("second").call(); git.commit().setMessage("second").call();
stat = git.status().call(); stat = git.status().call();
assertEquals(0, stat.getAdded().size()); assertEquals(0, stat.getAdded().size());
assertEquals(0, stat.getChanged().size()); assertEquals(0, stat.getChanged().size());
assertEquals(0, stat.getMissing().size()); assertEquals(0, stat.getMissing().size());
assertEquals(0, stat.getModified().size()); assertEquals(0, stat.getModified().size());
assertEquals(0, stat.getRemoved().size()); assertEquals(0, stat.getRemoved().size());
assertEquals(0, stat.getUntracked().size()); assertEquals(0, stat.getUntracked().size());
deleteTrashFile("a"); deleteTrashFile("a");
assertFalse(new File(git.getRepository().getWorkTree(), "a").exists()); assertFalse(new File(git.getRepository().getWorkTree(), "a").exists());
git.add().addFilepattern("a").setUpdate(true).call(); git.add().addFilepattern("a").setUpdate(true).call();
writeTrashFile("a", "recreated content of a"); writeTrashFile("a", "recreated content of a");
stat = git.status().call(); stat = git.status().call();
assertEquals(0, stat.getAdded().size()); assertEquals(0, stat.getAdded().size());
assertEquals(0, stat.getChanged().size()); assertEquals(0, stat.getChanged().size());
assertEquals(0, stat.getMissing().size()); assertEquals(0, stat.getMissing().size());
assertEquals(0, stat.getModified().size()); assertEquals(0, stat.getModified().size());
assertEquals(Sets.of("a"), stat.getRemoved()); assertEquals(Sets.of("a"), stat.getRemoved());
assertEquals(Sets.of("a"), stat.getUntracked()); assertEquals(Sets.of("a"), stat.getUntracked());
git.commit().setMessage("t").call(); git.commit().setMessage("t").call();
writeTrashFile("sub/a", "sub-file"); writeTrashFile("sub/a", "sub-file");
stat = git.status().call(); stat = git.status().call();
assertEquals(1, stat.getUntrackedFolders().size()); assertEquals(1, stat.getUntrackedFolders().size());
assertTrue(stat.getUntrackedFolders().contains("sub")); assertTrue(stat.getUntrackedFolders().contains("sub"));
}
} }
@Test @Test
public void testDifferentStatesWithPaths() throws IOException, public void testDifferentStatesWithPaths() throws IOException,
NoFilepatternException, GitAPIException { NoFilepatternException, GitAPIException {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "content of a"); writeTrashFile("a", "content of a");
writeTrashFile("D/b", "content of b"); writeTrashFile("D/b", "content of b");
writeTrashFile("D/c", "content of c"); writeTrashFile("D/c", "content of c");
writeTrashFile("D/D/d", "content of d"); writeTrashFile("D/D/d", "content of d");
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
writeTrashFile("a", "new content of a"); writeTrashFile("a", "new content of a");
writeTrashFile("D/b", "new content of b"); writeTrashFile("D/b", "new content of b");
writeTrashFile("D/D/d", "new content of d"); writeTrashFile("D/D/d", "new content of d");
// filter on an not existing path // filter on an not existing path
Status stat = git.status().addPath("x").call(); Status stat = git.status().addPath("x").call();
assertEquals(0, stat.getModified().size()); assertEquals(0, stat.getModified().size());
// filter on an existing file // filter on an existing file
stat = git.status().addPath("a").call(); stat = git.status().addPath("a").call();
assertEquals(Sets.of("a"), stat.getModified()); assertEquals(Sets.of("a"), stat.getModified());
// filter on an existing folder // filter on an existing folder
stat = git.status().addPath("D").call(); stat = git.status().addPath("D").call();
assertEquals(Sets.of("D/b", "D/D/d"), stat.getModified()); assertEquals(Sets.of("D/b", "D/D/d"), stat.getModified());
// filter on an existing folder and file // filter on an existing folder and file
stat = git.status().addPath("D/D").addPath("a").call(); stat = git.status().addPath("D/D").addPath("a").call();
assertEquals(Sets.of("a", "D/D/d"), stat.getModified()); assertEquals(Sets.of("a", "D/D/d"), stat.getModified());
// do not filter at all // do not filter at all
stat = git.status().call(); stat = git.status().call();
assertEquals(Sets.of("a", "D/b", "D/D/d"), stat.getModified()); assertEquals(Sets.of("a", "D/b", "D/D/d"), stat.getModified());
}
} }
} }

Loading…
Cancel
Save