From f53649bbc7ee0d09ee1a148f06db75efd5b293d5 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Wed, 15 Feb 2017 23:59:28 +0000 Subject: [PATCH] Convert GitTestUtil to Kotlin --- .../git4idea/cherrypick/GitCherryPickTest.kt | 2 +- .../tests/git4idea/log/GitSha1Test.kt | 2 +- .../git4idea/push/GitPushOperationBaseTest.kt | 2 +- .../push/GitPushOperationMultiRepoTest.kt | 12 +- .../push/GitPushOperationSingleRepoTest.kt | 2 +- .../git4idea/rebase/GitMultiRepoRebaseTest.kt | 2 +- .../git4idea/rebase/GitRebaseBaseTest.kt | 2 +- .../git4idea/repo/GitBareWorkTreeTest.kt | 4 +- .../repo/GitRepositoryReaderNewTest.kt | 2 +- .../git4idea/repo/GitStandardWorkTreeTest.kt | 2 +- .../git4idea/repo/GitWorkTreeBaseTest.kt | 4 +- .../tests/git4idea/test/GitPlatformTest.kt | 14 +- .../tests/git4idea/test/GitSingleRepoTest.kt | 2 +- .../tests/git4idea/test/GitTestUtil.kt | 334 ++++++++---------- .../tests/git4idea/tests/GitCommitTest.kt | 2 +- 15 files changed, 179 insertions(+), 209 deletions(-) diff --git a/plugins/git4idea/tests/git4idea/cherrypick/GitCherryPickTest.kt b/plugins/git4idea/tests/git4idea/cherrypick/GitCherryPickTest.kt index 15b81fb07e1e..97de95487e20 100644 --- a/plugins/git4idea/tests/git4idea/cherrypick/GitCherryPickTest.kt +++ b/plugins/git4idea/tests/git4idea/cherrypick/GitCherryPickTest.kt @@ -136,6 +136,6 @@ abstract class GitCherryPickTest : GitSingleRepoTest() { } private fun readFullDetails(hashes: List): List = - GitTestUtil.findGitLogProvider(myProject).readFullDetails(myProjectRoot, hashes) + findGitLogProvider(myProject).readFullDetails(myProjectRoot, hashes) } \ No newline at end of file diff --git a/plugins/git4idea/tests/git4idea/log/GitSha1Test.kt b/plugins/git4idea/tests/git4idea/log/GitSha1Test.kt index 3cfd2ee4265b..95f43bb6eb03 100644 --- a/plugins/git4idea/tests/git4idea/log/GitSha1Test.kt +++ b/plugins/git4idea/tests/git4idea/log/GitSha1Test.kt @@ -26,7 +26,7 @@ class GitSha1Test : GitSingleRepoTest() { @Throws(Exception::class) override fun setUp() { super.setUp() - GitTestUtil.createFileStructure(myProjectRoot, A_FILE) + createFileStructure(myProjectRoot, A_FILE) addCommit("initial") } diff --git a/plugins/git4idea/tests/git4idea/push/GitPushOperationBaseTest.kt b/plugins/git4idea/tests/git4idea/push/GitPushOperationBaseTest.kt index 44d494e32827..70846ef42666 100644 --- a/plugins/git4idea/tests/git4idea/push/GitPushOperationBaseTest.kt +++ b/plugins/git4idea/tests/git4idea/push/GitPushOperationBaseTest.kt @@ -53,7 +53,7 @@ abstract class GitPushOperationBaseTest : GitPlatformTest() { val parentRepo = createParentRepo(parentName) val broRepo = createBroRepo(broName, parentRepo) - val repository = GitTestUtil.createRepository(myProject, repoRoot) + val repository = createRepository(myProject, repoRoot) cd(repository) git("remote add origin " + parentRepo.path) git("push --set-upstream origin master:master") diff --git a/plugins/git4idea/tests/git4idea/push/GitPushOperationMultiRepoTest.kt b/plugins/git4idea/tests/git4idea/push/GitPushOperationMultiRepoTest.kt index b4401dddcd28..5e798d4d588e 100644 --- a/plugins/git4idea/tests/git4idea/push/GitPushOperationMultiRepoTest.kt +++ b/plugins/git4idea/tests/git4idea/push/GitPushOperationMultiRepoTest.kt @@ -20,10 +20,10 @@ import com.intellij.openapi.vcs.Executor import com.intellij.util.containers.ContainerUtil import git4idea.commands.GitCommandResult import git4idea.repo.GitRepository -import git4idea.test.GitTestUtil import git4idea.test.cd import git4idea.test.git import git4idea.test.last +import git4idea.test.makeCommit import git4idea.update.GitUpdateResult import java.io.File import java.util.* @@ -64,9 +64,9 @@ class GitPushOperationMultiRepoTest : GitPushOperationBaseTest() { } cd(myRepository) - GitTestUtil.makeCommit("file.txt") + makeCommit("file.txt") cd(myCommunity) - GitTestUtil.makeCommit("com.txt") + makeCommit("com.txt") val spec1 = makePushSpec(myRepository, "master", "origin/master") val spec2 = makePushSpec(myCommunity, "master", "origin/master") @@ -85,14 +85,14 @@ class GitPushOperationMultiRepoTest : GitPushOperationBaseTest() { fun test_update_all_roots_on_reject_when_needed_even_if_only_one_in_push_spec() { Executor.cd(myBro) - val broHash = GitTestUtil.makeCommit("bro.txt") + val broHash = makeCommit("bro.txt") git("push") Executor.cd(myBroCommunity) - val broCommunityHash = GitTestUtil.makeCommit("bro_com.txt") + val broCommunityHash = makeCommit("bro_com.txt") git("push") cd(myRepository) - GitTestUtil.makeCommit("file.txt") + makeCommit("file.txt") val mainSpec = makePushSpec(myRepository, "master", "origin/master") agreeToUpdate(GitRejectedPushUpdateDialog.MERGE_EXIT_CODE) // auto-update-all-roots is selected by default diff --git a/plugins/git4idea/tests/git4idea/push/GitPushOperationSingleRepoTest.kt b/plugins/git4idea/tests/git4idea/push/GitPushOperationSingleRepoTest.kt index 8d0f0f2d830f..372bccd90280 100644 --- a/plugins/git4idea/tests/git4idea/push/GitPushOperationSingleRepoTest.kt +++ b/plugins/git4idea/tests/git4idea/push/GitPushOperationSingleRepoTest.kt @@ -32,7 +32,7 @@ import git4idea.config.UpdateMethod import git4idea.push.GitPushRepoResult.Type.* import git4idea.repo.GitRepository import git4idea.test.* -import git4idea.test.GitTestUtil.makeCommit +import git4idea.test.makeCommit import git4idea.update.GitRebaseOverMergeProblem import git4idea.update.GitUpdateResult import java.io.File diff --git a/plugins/git4idea/tests/git4idea/rebase/GitMultiRepoRebaseTest.kt b/plugins/git4idea/tests/git4idea/rebase/GitMultiRepoRebaseTest.kt index e9e63259aca8..917355c928bc 100644 --- a/plugins/git4idea/tests/git4idea/rebase/GitMultiRepoRebaseTest.kt +++ b/plugins/git4idea/tests/git4idea/rebase/GitMultiRepoRebaseTest.kt @@ -24,8 +24,8 @@ import git4idea.branch.GitBranchUiHandler import git4idea.branch.GitBranchWorker import git4idea.branch.GitRebaseParams import git4idea.repo.GitRepository -import git4idea.test.GitTestUtil.cleanupForAssertion import git4idea.test.UNKNOWN_ERROR_TEXT +import git4idea.test.cleanupForAssertion import git4idea.test.git import org.mockito.Mockito import kotlin.properties.Delegates diff --git a/plugins/git4idea/tests/git4idea/rebase/GitRebaseBaseTest.kt b/plugins/git4idea/tests/git4idea/rebase/GitRebaseBaseTest.kt index 4bdc3d7195d4..152fa06a0cde 100644 --- a/plugins/git4idea/tests/git4idea/rebase/GitRebaseBaseTest.kt +++ b/plugins/git4idea/tests/git4idea/rebase/GitRebaseBaseTest.kt @@ -29,7 +29,7 @@ abstract class GitRebaseBaseTest : GitPlatformTest() { protected val LOCAL_CHANGES_WARNING : String = "Note that some local changes were stashed before rebase." - override fun createRepository(rootDir: String) = GitTestUtil.createRepository(myProject, rootDir, false) + override fun createRepository(rootDir: String) = createRepository(myProject, rootDir, false) override fun getDebugLogCategories() = super.getDebugLogCategories().plus("#git4idea.rebase") diff --git a/plugins/git4idea/tests/git4idea/repo/GitBareWorkTreeTest.kt b/plugins/git4idea/tests/git4idea/repo/GitBareWorkTreeTest.kt index 9415772577ef..075330a7dc01 100644 --- a/plugins/git4idea/tests/git4idea/repo/GitBareWorkTreeTest.kt +++ b/plugins/git4idea/tests/git4idea/repo/GitBareWorkTreeTest.kt @@ -15,8 +15,8 @@ */ package git4idea.repo -import git4idea.test.GitTestUtil.cloneRepo -import git4idea.test.GitTestUtil.initRepo +import git4idea.test.cloneRepo +import git4idea.test.initRepo import git4idea.test.cd import git4idea.test.tac import java.io.File diff --git a/plugins/git4idea/tests/git4idea/repo/GitRepositoryReaderNewTest.kt b/plugins/git4idea/tests/git4idea/repo/GitRepositoryReaderNewTest.kt index db9d45d65dec..12c6c79de260 100644 --- a/plugins/git4idea/tests/git4idea/repo/GitRepositoryReaderNewTest.kt +++ b/plugins/git4idea/tests/git4idea/repo/GitRepositoryReaderNewTest.kt @@ -22,7 +22,7 @@ import git4idea.branch.GitBranchUtil import git4idea.test.GitScenarios.commit import git4idea.test.GitScenarios.conflict import git4idea.test.GitSingleRepoTest -import git4idea.test.GitTestUtil.makeCommit +import git4idea.test.makeCommit import git4idea.test.git import git4idea.test.last import org.junit.Assume.assumeTrue diff --git a/plugins/git4idea/tests/git4idea/repo/GitStandardWorkTreeTest.kt b/plugins/git4idea/tests/git4idea/repo/GitStandardWorkTreeTest.kt index 44ee4f9296eb..458dfe917ced 100644 --- a/plugins/git4idea/tests/git4idea/repo/GitStandardWorkTreeTest.kt +++ b/plugins/git4idea/tests/git4idea/repo/GitStandardWorkTreeTest.kt @@ -26,7 +26,7 @@ class GitStandardWorkTreeTest : GitWorkTreeBaseTest() { val mainDir = File(myTestRoot, "main") assertTrue(mainDir.mkdir()) val path = mainDir.path - GitTestUtil.initRepo(path, true) + initRepo(path, true) return path } diff --git a/plugins/git4idea/tests/git4idea/repo/GitWorkTreeBaseTest.kt b/plugins/git4idea/tests/git4idea/repo/GitWorkTreeBaseTest.kt index 25b0badfeaf6..523d3d757fcd 100644 --- a/plugins/git4idea/tests/git4idea/repo/GitWorkTreeBaseTest.kt +++ b/plugins/git4idea/tests/git4idea/repo/GitWorkTreeBaseTest.kt @@ -21,8 +21,8 @@ import git4idea.GitUtil import git4idea.branch.GitBranchesCollection import git4idea.config.GitVersion import git4idea.test.GitPlatformTest -import git4idea.test.GitTestUtil import git4idea.test.git +import git4idea.test.registerRepo import org.junit.Assume.assumeTrue import java.io.File @@ -41,7 +41,7 @@ abstract class GitWorkTreeBaseTest : GitPlatformTest() { git("worktree add $myProjectPath") val gitDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(File(myProjectPath, GitUtil.DOT_GIT)) assertNotNull(gitDir) - myRepo = GitTestUtil.registerRepo(project, myProjectPath) + myRepo = registerRepo(project, myProjectPath) assertEquals(1, myGitRepositoryManager.repositories.size) assertNotNull(myGitRepositoryManager.getRepositoryForRoot(myProjectRoot)) } diff --git a/plugins/git4idea/tests/git4idea/test/GitPlatformTest.kt b/plugins/git4idea/tests/git4idea/test/GitPlatformTest.kt index 4a20e6a5d4bb..c9fc92dee7f3 100644 --- a/plugins/git4idea/tests/git4idea/test/GitPlatformTest.kt +++ b/plugins/git4idea/tests/git4idea/test/GitPlatformTest.kt @@ -52,14 +52,14 @@ abstract class GitPlatformTest : VcsPlatformTest() { myDialogManager = ServiceManager.getService(DialogManager::class.java) as TestDialogManager myVcsNotifier = ServiceManager.getService(myProject, VcsNotifier::class.java) as TestVcsNotifier - vcsHelper = GitTestUtil.overrideService(myProject, AbstractVcsHelper::class.java, MockVcsHelper::class.java) + vcsHelper = overrideService(myProject) myGitRepositoryManager = GitUtil.getRepositoryManager(myProject) - myGit = GitTestUtil.overrideService(Git::class.java, TestGitImpl::class.java) + myGit = overrideService() myVcs = GitVcs.getInstance(myProject)!! myVcs.doActivate() - GitTestUtil.assumeSupportedGitVersion(myVcs) + assumeSupportedGitVersion(myVcs) addSilently() removeSilently() } @@ -84,7 +84,7 @@ abstract class GitPlatformTest : VcsPlatformTest() { } protected open fun createRepository(rootDir: String): GitRepository { - return GitTestUtil.createRepository(myProject, rootDir) + return createRepository(myProject, rootDir) } /** @@ -120,7 +120,7 @@ abstract class GitPlatformTest : VcsPlatformTest() { } protected fun assertSuccessfulNotification(title: String, message: String) : Notification { - return GitTestUtil.assertNotification(NotificationType.INFORMATION, title, message, myVcsNotifier.lastNotification) + return assertNotification(NotificationType.INFORMATION, title, message, myVcsNotifier.lastNotification) } protected fun assertSuccessfulNotification(message: String) : Notification { @@ -128,13 +128,13 @@ abstract class GitPlatformTest : VcsPlatformTest() { } protected fun assertWarningNotification(title: String, message: String) { - GitTestUtil.assertNotification(NotificationType.WARNING, title, message, myVcsNotifier.lastNotification) + assertNotification(NotificationType.WARNING, title, message, myVcsNotifier.lastNotification) } protected fun assertErrorNotification(title: String, message: String) : Notification { val notification = myVcsNotifier.lastNotification assertNotNull("No notification was shown", notification) - GitTestUtil.assertNotification(NotificationType.ERROR, title, message, notification) + assertNotification(NotificationType.ERROR, title, message, notification) return notification } diff --git a/plugins/git4idea/tests/git4idea/test/GitSingleRepoTest.kt b/plugins/git4idea/tests/git4idea/test/GitSingleRepoTest.kt index 0fbdb3a30d55..4030928aaaaf 100644 --- a/plugins/git4idea/tests/git4idea/test/GitSingleRepoTest.kt +++ b/plugins/git4idea/tests/git4idea/test/GitSingleRepoTest.kt @@ -37,7 +37,7 @@ abstract class GitSingleRepoTest : GitPlatformTest() { @Throws(Exception::class) override fun setUp() { super.setUp() - myRepo = GitTestUtil.createRepository(myProject, myProjectPath, makeInitialCommit()) + myRepo = createRepository(myProject, myProjectPath, makeInitialCommit()) cd(myProjectPath) } diff --git a/plugins/git4idea/tests/git4idea/test/GitTestUtil.kt b/plugins/git4idea/tests/git4idea/test/GitTestUtil.kt index d16b88a0db01..5af8e6858b95 100644 --- a/plugins/git4idea/tests/git4idea/test/GitTestUtil.kt +++ b/plugins/git4idea/tests/git4idea/test/GitTestUtil.kt @@ -13,211 +13,181 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package git4idea.test; +@file:JvmName("GitTestUtil") -import com.intellij.notification.Notification; -import com.intellij.notification.NotificationType; -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.components.ServiceManager; -import com.intellij.openapi.extensions.Extensions; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Condition; -import com.intellij.openapi.vcs.ProjectLevelVcsManager; -import com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl; -import com.intellij.openapi.vfs.LocalFileSystem; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.containers.ContainerUtil; -import com.intellij.vcs.log.VcsLogObjectsFactory; -import com.intellij.vcs.log.VcsLogProvider; -import com.intellij.vcs.log.VcsRef; -import git4idea.GitUtil; -import git4idea.GitVcs; -import git4idea.config.GitVersion; -import git4idea.log.GitLogProvider; -import git4idea.repo.GitRepository; -import org.jetbrains.annotations.NotNull; -import org.picocontainer.MutablePicoContainer; +package git4idea.test -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; +import com.intellij.notification.Notification +import com.intellij.notification.NotificationType +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.components.service +import com.intellij.openapi.extensions.Extensions +import com.intellij.openapi.project.Project +import com.intellij.openapi.vcs.Executor.* +import com.intellij.openapi.vcs.ProjectLevelVcsManager +import com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl +import com.intellij.openapi.vfs.LocalFileSystem +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.vcs.log.VcsLogObjectsFactory +import com.intellij.vcs.log.VcsLogProvider +import com.intellij.vcs.log.VcsRef +import git4idea.GitUtil +import git4idea.GitVcs +import git4idea.log.GitLogProvider +import git4idea.repo.GitRepository +import org.junit.Assert.* +import org.junit.Assume.assumeTrue +import org.picocontainer.MutablePicoContainer +import java.io.File -import static com.intellij.openapi.util.text.StringUtil.splitByLines; -import static com.intellij.openapi.vcs.Executor.*; -import static com.intellij.openapi.vcs.Executor.cd; -import static git4idea.test.GitExecutor.*; -import static junit.framework.Assert.assertNotNull; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assume.assumeTrue; +const val USER_NAME = "John Doe" +const val USER_EMAIL = "John.Doe@example.com" -public class GitTestUtil { - - public static final String USER_NAME = "John Doe"; - public static final String USER_EMAIL = "John.Doe@example.com"; - - /** - *

Creates file structure for given paths. Path element should be a relative (from project root) - * path to a file or a directory. All intermediate paths will be created if needed. - * To create a dir without creating a file pass "dir/" as a parameter.

- *

Usage example: - * createFileStructure("a.txt", "b.txt", "dir/c.txt", "dir/subdir/d.txt", "anotherdir/");

- *

This will create files a.txt and b.txt in the project dir, create directories dir, dir/subdir and anotherdir, - * and create file c.txt in dir and d.txt in dir/subdir.

- *

Note: use forward slash to denote directories, even if it is backslash that separates dirs in your system.

- *

All files are populated with "initial content" string.

- */ - public static void createFileStructure(@NotNull VirtualFile rootDir, String... paths) { - for (String path : paths) { - cd(rootDir); - boolean dir = path.endsWith("/"); - if (dir) { - mkdir(path); - } - else { - touch(path, "initial_content_" + Math.random()); - } - } - } - - public static void initRepo(@NotNull String repoRoot, boolean makeInitialCommit) { - cd(repoRoot); - git("init"); - setupDefaultUsername(); - if (makeInitialCommit) { - touch("initial.txt"); - git("add initial.txt"); - git("commit -m initial"); - } - } - - public static void cloneRepo(@NotNull String source, @NotNull String destination, boolean bare) { - cd(source); - if (bare) { - git("clone --bare -- . " + destination); +/** + * + * Creates file structure for given paths. Path element should be a relative (from project root) + * path to a file or a directory. All intermediate paths will be created if needed. + * To create a dir without creating a file pass "dir/" as a parameter. + * + * Usage example: + * `createFileStructure("a.txt", "b.txt", "dir/c.txt", "dir/subdir/d.txt", "anotherdir/");` + * + * This will create files a.txt and b.txt in the project dir, create directories dir, dir/subdir and anotherdir, + * and create file c.txt in dir and d.txt in dir/subdir. + * + * Note: use forward slash to denote directories, even if it is backslash that separates dirs in your system. + * + * All files are populated with "initial content" string. + */ +fun createFileStructure(rootDir: VirtualFile, vararg paths: String) { + for (path in paths) { + cd(rootDir) + val dir = path.endsWith("/") + if (dir) { + mkdir(path) } else { - git("clone -- . " + destination); + touch(path, "initial_content_" + Math.random()) } } +} - public static void setupDefaultUsername() { - setupUsername(USER_NAME, USER_EMAIL); +fun initRepo(repoRoot: String, makeInitialCommit: Boolean) { + cd(repoRoot) + git("init") + setupDefaultUsername() + if (makeInitialCommit) { + touch("initial.txt") + git("add initial.txt") + git("commit -m initial") } +} - public static void setupUsername(@NotNull String name, @NotNull String email) { - assertFalse("Can not set empty user name ", name.isEmpty()); - assertFalse("Can not set empty user email ", email.isEmpty()); - git("config user.name '" + name + "'"); - git("config user.email '" + email + "'"); +fun cloneRepo(source: String, destination: String, bare: Boolean) { + cd(source) + if (bare) { + git("clone --bare -- . $destination") } + else { + git("clone -- . $destination") + } +} + +fun setupDefaultUsername() { + setupUsername(USER_NAME, USER_EMAIL) +} - /** - * Creates a Git repository in the given root directory; - * registers it in the Settings; - * return the {@link GitRepository} object for this newly created repository. - */ - @NotNull - public static GitRepository createRepository(@NotNull Project project, @NotNull String root) { - return createRepository(project, root, true); - } +fun setupUsername(name: String, email: String) { + assertFalse("Can not set empty user name ", name.isEmpty()) + assertFalse("Can not set empty user email ", email.isEmpty()) + git("config user.name '$name'") + git("config user.email '$email'") +} + +/** + * Creates a Git repository in the given root directory; + * registers it in the Settings; + * return the [GitRepository] object for this newly created repository. + */ +fun createRepository(project: Project, root: String): GitRepository { + return createRepository(project, root, true) +} - public static GitRepository createRepository(@NotNull Project project, @NotNull String root, boolean makeInitialCommit) { - initRepo(root, makeInitialCommit); - VirtualFile gitDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(root, GitUtil.DOT_GIT)); - assertNotNull(gitDir); - return registerRepo(project, root); - } +fun createRepository(project: Project, root: String, makeInitialCommit: Boolean): GitRepository { + initRepo(root, makeInitialCommit) + val gitDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(File(root, GitUtil.DOT_GIT)) + assertNotNull(gitDir) + return registerRepo(project, root) +} - @NotNull - public static GitRepository registerRepo(Project project, String root) { - ProjectLevelVcsManagerImpl vcsManager = (ProjectLevelVcsManagerImpl)ProjectLevelVcsManager.getInstance(project); - vcsManager.setDirectoryMapping(root, GitVcs.NAME); - VirtualFile file = LocalFileSystem.getInstance().findFileByIoFile(new File(root)); - assertFalse(vcsManager.getAllVcsRoots().length == 0); - GitRepository repository = GitUtil.getRepositoryManager(project).getRepositoryForRoot(file); - assertNotNull("Couldn't find repository for root " + root, repository); - return repository; - } +fun registerRepo(project: Project, root: String): GitRepository { + val vcsManager = ProjectLevelVcsManager.getInstance(project) as ProjectLevelVcsManagerImpl + vcsManager.setDirectoryMapping(root, GitVcs.NAME) + val file = LocalFileSystem.getInstance().findFileByIoFile(File(root)) + assertFalse(vcsManager.allVcsRoots.isEmpty()) + val repository = GitUtil.getRepositoryManager(project).getRepositoryForRoot(file) + assertNotNull("Couldn't find repository for root " + root, repository) + return repository!! +} - public static void assumeSupportedGitVersion(@NotNull GitVcs vcs) { - GitVersion version = vcs.getVersion(); - assumeTrue("Unsupported Git version: " + version, version.isSupported()); - } +fun assumeSupportedGitVersion(vcs: GitVcs) { + val version = vcs.version + assumeTrue("Unsupported Git version: " + version, version.isSupported) +} - @SuppressWarnings("unchecked") - @NotNull - public static T overrideService(@NotNull Project project, Class serviceInterface, Class serviceImplementation) { - String key = serviceInterface.getName(); - MutablePicoContainer picoContainer = (MutablePicoContainer) project.getPicoContainer(); - picoContainer.unregisterComponent(key); - picoContainer.registerComponentImplementation(key, serviceImplementation); - return (T) ServiceManager.getService(project, serviceInterface); - } +inline fun overrideService(project: Project): Impl { + val key = Int::class.java.name + val picoContainer = project.picoContainer as MutablePicoContainer + picoContainer.unregisterComponent(key) + picoContainer.registerComponentImplementation(key, Impl::class.java) + return project.service() as Impl +} - @SuppressWarnings("unchecked") - @NotNull - public static T overrideService(Class serviceInterface, Class serviceImplementation) { - String key = serviceInterface.getName(); - MutablePicoContainer picoContainer = (MutablePicoContainer) ApplicationManager.getApplication().getPicoContainer(); - picoContainer.unregisterComponent(key); - picoContainer.registerComponentImplementation(key, serviceImplementation); - return (T) ServiceManager.getService(serviceInterface); - } +inline fun overrideService(): Impl { + val key = Int::class.java.name + val picoContainer = ApplicationManager.getApplication().picoContainer as MutablePicoContainer + picoContainer.unregisterComponent(key) + picoContainer.registerComponentImplementation(key, Impl::class.java) + return service() as Impl +} - @NotNull - public static Set readAllRefs(@NotNull VirtualFile root, @NotNull VcsLogObjectsFactory objectsFactory) { - String[] refs = splitByLines(git("log --branches --tags --no-walk --format=%H%d --decorate=full")); - Set result = ContainerUtil.newHashSet(); - for (String ref : refs) { - result.addAll(new RefParser(objectsFactory).parseCommitRefs(ref, root)); - } - return result; +fun readAllRefs(root: VirtualFile, objectsFactory: VcsLogObjectsFactory): Set { + val refs = git("log --branches --tags --no-walk --format=%H%d --decorate=full").lines() + val result = mutableSetOf() + for (ref in refs) { + result.addAll(RefParser(objectsFactory).parseCommitRefs(ref, root)) } + return result +} - @NotNull - public static String makeCommit(String file) throws IOException { - append(file, "some content"); - addCommit("some message"); - return last(); - } +fun makeCommit(file: String): String { + append(file, "some content") + addCommit("some message") + return last() +} - public static Notification assertNotification(@NotNull NotificationType type, - @NotNull String title, - @NotNull String content, - @NotNull Notification actual) { - assertEquals("Incorrect notification type: " + tos(actual), type, actual.getType()); - assertEquals("Incorrect notification title: " + tos(actual), title, actual.getTitle()); - assertEquals("Incorrect notification content: " + tos(actual), cleanupForAssertion(content), cleanupForAssertion(actual.getContent())); - return actual; - } +fun assertNotification(type: NotificationType, title: String, content: String, actual: Notification): Notification { + assertEquals("Incorrect notification type: " + tos(actual), type, actual.type) + assertEquals("Incorrect notification title: " + tos(actual), title, actual.title) + assertEquals("Incorrect notification content: " + tos(actual), cleanupForAssertion(content), cleanupForAssertion(actual.content)) + return actual +} - @NotNull - public static String cleanupForAssertion(@NotNull String content) { - String nobr = content.replace("
", "\n").replace("
", "\n"); - return Arrays.stream(splitByLines(nobr)) - .map(line -> line.replaceAll(" href='[^']*'", "").trim()) - .filter(line -> !line.isEmpty()) - .collect(Collectors.joining(" ")); - } +fun cleanupForAssertion(content: String): String { + val nobr = content.replace("
", "\n").replace("
", "\n") + return nobr.lines() + .map { line -> line.replace(" href='[^']*'".toRegex(), "").trim({ it <= ' ' }) } + .filter { line -> !line.isEmpty() } + .joinToString(" ") +} - @NotNull - private static String tos(@NotNull Notification notification) { - return notification.getTitle() + "|" + notification.getContent(); - } +private fun tos(notification: Notification): String { + return "${notification.title}|${notification.content}" +} - public static GitLogProvider findGitLogProvider(@NotNull Project project) { - List providers = - ContainerUtil.filter(Extensions.getExtensions(VcsLogProvider.LOG_PROVIDER_EP, project), new Condition() { - @Override - public boolean value(VcsLogProvider provider) { - return provider.getSupportedVcs().equals(GitVcs.getKey()); - } - }); - assertEquals("Incorrect number of GitLogProviders", 1, providers.size()); - return (GitLogProvider)providers.get(0); - } +fun findGitLogProvider(project: Project): GitLogProvider { + val providers = Extensions.getExtensions(VcsLogProvider.LOG_PROVIDER_EP, project) + .filter { provider -> provider.supportedVcs == GitVcs.getKey() } + assertEquals("Incorrect number of GitLogProviders", 1, providers.size) + return providers[0] as GitLogProvider } diff --git a/plugins/git4idea/tests/git4idea/tests/GitCommitTest.kt b/plugins/git4idea/tests/git4idea/tests/GitCommitTest.kt index de45df74a654..5bee825614eb 100644 --- a/plugins/git4idea/tests/git4idea/tests/GitCommitTest.kt +++ b/plugins/git4idea/tests/git4idea/tests/GitCommitTest.kt @@ -26,7 +26,7 @@ import git4idea.changes.GitChangeUtils import git4idea.checkin.GitCheckinEnvironment import git4idea.history.GitHistoryUtils import git4idea.test.* -import git4idea.test.GitTestUtil.createFileStructure +import git4idea.test.createFileStructure import java.io.File import java.util.*