Browse Source

Refactor test cases

This change moves commonly used methods into the RepositoryTestCase
base class.

Change-Id: I56a46c31ee1661c7ce22eb755ab23da8bc9f5da2
Signed-off-by: Philipp Thun <philipp.thun@sap.com>
stable-0.12
Philipp Thun 14 years ago
parent
commit
dcefc660f1
  1. 20
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
  2. 27
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
  3. 22
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
  4. 18
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
  5. 25
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java

20
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java

@ -51,12 +51,8 @@ import java.util.Iterator;
import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.junit.Test; import org.junit.Test;
/** /**
@ -103,20 +99,4 @@ public class CherryPickCommandTest extends RepositoryTestCase {
assertEquals("create a", history.next().getFullMessage()); assertEquals("create a", history.next().getFullMessage());
assertFalse(history.hasNext()); assertFalse(history.hasNext());
} }
private void checkoutBranch(String branchName)
throws IllegalStateException, IOException {
RevWalk walk = new RevWalk(db);
RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD));
RevCommit branch = walk.parseCommit(db.resolve(branchName));
DirCacheCheckout dco = new DirCacheCheckout(db, head.getTree().getId(),
db.lockDirCache(), branch.getTree().getId());
dco.setFailOnConflict(true);
dco.checkout();
walk.release();
// update the HEAD
RefUpdate refUpdate = db.updateRef(Constants.HEAD);
refUpdate.link(branchName);
}
} }

27
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java

@ -49,20 +49,15 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import org.eclipse.jgit.api.MergeResult.MergeStatus; import org.eclipse.jgit.api.MergeResult.MergeStatus;
import org.eclipse.jgit.api.errors.InvalidMergeHeadsException; import org.eclipse.jgit.api.errors.InvalidMergeHeadsException;
import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RepositoryState; import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.merge.MergeStrategy; import org.eclipse.jgit.merge.MergeStrategy;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.junit.Test; import org.junit.Test;
public class MergeCommandTest extends RepositoryTestCase { public class MergeCommandTest extends RepositoryTestCase {
@ -163,7 +158,6 @@ public class MergeCommandTest extends RepositoryTestCase {
} }
} }
@Test @Test
public void testContentMerge() throws Exception { public void testContentMerge() throws Exception {
Git git = new Git(db); Git git = new Git(db);
@ -795,25 +789,4 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(null, result.getConflicts()); assertEquals(null, result.getConflicts());
assertEquals(RepositoryState.SAFE, db.getRepositoryState()); assertEquals(RepositoryState.SAFE, db.getRepositoryState());
} }
private void createBranch(ObjectId objectId, String branchName) throws IOException {
RefUpdate updateRef = db.updateRef(branchName);
updateRef.setNewObjectId(objectId);
updateRef.update();
}
private void checkoutBranch(String branchName) throws IllegalStateException, IOException {
RevWalk walk = new RevWalk(db);
RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD));
RevCommit branch = walk.parseCommit(db.resolve(branchName));
DirCacheCheckout dco = new DirCacheCheckout(db,
head.getTree().getId(), db.lockDirCache(),
branch.getTree().getId());
dco.setFailOnConflict(true);
dco.checkout();
walk.release();
// update the HEAD
RefUpdate refUpdate = db.updateRef(Constants.HEAD);
refUpdate.link(branchName);
}
} }

22
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java

@ -84,28 +84,6 @@ public class RebaseCommandTest extends RepositoryTestCase {
this.git = new Git(db); this.git = new Git(db);
} }
private void createBranch(ObjectId objectId, String branchName)
throws IOException {
RefUpdate updateRef = db.updateRef(branchName);
updateRef.setNewObjectId(objectId);
updateRef.update();
}
private void checkoutBranch(String branchName)
throws IllegalStateException, IOException {
RevWalk walk = new RevWalk(db);
RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD));
RevCommit branch = walk.parseCommit(db.resolve(branchName));
DirCacheCheckout dco = new DirCacheCheckout(db, head.getTree().getId(),
db.lockDirCache(), branch.getTree().getId());
dco.setFailOnConflict(true);
dco.checkout();
walk.release();
// update the HEAD
RefUpdate refUpdate = db.updateRef(Constants.HEAD);
refUpdate.link(branchName);
}
private void checkoutCommit(RevCommit commit) throws IllegalStateException, private void checkoutCommit(RevCommit commit) throws IllegalStateException,
IOException { IOException {
RevWalk walk = new RevWalk(db); RevWalk walk = new RevWalk(db);

18
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java

@ -53,9 +53,7 @@ import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheCheckout; import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.errors.CorruptObjectException; import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.errors.NoWorkTreeException; import org.eclipse.jgit.errors.NoWorkTreeException;
import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.junit.Test; import org.junit.Test;
public class DirCacheCheckoutTest extends ReadTreeTest { public class DirCacheCheckoutTest extends ReadTreeTest {
@ -159,20 +157,4 @@ public class DirCacheCheckoutTest extends ReadTreeTest {
assertTrue(dc.checkout()); assertTrue(dc.checkout());
return dc; return dc;
} }
private void checkoutBranch(String branchName)
throws IllegalStateException, IOException {
RevWalk walk = new RevWalk(db);
RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD));
RevCommit branch = walk.parseCommit(db.resolve(branchName));
DirCacheCheckout dco = new DirCacheCheckout(db, head.getTree(),
db.lockDirCache(), branch.getTree());
dco.setFailOnConflict(true);
assertTrue(dco.checkout());
walk.release();
// update the HEAD
RefUpdate refUpdate = db.updateRef(Constants.HEAD);
assertEquals(Result.FORCED, refUpdate.link(branchName));
}
} }

25
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java

@ -60,8 +60,11 @@ import java.util.TreeSet;
import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheBuilder; import org.eclipse.jgit.dircache.DirCacheBuilder;
import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.dircache.DirCacheEntry; import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase; import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
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.FileRepository;
import org.eclipse.jgit.treewalk.FileTreeIterator; import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.util.FileUtils; import org.eclipse.jgit.util.FileUtils;
@ -374,4 +377,26 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
FileUtils.delete(tmp); FileUtils.delete(tmp);
} }
} }
protected void createBranch(ObjectId objectId, String branchName)
throws IOException {
RefUpdate updateRef = db.updateRef(branchName);
updateRef.setNewObjectId(objectId);
updateRef.update();
}
protected void checkoutBranch(String branchName)
throws IllegalStateException, IOException {
RevWalk walk = new RevWalk(db);
RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD));
RevCommit branch = walk.parseCommit(db.resolve(branchName));
DirCacheCheckout dco = new DirCacheCheckout(db, head.getTree().getId(),
db.lockDirCache(), branch.getTree().getId());
dco.setFailOnConflict(true);
dco.checkout();
walk.release();
// update the HEAD
RefUpdate refUpdate = db.updateRef(Constants.HEAD);
refUpdate.link(branchName);
}
} }

Loading…
Cancel
Save