]> source.dussan.org Git - jgit.git/commitdiff
Refactor test cases 34/2734/2
authorPhilipp Thun <philipp.thun@sap.com>
Mon, 21 Mar 2011 08:40:14 +0000 (09:40 +0100)
committerPhilipp Thun <philipp.thun@sap.com>
Mon, 21 Mar 2011 08:40:14 +0000 (09:40 +0100)
This change moves commonly used methods into the RepositoryTestCase
base class.

Change-Id: I56a46c31ee1661c7ce22eb755ab23da8bc9f5da2
Signed-off-by: Philipp Thun <philipp.thun@sap.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java

index 6f57a62787f2f2af798cee85b487ac051f5c61f3..88bd6acfdfb037d4044ebe156baeeb899ff03be7 100644 (file)
@@ -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);
-       }
-
 }
index 2761989c717cc817773b9cbb42dc78cb74cabba5..132aaa1ac8321803590e1d4befa5d30acaf2b6d6 100644 (file)
@@ -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);
-       }
 }
index f1a3f783fa513ff0adbdf4bfbdb70f2738397a4a..8486b70a7770ad7990b483b2710d4c4ba73a10a4 100644 (file)
@@ -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);
index 481a645765c8223d37bd2eb48a0281108c0140fd..160eb653b5b0346ca7c08705816f0c3a8ba4476b 100644 (file)
@@ -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));
-       }
-
 }
index ee4165dfb7d47998b0648217dd3410c4fb70f291..934c76cbb5e4e4810ac913d4665c057d8615ecd9 100644 (file)
@@ -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);
+       }
 }