diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2010-10-08 22:41:18 -0700 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2010-10-08 22:41:18 -0700 |
commit | 1739af643e35efc29fa5f4828ae87941821b94b2 (patch) | |
tree | 671d8b09ea827fbc0c4db65dbacd125066aa3797 /org.eclipse.jgit.test/tst/org/eclipse/jgit | |
parent | be2ddff6a72cff3d28b87d038a96194a6e2bd272 (diff) | |
download | jgit-1739af643e35efc29fa5f4828ae87941821b94b2.tar.gz jgit-1739af643e35efc29fa5f4828ae87941821b94b2.zip |
Cleanup RefUpdateTest
Application code, including unit tests for storage implementations,
should not extend RevCommit outside of the scope of using it for a
RevWalk. Its a lot of overhead and unlikely to work long-term.
Instead for the one test that matters, use a custom subclass of the
ObjectId type. This lets us measure exactly what we are looking for,
which is that the subclass isn't retained.
A lot of other tests were unnecessarily wrapping an object with a
RevCommit and storing that back into the RefUpdate. This is just
retesting what the earlier no-cache test was doing, and complicated
the test considerably. Drop that code and just rely on the value that
was configured by the helper method.
Change-Id: I5b31813484eaa306e9bc4de9622dd5bd4846b16d
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefUpdateTest.java | 42 |
1 files changed, 9 insertions, 33 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefUpdateTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefUpdateTest.java index a8a6d9d823..4e2e14a6f5 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefUpdateTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/RefUpdateTest.java @@ -51,22 +51,18 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.RefRename; import org.eclipse.jgit.lib.RefUpdate; +import org.eclipse.jgit.lib.RefUpdate.Result; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.SampleDataRepositoryTestCase; -import org.eclipse.jgit.lib.RefUpdate.Result; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; -import org.eclipse.jgit.storage.file.FileRepository; -import org.eclipse.jgit.storage.file.LockFile; -import org.eclipse.jgit.storage.file.RefDirectory; -import org.eclipse.jgit.storage.file.RefDirectoryUpdate; -import org.eclipse.jgit.storage.file.ReflogReader; public class RefUpdateTest extends SampleDataRepositoryTestCase { @@ -103,9 +99,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { public void testNoCacheObjectIdSubclass() throws IOException { final String newRef = "refs/heads/abc"; final RefUpdate ru = updateRef(newRef); - final RevCommit newid = new RevCommit(ru.getNewObjectId()) { - // empty - }; + final SubclassedId newid = new SubclassedId(ru.getNewObjectId()); ru.setNewObjectId(newid); Result update = ru.update(); assertEquals(Result.NEW, update); @@ -131,19 +125,11 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { throws IOException { final String newRef = "refs/heads/z"; final RefUpdate ru = updateRef(newRef); - final RevCommit newid = new RevCommit(ru.getNewObjectId()) { - // empty - }; - ru.setNewObjectId(newid); Result update = ru.update(); assertEquals(Result.NEW, update); // end setup final String newRef2 = "refs/heads/z/a"; final RefUpdate ru2 = updateRef(newRef2); - final RevCommit newid2 = new RevCommit(ru2.getNewObjectId()) { - // empty - }; - ru.setNewObjectId(newid2); Result update2 = ru2.update(); assertEquals(Result.LOCK_FAILURE, update2); assertEquals(1, db.getReflogReader("refs/heads/z").getReverseEntries().size()); @@ -154,10 +140,6 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { throws IOException { final String newRef = "refs/heads/master/x"; final RefUpdate ru = updateRef(newRef); - final RevCommit newid = new RevCommit(ru.getNewObjectId()) { - // empty - }; - ru.setNewObjectId(newid); Result update = ru.update(); assertEquals(Result.LOCK_FAILURE, update); assertNull(db.getReflogReader("refs/heads/master/x")); @@ -168,19 +150,11 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { throws IOException { final String newRef = "refs/heads/z/a"; final RefUpdate ru = updateRef(newRef); - final RevCommit newid = new RevCommit(ru.getNewObjectId()) { - // empty - }; - ru.setNewObjectId(newid); Result update = ru.update(); assertEquals(Result.NEW, update); // end setup final String newRef2 = "refs/heads/z"; final RefUpdate ru2 = updateRef(newRef2); - final RevCommit newid2 = new RevCommit(ru2.getNewObjectId()) { - // empty - }; - ru.setNewObjectId(newid2); Result update2 = ru2.update(); assertEquals(Result.LOCK_FAILURE, update2); assertEquals(1, db.getReflogReader("refs/heads/z/a").getReverseEntries().size()); @@ -192,10 +166,6 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { throws IOException { final String newRef = "refs/heads/prefix"; final RefUpdate ru = updateRef(newRef); - final RevCommit newid = new RevCommit(ru.getNewObjectId()) { - // empty - }; - ru.setNewObjectId(newid); Result update = ru.update(); assertEquals(Result.LOCK_FAILURE, update); assertNull(db.getReflogReader("refs/heads/prefix")); @@ -853,4 +823,10 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { update.setNewObjectId(newId); refs.log(update, msg, true); } + + private static class SubclassedId extends ObjectId { + SubclassedId(AnyObjectId src) { + super(src); + } + } } |