From 3af429b5376843947b61d284ea9f51cdae1721fe Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Mon, 15 Oct 2012 15:21:03 +0400 Subject: [PATCH] [git tests] Extract repository creation to GitLightTest. Use in GitBranchWorkerTest --- .../branch/GitBranchWorkerTest.groovy | 28 +++----------- .../tests/git4idea/test/GitLightTest.groovy | 37 ++++++++++++++++--- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/plugins/git4idea/tests/git4idea/branch/GitBranchWorkerTest.groovy b/plugins/git4idea/tests/git4idea/branch/GitBranchWorkerTest.groovy index ca8bce6a59d4..a4c60393efcb 100644 --- a/plugins/git4idea/tests/git4idea/branch/GitBranchWorkerTest.groovy +++ b/plugins/git4idea/tests/git4idea/branch/GitBranchWorkerTest.groovy @@ -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 diff --git a/plugins/git4idea/tests/git4idea/test/GitLightTest.groovy b/plugins/git4idea/tests/git4idea/test/GitLightTest.groovy index 29b8aa2b3ff9..94aea7cc6d87 100644 --- a/plugins/git4idea/tests/git4idea/test/GitLightTest.groovy +++ b/plugins/git4idea/tests/git4idea/test/GitLightTest.groovy @@ -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") + } + }