Browse Source

RefUpdateTest: Use try-with-resource for auto-closable types

Change-Id: I25c8db0e410aa2a4a53dc7d8863e4a6efefcf7cb
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
stable-4.2
David Pursehouse 9 years ago
parent
commit
0352276da7
  1. 23
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java

23
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java

@ -558,13 +558,15 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
assertEquals(ppid, db.resolve("refs/heads/master")); assertEquals(ppid, db.resolve("refs/heads/master"));
// real test // real test
RevCommit old = new RevWalk(db).parseCommit(ppid); try (RevWalk rw = new RevWalk(db)) {
RefUpdate updateRef2 = db.updateRef("refs/heads/master"); RevCommit old = rw.parseCommit(ppid);
updateRef2.setExpectedOldObjectId(old); RefUpdate updateRef2 = db.updateRef("refs/heads/master");
updateRef2.setNewObjectId(pid); updateRef2.setExpectedOldObjectId(old);
Result update2 = updateRef2.update(); updateRef2.setNewObjectId(pid);
assertEquals(Result.FAST_FORWARD, update2); Result update2 = updateRef2.update();
assertEquals(pid, db.resolve("refs/heads/master")); assertEquals(Result.FAST_FORWARD, update2);
assertEquals(pid, db.resolve("refs/heads/master"));
}
} }
/** /**
@ -707,9 +709,10 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
// Create new Repository instance, to reread caches and make sure our // Create new Repository instance, to reread caches and make sure our
// assumptions are persistent. // assumptions are persistent.
Repository ndb = new FileRepository(db.getDirectory()); try (Repository ndb = new FileRepository(db.getDirectory())) {
assertEquals(rb2, ndb.resolve("refs/heads/new/name")); assertEquals(rb2, ndb.resolve("refs/heads/new/name"));
assertNull(ndb.resolve("refs/heads/b")); assertNull(ndb.resolve("refs/heads/b"));
}
} }
public void tryRenameWhenLocked(String toLock, String fromName, public void tryRenameWhenLocked(String toLock, String fromName,

Loading…
Cancel
Save