Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse2016-02-12 00:07:24 -0500
committerDavid Pursehouse2016-02-12 00:07:53 -0500
commit53b6bb9cca12aa872a6839f3ab9d129d2708735a (patch)
tree01bbaf236037d26517d71dc37068ee588c8a820b
parentf7a3643fb8c977739af928f2aafc9eeb01a83abc (diff)
downloadjgit-53b6bb9cca12aa872a6839f3ab9d129d2708735a.tar.gz
jgit-53b6bb9cca12aa872a6839f3ab9d129d2708735a.tar.xz
jgit-53b6bb9cca12aa872a6839f3ab9d129d2708735a.zip
PatchIdDiffFormatterTest: Open Git and PatchIdDiffFormatter in try-with-resource
Change-Id: I39e898e52c3d9dffaba9dabf11c085503fbc1acf Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/PatchIdDiffFormatterTest.java82
1 files changed, 43 insertions, 39 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/PatchIdDiffFormatterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/PatchIdDiffFormatterTest.java
index ce283ae4f9..024aaa3f5e 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/PatchIdDiffFormatterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/PatchIdDiffFormatterTest.java
@@ -61,21 +61,22 @@ public class PatchIdDiffFormatterTest extends RepositoryTestCase {
File folder = new File(db.getDirectory().getParent(), "folder");
folder.mkdir();
write(new File(folder, "folder.txt"), "folder");
- Git git = new Git(db);
- git.add().addFilepattern(".").call();
- git.commit().setMessage("Initial commit").call();
- write(new File(folder, "folder.txt"), "folder change");
+ try (Git git = new Git(db);
+ PatchIdDiffFormatter df = new PatchIdDiffFormatter()) {
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("Initial commit").call();
+ write(new File(folder, "folder.txt"), "folder change");
- PatchIdDiffFormatter df = new PatchIdDiffFormatter();
- df.setRepository(db);
- df.setPathFilter(PathFilter.create("folder"));
- DirCacheIterator oldTree = new DirCacheIterator(db.readDirCache());
- FileTreeIterator newTree = new FileTreeIterator(db);
- df.format(oldTree, newTree);
- df.flush();
+ df.setRepository(db);
+ df.setPathFilter(PathFilter.create("folder"));
+ DirCacheIterator oldTree = new DirCacheIterator(db.readDirCache());
+ FileTreeIterator newTree = new FileTreeIterator(db);
+ df.format(oldTree, newTree);
+ df.flush();
- assertEquals("1ff64e0f9333e9b81967c3e8d7a81362b14d5441", df
- .getCalulatedPatchId().name());
+ assertEquals("1ff64e0f9333e9b81967c3e8d7a81362b14d5441", df
+ .getCalulatedPatchId().name());
+ }
}
@Test
@@ -84,37 +85,40 @@ public class PatchIdDiffFormatterTest extends RepositoryTestCase {
File folder = new File(db.getDirectory().getParent(), "folder");
folder.mkdir();
write(new File(folder, "folder.txt"), "\n\n\n\nfolder");
- Git git = new Git(db);
- git.add().addFilepattern(".").call();
- git.commit().setMessage("Initial commit").call();
- write(new File(folder, "folder.txt"), "\n\n\n\nfolder change");
+ try (Git git = new Git(db)) {
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("Initial commit").call();
+ write(new File(folder, "folder.txt"), "\n\n\n\nfolder change");
- PatchIdDiffFormatter df = new PatchIdDiffFormatter();
- df.setRepository(db);
- df.setPathFilter(PathFilter.create("folder"));
- DirCacheIterator oldTree = new DirCacheIterator(db.readDirCache());
- FileTreeIterator newTree = new FileTreeIterator(db);
- df.format(oldTree, newTree);
- df.flush();
+ try (PatchIdDiffFormatter df = new PatchIdDiffFormatter()) {
+ df.setRepository(db);
+ df.setPathFilter(PathFilter.create("folder"));
+ DirCacheIterator oldTree = new DirCacheIterator(db.readDirCache());
+ FileTreeIterator newTree = new FileTreeIterator(db);
+ df.format(oldTree, newTree);
+ df.flush();
- assertEquals("08fca5ac531383eb1da8bf6b6f7cf44411281407", df
- .getCalulatedPatchId().name());
+ assertEquals("08fca5ac531383eb1da8bf6b6f7cf44411281407", df
+ .getCalulatedPatchId().name());
+ }
- write(new File(folder, "folder.txt"), "a\n\n\n\nfolder");
- git.add().addFilepattern(".").call();
- git.commit().setMessage("Initial commit").call();
- write(new File(folder, "folder.txt"), "a\n\n\n\nfolder change");
+ write(new File(folder, "folder.txt"), "a\n\n\n\nfolder");
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("Initial commit").call();
+ write(new File(folder, "folder.txt"), "a\n\n\n\nfolder change");
- df = new PatchIdDiffFormatter();
- df.setRepository(db);
- df.setPathFilter(PathFilter.create("folder"));
- oldTree = new DirCacheIterator(db.readDirCache());
- newTree = new FileTreeIterator(db);
- df.format(oldTree, newTree);
- df.flush();
+ try (PatchIdDiffFormatter df = new PatchIdDiffFormatter()) {
+ df.setRepository(db);
+ df.setPathFilter(PathFilter.create("folder"));
+ DirCacheIterator oldTree = new DirCacheIterator(db.readDirCache());
+ FileTreeIterator newTree = new FileTreeIterator(db);
+ df.format(oldTree, newTree);
+ df.flush();
- assertEquals("08fca5ac531383eb1da8bf6b6f7cf44411281407", df
- .getCalulatedPatchId().name());
+ assertEquals("08fca5ac531383eb1da8bf6b6f7cf44411281407", df
+ .getCalulatedPatchId().name());
+ }
+ }
}
}

Back to the top