[Mercurial Tests] createRepository and cloneFrom moved to HgTestRepository.

Made AbstractVcsTestCase.verify() public.
This commit is contained in:
Kirill Likhodedov
2010-08-10 17:38:18 +04:00
parent 330f577e5a
commit cc9eda08cc
5 changed files with 54 additions and 42 deletions
@@ -215,7 +215,7 @@ public class AbstractVcsTestCase {
option.setValue(value);
}
protected static void verify(final ProcessOutput runResult) {
public static void verify(final ProcessOutput runResult) {
Assert.assertEquals(runResult.getStderr(), 0, runResult.getExitCode());
}
@@ -20,8 +20,6 @@ import com.intellij.openapi.vcs.changes.VcsDirtyScopeManager;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.AbstractVcsTestCase;
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory;
import com.intellij.testFramework.fixtures.TempDirTestFixture;
import com.intellij.vcsUtil.VcsUtil;
import org.jetbrains.annotations.Nullable;
import org.testng.annotations.BeforeMethod;
@@ -66,24 +64,6 @@ public abstract class HgAbstractTestCase extends AbstractVcsTestCase {
myTraceClient = true;
}
/**
* Creates a new Mercurial repository in a temporary test directory.
* @return created repository
*/
protected HgTestRepository createRepository() throws Exception {
final TempDirTestFixture dirFixture = createFixtureDir();
final File repo = new File(dirFixture.getTempDirPath());
ProcessOutput processOutput = runHg(repo, "init");
verify(processOutput);
return new HgTestRepository(this, dirFixture);
}
protected static TempDirTestFixture createFixtureDir() throws Exception {
final TempDirTestFixture fixture = IdeaTestFixtureFactory.getFixtureFactory().createTempDirTestFixture();
fixture.setUp();
return fixture;
}
protected void enableSilentOperation(final VcsConfiguration.StandardConfirmation op) {
setStandardConfirmation(HgVcs.VCS_NAME, op, VcsShowConfirmationOption.Value.DO_ACTION_SILENTLY);
}
@@ -15,9 +15,7 @@
*/
package org.zmlx.hg4idea.test;
import com.intellij.execution.process.ProcessOutput;
import com.intellij.openapi.vcs.VcsConfiguration;
import com.intellij.testFramework.fixtures.TempDirTestFixture;
import org.testng.annotations.BeforeMethod;
import org.zmlx.hg4idea.HgVcs;
@@ -38,8 +36,8 @@ public class HgCollaborativeTestCase extends HgAbstractTestCase {
protected void setUp() throws Exception {
super.setUp();
myParentRepo = createRepository();
myRepo = cloneFrom(myParentRepo);
myParentRepo = HgTestRepository.create(this);
myRepo = myParentRepo.cloneRepository();
myProjectDir = new File(myRepo.getDirFixture().getTempDirPath());
@@ -51,16 +49,4 @@ public class HgCollaborativeTestCase extends HgAbstractTestCase {
enableSilentOperation(VcsConfiguration.StandardConfirmation.REMOVE);
}
/**
* Clones a repository from the given one. New repository is located in a temporary test directory.
* @param parent repository to clone from.
* @return New repository cloned from the given parent.
*/
protected HgTestRepository cloneFrom(HgTestRepository parent) throws Exception {
final TempDirTestFixture dirFixture = createFixtureDir();
final ProcessOutput processOutput = runHg(null, "clone", parent.getDirFixture().getTempDirPath(), dirFixture.getTempDirPath());
verify(processOutput);
return new HgTestRepository(this, dirFixture);
}
}
@@ -35,7 +35,7 @@ public class HgSingleUserTestCase extends HgAbstractTestCase {
protected void setUp() throws Exception {
super.setUp();
myRepo = createRepository();
myRepo = HgTestRepository.create(this);
myProjectDir = new File(myRepo.getDirFixture().getTempDirPath());
initProject(myProjectDir);
@@ -15,7 +15,10 @@
*/
package org.zmlx.hg4idea.test;
import com.intellij.execution.process.ProcessOutput;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.AbstractVcsTestCase;
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory;
import com.intellij.testFramework.fixtures.TempDirTestFixture;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -47,11 +50,49 @@ class HgTestRepository {
myParent = parent;
}
/**
* Creates a new Mercurial repository in a new temporary test directory.
* @param testCase reference to the test case instance.
* @return created repository.
*/
public static HgTestRepository create(HgAbstractTestCase testCase) throws Exception {
final TempDirTestFixture dirFixture = createFixtureDir();
final File repo = new File(dirFixture.getTempDirPath());
final ProcessOutput processOutput = testCase.runHg(repo, "init");
AbstractVcsTestCase.verify(processOutput);
return new HgTestRepository(testCase, dirFixture);
}
private static TempDirTestFixture createFixtureDir() throws Exception {
final TempDirTestFixture fixture = IdeaTestFixtureFactory.getFixtureFactory().createTempDirTestFixture();
fixture.setUp();
return fixture;
}
/**
* Clones a repository from this one. New repository is located in a new temporary test directory.
* @return New repository cloned from this one.
*/
HgTestRepository cloneRepository() throws Exception {
final TempDirTestFixture dirFixture = createFixtureDir();
final ProcessOutput processOutput = myTest.runHg(null, "clone", getDirFixture().getTempDirPath(), dirFixture.getTempDirPath());
AbstractVcsTestCase.verify(processOutput);
return new HgTestRepository(myTest, dirFixture);
}
@NotNull
TempDirTestFixture getDirFixture() {
return myDirFixture;
}
public VirtualFile getDir() {
return myDirFixture.getFile(".");
}
public VirtualFile createFile(String filename) {
return myDirFixture.createFile(filename);
}
/**
* Natively executes the given mercurial command.
* @param commandWithParameters Mercurial command with parameters. E.g. ["status", "-a"]
@@ -68,15 +109,20 @@ class HgTestRepository {
execute("commit", "-m", "Sample commit message");
}
void update() throws IOException {
execute("update");
void merge() throws IOException {
execute("merge");
}
void pull() throws IOException {
execute("pull");
}
void push() throws IOException {
execute("push");
}
public VirtualFile getDir() {
return myDirFixture.getFile(".");
void update() throws IOException {
execute("update");
}
}