summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@sonymobile.com>2016-02-05 17:03:25 +0900
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2016-02-05 17:03:44 +0900
commit6aa619ec5cf7dc2d4149fa8087d985c801223639 (patch)
tree735169985172db59ab81298cc0416339b16b041d
parent96ff3110498329bd9a0e1850da5d6f9bf6507f51 (diff)
downloadjgit-6aa619ec5cf7dc2d4149fa8087d985c801223639.tar.gz
jgit-6aa619ec5cf7dc2d4149fa8087d985c801223639.zip
StatusCommandTest: Open Git in try-with-resource
Change-Id: Id13ad9fa3157d0479da12fb8184437be3ca8c948 Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java190
1 files changed, 96 insertions, 94 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java
index c70604ecb4..f3ac65ca08 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java
@@ -61,109 +61,111 @@ public class StatusCommandTest extends RepositoryTestCase {
@Test
public void testEmptyStatus() throws NoWorkTreeException,
GitAPIException {
- Git git = new Git(db);
-
- Status stat = git.status().call();
- assertEquals(0, stat.getAdded().size());
- assertEquals(0, stat.getChanged().size());
- assertEquals(0, stat.getMissing().size());
- assertEquals(0, stat.getModified().size());
- assertEquals(0, stat.getRemoved().size());
- assertEquals(0, stat.getUntracked().size());
+ try (Git git = new Git(db)) {
+ Status stat = git.status().call();
+ assertEquals(0, stat.getAdded().size());
+ assertEquals(0, stat.getChanged().size());
+ assertEquals(0, stat.getMissing().size());
+ assertEquals(0, stat.getModified().size());
+ assertEquals(0, stat.getRemoved().size());
+ assertEquals(0, stat.getUntracked().size());
+ }
}
@Test
public void testDifferentStates() throws IOException,
NoFilepatternException, GitAPIException {
- Git git = new Git(db);
- writeTrashFile("a", "content of a");
- writeTrashFile("b", "content of b");
- writeTrashFile("c", "content of c");
- git.add().addFilepattern("a").addFilepattern("b").call();
- Status stat = git.status().call();
- assertEquals(Sets.of("a", "b"), stat.getAdded());
- assertEquals(0, stat.getChanged().size());
- assertEquals(0, stat.getMissing().size());
- assertEquals(0, stat.getModified().size());
- assertEquals(0, stat.getRemoved().size());
- assertEquals(Sets.of("c"), stat.getUntracked());
- git.commit().setMessage("initial").call();
-
- writeTrashFile("a", "modified content of a");
- writeTrashFile("b", "modified content of b");
- writeTrashFile("d", "content of d");
- git.add().addFilepattern("a").addFilepattern("d").call();
- writeTrashFile("a", "again modified content of a");
- stat = git.status().call();
- assertEquals(Sets.of("d"), stat.getAdded());
- assertEquals(Sets.of("a"), stat.getChanged());
- assertEquals(0, stat.getMissing().size());
- assertEquals(Sets.of("b", "a"), stat.getModified());
- assertEquals(0, stat.getRemoved().size());
- assertEquals(Sets.of("c"), stat.getUntracked());
- git.add().addFilepattern(".").call();
- git.commit().setMessage("second").call();
-
- stat = git.status().call();
- assertEquals(0, stat.getAdded().size());
- assertEquals(0, stat.getChanged().size());
- assertEquals(0, stat.getMissing().size());
- assertEquals(0, stat.getModified().size());
- assertEquals(0, stat.getRemoved().size());
- assertEquals(0, stat.getUntracked().size());
-
- deleteTrashFile("a");
- assertFalse(new File(git.getRepository().getWorkTree(), "a").exists());
- git.add().addFilepattern("a").setUpdate(true).call();
- writeTrashFile("a", "recreated content of a");
- stat = git.status().call();
- assertEquals(0, stat.getAdded().size());
- assertEquals(0, stat.getChanged().size());
- assertEquals(0, stat.getMissing().size());
- assertEquals(0, stat.getModified().size());
- assertEquals(Sets.of("a"), stat.getRemoved());
- assertEquals(Sets.of("a"), stat.getUntracked());
- git.commit().setMessage("t").call();
-
- writeTrashFile("sub/a", "sub-file");
- stat = git.status().call();
- assertEquals(1, stat.getUntrackedFolders().size());
- assertTrue(stat.getUntrackedFolders().contains("sub"));
+ try (Git git = new Git(db)) {
+ writeTrashFile("a", "content of a");
+ writeTrashFile("b", "content of b");
+ writeTrashFile("c", "content of c");
+ git.add().addFilepattern("a").addFilepattern("b").call();
+ Status stat = git.status().call();
+ assertEquals(Sets.of("a", "b"), stat.getAdded());
+ assertEquals(0, stat.getChanged().size());
+ assertEquals(0, stat.getMissing().size());
+ assertEquals(0, stat.getModified().size());
+ assertEquals(0, stat.getRemoved().size());
+ assertEquals(Sets.of("c"), stat.getUntracked());
+ git.commit().setMessage("initial").call();
+
+ writeTrashFile("a", "modified content of a");
+ writeTrashFile("b", "modified content of b");
+ writeTrashFile("d", "content of d");
+ git.add().addFilepattern("a").addFilepattern("d").call();
+ writeTrashFile("a", "again modified content of a");
+ stat = git.status().call();
+ assertEquals(Sets.of("d"), stat.getAdded());
+ assertEquals(Sets.of("a"), stat.getChanged());
+ assertEquals(0, stat.getMissing().size());
+ assertEquals(Sets.of("b", "a"), stat.getModified());
+ assertEquals(0, stat.getRemoved().size());
+ assertEquals(Sets.of("c"), stat.getUntracked());
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("second").call();
+
+ stat = git.status().call();
+ assertEquals(0, stat.getAdded().size());
+ assertEquals(0, stat.getChanged().size());
+ assertEquals(0, stat.getMissing().size());
+ assertEquals(0, stat.getModified().size());
+ assertEquals(0, stat.getRemoved().size());
+ assertEquals(0, stat.getUntracked().size());
+
+ deleteTrashFile("a");
+ assertFalse(new File(git.getRepository().getWorkTree(), "a").exists());
+ git.add().addFilepattern("a").setUpdate(true).call();
+ writeTrashFile("a", "recreated content of a");
+ stat = git.status().call();
+ assertEquals(0, stat.getAdded().size());
+ assertEquals(0, stat.getChanged().size());
+ assertEquals(0, stat.getMissing().size());
+ assertEquals(0, stat.getModified().size());
+ assertEquals(Sets.of("a"), stat.getRemoved());
+ assertEquals(Sets.of("a"), stat.getUntracked());
+ git.commit().setMessage("t").call();
+
+ writeTrashFile("sub/a", "sub-file");
+ stat = git.status().call();
+ assertEquals(1, stat.getUntrackedFolders().size());
+ assertTrue(stat.getUntrackedFolders().contains("sub"));
+ }
}
@Test
public void testDifferentStatesWithPaths() throws IOException,
NoFilepatternException, GitAPIException {
- Git git = new Git(db);
- writeTrashFile("a", "content of a");
- writeTrashFile("D/b", "content of b");
- writeTrashFile("D/c", "content of c");
- writeTrashFile("D/D/d", "content of d");
- git.add().addFilepattern(".").call();
-
- writeTrashFile("a", "new content of a");
- writeTrashFile("D/b", "new content of b");
- writeTrashFile("D/D/d", "new content of d");
-
-
- // filter on an not existing path
- Status stat = git.status().addPath("x").call();
- assertEquals(0, stat.getModified().size());
-
- // filter on an existing file
- stat = git.status().addPath("a").call();
- assertEquals(Sets.of("a"), stat.getModified());
-
- // filter on an existing folder
- stat = git.status().addPath("D").call();
- assertEquals(Sets.of("D/b", "D/D/d"), stat.getModified());
-
- // filter on an existing folder and file
- stat = git.status().addPath("D/D").addPath("a").call();
- assertEquals(Sets.of("a", "D/D/d"), stat.getModified());
-
- // do not filter at all
- stat = git.status().call();
- assertEquals(Sets.of("a", "D/b", "D/D/d"), stat.getModified());
+ try (Git git = new Git(db)) {
+ writeTrashFile("a", "content of a");
+ writeTrashFile("D/b", "content of b");
+ writeTrashFile("D/c", "content of c");
+ writeTrashFile("D/D/d", "content of d");
+ git.add().addFilepattern(".").call();
+
+ writeTrashFile("a", "new content of a");
+ writeTrashFile("D/b", "new content of b");
+ writeTrashFile("D/D/d", "new content of d");
+
+
+ // filter on an not existing path
+ Status stat = git.status().addPath("x").call();
+ assertEquals(0, stat.getModified().size());
+
+ // filter on an existing file
+ stat = git.status().addPath("a").call();
+ assertEquals(Sets.of("a"), stat.getModified());
+
+ // filter on an existing folder
+ stat = git.status().addPath("D").call();
+ assertEquals(Sets.of("D/b", "D/D/d"), stat.getModified());
+
+ // filter on an existing folder and file
+ stat = git.status().addPath("D/D").addPath("a").call();
+ assertEquals(Sets.of("a", "D/D/d"), stat.getModified());
+
+ // do not filter at all
+ stat = git.status().call();
+ assertEquals(Sets.of("a", "D/b", "D/D/d"), stat.getModified());
+ }
}
}