diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2010-01-05 11:44:52 -0800 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2010-01-12 11:56:55 -0800 |
commit | f945c424d0cc7688cd160fd5ed9636cd2479e378 (patch) | |
tree | e55b3dcb963eabdc3be1247d3975508f76e98546 /org.eclipse.jgit.test | |
parent | 23cb7f9d5c1fa1c57cc59350ff16a9ecff527313 (diff) | |
download | jgit-f945c424d0cc7688cd160fd5ed9636cd2479e378.tar.gz jgit-f945c424d0cc7688cd160fd5ed9636cd2479e378.zip |
Abstract out utility functions for creating test commits
These routines create a fairly clean DSL for writing out the
structure of a repository in a test case. Abstract them into
a helper class that we can reuse in other test environments.
Change-Id: I55cce3d557e1a28afe2fdf37b3a5b67e2651c9f1
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit.test')
8 files changed, 54 insertions, 102 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/DateRevQueueTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/DateRevQueueTest.java index b3a92951b6..ee9c81cbdd 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/DateRevQueueTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/DateRevQueueTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, Google Inc. + * Copyright (C) 2009-2010, Google Inc. * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -60,10 +60,10 @@ public class DateRevQueueTest extends RevQueueTestCase<DateRevQueue> { } public void testInsertOutOfOrder() throws Exception { - final RevCommit a = parse(commit()); - final RevCommit b = parse(commit(10, a)); - final RevCommit c1 = parse(commit(5, b)); - final RevCommit c2 = parse(commit(-50, b)); + final RevCommit a = parseBody(commit()); + final RevCommit b = parseBody(commit(10, a)); + final RevCommit c1 = parseBody(commit(5, b)); + final RevCommit c2 = parseBody(commit(-50, b)); q.add(c2); q.add(a); @@ -78,8 +78,8 @@ public class DateRevQueueTest extends RevQueueTestCase<DateRevQueue> { } public void testInsertTie() throws Exception { - final RevCommit a = parse(commit()); - final RevCommit b = parse(commit(0, a)); + final RevCommit a = parseBody(commit()); + final RevCommit b = parseBody(commit(0, a)); { q = create(); q.add(a); @@ -101,9 +101,9 @@ public class DateRevQueueTest extends RevQueueTestCase<DateRevQueue> { } public void testCloneFIFO() throws Exception { - final RevCommit a = parse(commit()); - final RevCommit b = parse(commit(200, a)); - final RevCommit c = parse(commit(200, b)); + final RevCommit a = parseBody(commit()); + final RevCommit b = parseBody(commit(200, a)); + final RevCommit c = parseBody(commit(200, b)); final FIFORevQueue src = new FIFORevQueue(); src.add(a); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/ObjectWalkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/ObjectWalkTest.java index 7dddeee205..582406c01b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/ObjectWalkTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/ObjectWalkTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, Google Inc. + * Copyright (C) 2009-2010, Google Inc. * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -46,6 +46,7 @@ package org.eclipse.jgit.revwalk; public class ObjectWalkTest extends RevWalkTestCase { protected ObjectWalk objw; + @Override protected RevWalk createRevWalk() { return objw = new ObjectWalk(db); } @@ -64,7 +65,7 @@ public class ObjectWalkTest extends RevWalkTestCase { assertCommit(a, objw.next()); assertNull(objw.next()); - assertSame(emptyTree, objw.nextObject()); + assertSame(tree(), objw.nextObject()); assertNull(objw.nextObject()); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java index 87ecaa8c53..d4f289a16b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, Google Inc. + * Copyright (C) 2009-2010, Google Inc. * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -81,10 +81,10 @@ public class RevObjectTest extends RevWalkTestCase { } public void testRevObjectTypes() throws Exception { - assertEquals(Constants.OBJ_TREE, emptyTree.getType()); + assertEquals(Constants.OBJ_TREE, tree().getType()); assertEquals(Constants.OBJ_COMMIT, commit().getType()); assertEquals(Constants.OBJ_BLOB, blob("").getType()); - assertEquals(Constants.OBJ_TAG, tag("emptyTree", emptyTree).getType()); + assertEquals(Constants.OBJ_TAG, tag("emptyTree", tree()).getType()); } public void testHasRevFlag() throws Exception { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevQueueTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevQueueTestCase.java index 24e84b041d..c549054cbb 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevQueueTestCase.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevQueueTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, Google Inc. + * Copyright (C) 2009-2010, Google Inc. * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -61,8 +61,8 @@ public abstract class RevQueueTestCase<T extends AbstractRevQueue> extends } public void testClear() throws Exception { - final RevCommit a = parse(commit()); - final RevCommit b = parse(commit(a)); + final RevCommit a = parseBody(commit()); + final RevCommit b = parseBody(commit(a)); q.add(a); q.add(b); @@ -71,8 +71,8 @@ public abstract class RevQueueTestCase<T extends AbstractRevQueue> extends } public void testHasFlags() throws Exception { - final RevCommit a = parse(commit()); - final RevCommit b = parse(commit(a)); + final RevCommit a = parseBody(commit()); + final RevCommit b = parseBody(commit(a)); q.add(a); q.add(b); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFilterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFilterTest.java index db4c38e72b..a6421c41d1 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFilterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, Google Inc. + * Copyright (C) 2009-2010, Google Inc. * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -231,14 +231,14 @@ public class RevWalkFilterTest extends RevWalkTestCase { final RevCommit b = commit(a); tick(100); - Date since = new Date(nowTick); + Date since = getClock(); final RevCommit c1 = commit(b); tick(100); final RevCommit c2 = commit(b); tick(100); - Date until = new Date(nowTick); + Date until = getClock(); final RevCommit d = commit(c1, c2); tick(100); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter6012Test.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter6012Test.java index 73d41eae64..c4bfbf8819 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter6012Test.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter6012Test.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, Google Inc. + * Copyright (C) 2009-2010, Google Inc. * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -80,10 +80,10 @@ public class RevWalkPathFilter6012Test extends RevWalkTestCase { b = commit(tree(file(pF, zI)), a); c = commit(tree(file(pF, zI)), a); d = commit(tree(file(pA, zS), file(pF, zI)), c); - parse(d); + parseBody(d); e = commit(d.getTree(), d, b); f = commit(tree(file(pA, zS), file(pE, zY), file(pF, zI)), e); - parse(f); + parseBody(f); g = commit(tree(file(pE, zY), file(pF, zI)), b); h = commit(f.getTree(), g, f); i = commit(tree(file(pA, zS), file(pE, zY), file(pF, zF)), h); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkSortTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkSortTest.java index 0d3e0cf5aa..65ed873bf4 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkSortTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkSortTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, Google Inc. + * Copyright (C) 2009-2010, Google Inc. * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -96,8 +96,8 @@ public class RevWalkSortTest extends RevWalkTestCase { final RevCommit b = commit(a); final RevCommit c = commit(-5, b); final RevCommit d = commit(10, c); - assertTrue(parse(a).getCommitTime() < parse(d).getCommitTime()); - assertTrue(parse(c).getCommitTime() < parse(b).getCommitTime()); + assertTrue(parseBody(a).getCommitTime() < parseBody(d).getCommitTime()); + assertTrue(parseBody(c).getCommitTime() < parseBody(b).getCommitTime()); rw.sort(RevSort.COMMIT_TIME_DESC); markStart(d); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java index 312fc00b13..64052323f1 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009, Google Inc. + * Copyright (C) 2009-2010, Google Inc. * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -43,130 +43,81 @@ package org.eclipse.jgit.revwalk; -import java.util.Collections; import java.util.Date; -import org.eclipse.jgit.dircache.DirCache; -import org.eclipse.jgit.dircache.DirCacheBuilder; import org.eclipse.jgit.dircache.DirCacheEntry; -import org.eclipse.jgit.lib.Commit; -import org.eclipse.jgit.lib.Constants; -import org.eclipse.jgit.lib.FileMode; -import org.eclipse.jgit.lib.ObjectId; -import org.eclipse.jgit.lib.ObjectWriter; -import org.eclipse.jgit.lib.PersonIdent; +import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.lib.RepositoryTestCase; -import org.eclipse.jgit.lib.Tag; -import org.eclipse.jgit.lib.Tree; -import org.eclipse.jgit.treewalk.TreeWalk; -import org.eclipse.jgit.treewalk.filter.PathFilterGroup; /** Support for tests of the {@link RevWalk} class. */ public abstract class RevWalkTestCase extends RepositoryTestCase { - protected ObjectWriter ow; - - protected RevTree emptyTree; - - protected long nowTick; + private TestRepository util; protected RevWalk rw; + @Override public void setUp() throws Exception { super.setUp(); - ow = new ObjectWriter(db); - rw = createRevWalk(); - emptyTree = rw.parseTree(ow.writeTree(new Tree(db))); - nowTick = 1236977987000L; + util = new TestRepository(db, createRevWalk()); + rw = util.getRevWalk(); } protected RevWalk createRevWalk() { return new RevWalk(db); } + protected Date getClock() { + return util.getClock(); + } + protected void tick(final int secDelta) { - nowTick += secDelta * 1000L; + util.tick(secDelta); } protected RevBlob blob(final String content) throws Exception { - return rw.lookupBlob(ow.writeBlob(Constants.encode(content))); + return util.blob(content); } protected DirCacheEntry file(final String path, final RevBlob blob) throws Exception { - final DirCacheEntry e = new DirCacheEntry(path); - e.setFileMode(FileMode.REGULAR_FILE); - e.setObjectId(blob); - return e; + return util.file(path, blob); } protected RevTree tree(final DirCacheEntry... entries) throws Exception { - final DirCache dc = DirCache.newInCore(); - final DirCacheBuilder b = dc.builder(); - for (final DirCacheEntry e : entries) - b.add(e); - b.finish(); - return rw.lookupTree(dc.writeTree(ow)); + return util.tree(entries); } protected RevObject get(final RevTree tree, final String path) throws Exception { - final TreeWalk tw = new TreeWalk(db); - tw.setFilter(PathFilterGroup.createFromStrings(Collections - .singleton(path))); - tw.reset(tree); - while (tw.next()) { - if (tw.isSubtree() && !path.equals(tw.getPathString())) { - tw.enterSubtree(); - continue; - } - final ObjectId entid = tw.getObjectId(0); - final FileMode entmode = tw.getFileMode(0); - return rw.lookupAny(entid, entmode.getObjectType()); - } - fail("Can't find " + path + " in tree " + tree.name()); - return null; // never reached. + return util.get(tree, path); } protected RevCommit commit(final RevCommit... parents) throws Exception { - return commit(1, emptyTree, parents); + return util.commit(parents); } protected RevCommit commit(final RevTree tree, final RevCommit... parents) throws Exception { - return commit(1, tree, parents); + return util.commit(tree, parents); } protected RevCommit commit(final int secDelta, final RevCommit... parents) throws Exception { - return commit(secDelta, emptyTree, parents); + return util.commit(secDelta, parents); } protected RevCommit commit(final int secDelta, final RevTree tree, final RevCommit... parents) throws Exception { - tick(secDelta); - final Commit c = new Commit(db); - c.setTreeId(tree); - c.setParentIds(parents); - c.setAuthor(new PersonIdent(author, new Date(nowTick))); - c.setCommitter(new PersonIdent(committer, new Date(nowTick))); - c.setMessage(""); - return rw.lookupCommit(ow.writeCommit(c)); + return util.commit(secDelta, tree, parents); } protected RevTag tag(final String name, final RevObject dst) throws Exception { - final Tag t = new Tag(db); - t.setType(Constants.typeString(dst.getType())); - t.setObjId(dst.toObjectId()); - t.setTag(name); - t.setTagger(new PersonIdent(committer, new Date(nowTick))); - t.setMessage(""); - return (RevTag) rw.lookupAny(ow.writeTag(t), Constants.OBJ_TAG); - } - - protected <T extends RevObject> T parse(final T t) throws Exception { - rw.parseBody(t); - return t; + return util.tag(name, dst); + } + + protected <T extends RevObject> T parseBody(final T t) throws Exception { + return util.parseBody(t); } protected void markStart(final RevCommit commit) throws Exception { |