[git tests] Extract repository creation to GitLightTest. Use in GitBranchWorkerTest

This commit is contained in:
Kirill Likhodedov
2012-10-18 17:53:51 +04:00
parent dbcc68d3bb
commit 3af429b537
2 changed files with 37 additions and 28 deletions
@@ -34,8 +34,10 @@ import git4idea.config.GitVersion
import git4idea.config.GitVersionSpecialty
import git4idea.history.browser.GitCommit
import git4idea.repo.GitRepository
import git4idea.repo.GitRepositoryImpl
import git4idea.test.*
import git4idea.test.GitExecutor
import git4idea.test.GitLightTest
import git4idea.test.GitMockVirtualFile
import git4idea.test.GitScenarios
import org.jetbrains.annotations.NotNull
import org.junit.After
import org.junit.Before
@@ -67,35 +69,15 @@ class GitBranchWorkerTest extends GitLightTest {
def community = mkdir("community")
def contrib = mkdir("contrib")
[ myRootDir, community, contrib ].each { initRepo(it) }
myUltimate = createRepository(myRootDir)
myCommunity = createRepository(community)
myContrib = createRepository(contrib)
myRepositories = [ myUltimate, myCommunity, myContrib ]
cd(myRootDir)
touch(".gitignore", "community\ncontrib")
git("add .gitignore")
git("commit -m gitignore")
myRepositories = [ myUltimate, myCommunity, myContrib ]
myRepositories.each { ((GitTestRepositoryManager)myPlatformFacade.getRepositoryManager(myProject)).add(it) }
}
private GitRepository createRepository(String rootDir) {
// TODO this smells hacky
// the constructor and notifyListeners() should probably be private
// getPresentableUrl should probably be final, and we should have a better VirtualFile implementation for tests.
new GitRepositoryImpl(new GitMockVirtualFile(rootDir), myPlatformFacade, myProject, myProject, true) {
@Override
protected void notifyListeners() {
}
@Override
String getPresentableUrl() {
return rootDir;
}
}
}
@After
@@ -19,6 +19,8 @@ import com.intellij.openapi.util.Disposer
import com.intellij.openapi.util.io.FileUtil
import git4idea.PlatformFacade
import git4idea.commands.Git
import git4idea.repo.GitRepository
import git4idea.repo.GitRepositoryImpl
import org.junit.After
import org.junit.Before
@@ -51,17 +53,37 @@ class GitLightTest {
}
@After
public void tearDown() {
protected void tearDown() {
FileUtil.delete(new File(myRootDir))
Disposer.dispose(myProject)
}
public void setupUsername() {
git("config user.name $USER_NAME")
git("config user.email $USER_EMAIL")
protected GitRepository createRepository(String rootDir) {
// TODO this smells hacky
// the constructor and notifyListeners() should probably be private
// getPresentableUrl should probably be final, and we should have a better VirtualFile implementation for tests.
GitRepository repository = new GitRepositoryImpl(new GitMockVirtualFile(rootDir), myPlatformFacade, myProject, myProject, true) {
@Override
protected void notifyListeners() {
}
@Override
String getPresentableUrl() {
return rootDir;
}
}
registerRepository(repository)
initRepo(rootDir)
return repository
}
public void initRepo(String repoRoot) {
private void registerRepository(GitRepositoryImpl repository) {
((GitTestRepositoryManager)myPlatformFacade.getRepositoryManager(myProject)).add(repository)
}
private void initRepo(String repoRoot) {
cd repoRoot
git("init")
setupUsername();
@@ -70,4 +92,9 @@ class GitLightTest {
git("commit -m initial")
}
private void setupUsername() {
git("config user.name $USER_NAME")
git("config user.email $USER_EMAIL")
}
}