aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Thun2011-03-21 04:40:14 (EDT)
committerPhilipp Thun2011-03-21 04:40:14 (EDT)
commitdcefc660f15a85fcc2b4ca21ca5d12938b157e82 (patch)
tree89b3dfdcb01650aa0d2f8219eeeb010392a61f81
parenta62abbe180a6793adcc5a3db7a55c225066daf8d (diff)
downloadjgit-dcefc660f15a85fcc2b4ca21ca5d12938b157e82.zip
jgit-dcefc660f15a85fcc2b4ca21ca5d12938b157e82.tar.gz
jgit-dcefc660f15a85fcc2b4ca21ca5d12938b157e82.tar.bz2
Refactor test casesrefs/changes/34/2734/2
This change moves commonly used methods into the RepositoryTestCase base class. Change-Id: I56a46c31ee1661c7ce22eb755ab23da8bc9f5da2 Signed-off-by: Philipp Thun <philipp.thun@sap.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java20
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java27
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java22
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java18
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java25
5 files changed, 25 insertions, 87 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
index 6f57a62..88bd6ac 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
+++ b/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.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.revwalk.RevCommit;
-import org.eclipse.jgit.revwalk.RevWalk;
import org.junit.Test;
/**
@@ -103,20 +99,4 @@ public class CherryPickCommandTest extends RepositoryTestCase {
assertEquals("create a", history.next().getFullMessage());
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);
- }
-
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
index 2761989..132aaa1 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
+++ b/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 java.io.File;
-import java.io.IOException;
import java.util.Iterator;
import org.eclipse.jgit.api.MergeResult.MergeStatus;
import org.eclipse.jgit.api.errors.InvalidMergeHeadsException;
-import org.eclipse.jgit.dircache.DirCacheCheckout;
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.RepositoryTestCase;
import org.eclipse.jgit.merge.MergeStrategy;
import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.revwalk.RevWalk;
import org.junit.Test;
public class MergeCommandTest extends RepositoryTestCase {
@@ -163,7 +158,6 @@ public class MergeCommandTest extends RepositoryTestCase {
}
}
-
@Test
public void testContentMerge() throws Exception {
Git git = new Git(db);
@@ -795,25 +789,4 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(null, result.getConflicts());
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);
- }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
index f1a3f78..8486b70 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
+++ b/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);
}
- 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,
IOException {
RevWalk walk = new RevWalk(db);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
index 481a645..160eb65 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
+++ b/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.errors.CorruptObjectException;
import org.eclipse.jgit.errors.NoWorkTreeException;
-import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.revwalk.RevWalk;
import org.junit.Test;
public class DirCacheCheckoutTest extends ReadTreeTest {
@@ -159,20 +157,4 @@ public class DirCacheCheckoutTest extends ReadTreeTest {
assertTrue(dc.checkout());
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));
- }
-
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java
index ee4165d..934c76c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java
+++ b/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.DirCacheBuilder;
+import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.dircache.DirCacheEntry;
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.treewalk.FileTreeIterator;
import org.eclipse.jgit.util.FileUtils;
@@ -374,4 +377,26 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
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);
+ }
}