RevCommitListTest: Open Git and RevWalk in try-with-resource

Change-Id: I4ba273a364a12f82a3b3b06ba050bc633411daf6
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
This commit is contained in:
David Pursehouse 2016-02-05 17:26:03 +09:00
parent 5bfdc3341c
commit 3c4e7c08a7
1 changed files with 19 additions and 17 deletions

View File

@ -57,14 +57,15 @@ public class RevCommitListTest extends RepositoryTestCase {
private RevCommitList<RevCommit> list; private RevCommitList<RevCommit> list;
public void setup(int count) throws Exception { public void setup(int count) throws Exception {
Git git = new Git(db); try (Git git = new Git(db);
for (int i = 0; i < count; i++) RevWalk w = new RevWalk(db);) {
git.commit().setCommitter(committer).setAuthor(author) for (int i = 0; i < count; i++)
.setMessage("commit " + i).call(); git.commit().setCommitter(committer).setAuthor(author)
list = new RevCommitList<RevCommit>(); .setMessage("commit " + i).call();
RevWalk w = new RevWalk(db); list = new RevCommitList<RevCommit>();
w.markStart(w.lookupCommit(db.resolve(Constants.HEAD))); w.markStart(w.lookupCommit(db.resolve(Constants.HEAD)));
list.source(w); list.source(w);
}
} }
@Test @Test
@ -107,17 +108,18 @@ public void testFillToHighMarkMulitpleBlocks() throws Exception {
public void testFillToCommit() throws Exception { public void testFillToCommit() throws Exception {
setup(3); setup(3);
RevWalk w = new RevWalk(db); try (RevWalk w = new RevWalk(db)) {
w.markStart(w.lookupCommit(db.resolve(Constants.HEAD))); w.markStart(w.lookupCommit(db.resolve(Constants.HEAD)));
w.next(); w.next();
RevCommit c = w.next(); RevCommit c = w.next();
assertNotNull("should have found 2. commit", c); assertNotNull("should have found 2. commit", c);
list.fillTo(c, 5); list.fillTo(c, 5);
assertEquals(2, list.size()); assertEquals(2, list.size());
assertEquals("commit 1", list.get(1).getFullMessage()); assertEquals("commit 1", list.get(1).getFullMessage());
assertNull(list.get(3)); assertNull(list.get(3));
}
} }
@Test @Test