<commit_before>/*
 * Copyright 2000-2015 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package git4idea.test

import com.intellij.notification.Notification
import com.intellij.notification.NotificationType
import com.intellij.openapi.components.service
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.vcs.*
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.testFramework.vcs.AbstractVcsTestCase
import com.intellij.vcs.test.VcsPlatformTest
import git4idea.DialogManager
import git4idea.GitUtil
import git4idea.GitVcs
import git4idea.commands.Git
import git4idea.commands.GitHandler
import git4idea.config.GitVcsSettings
import git4idea.repo.GitRepository
import git4idea.repo.GitRepositoryManager
import java.io.File

abstract class GitPlatformTest : VcsPlatformTest() {

  protected lateinit var myGitRepositoryManager: GitRepositoryManager
  protected lateinit var myGitSettings: GitVcsSettings
  protected lateinit var myGit: TestGitImpl
  protected lateinit var myVcs: GitVcs
  protected lateinit var myDialogManager: TestDialogManager
  protected lateinit var myVcsNotifier: TestVcsNotifier
  protected lateinit var vcsHelper: MockVcsHelper

  @Throws(Exception::class)
  override fun setUp() {
    super.setUp()

    myGitSettings = GitVcsSettings.getInstance(myProject)
    myGitSettings.appSettings.setPathToGit(gitExecutable())

    myDialogManager = service<DialogManager>() as TestDialogManager
    myVcsNotifier = myProject.service<VcsNotifier>() as TestVcsNotifier

    vcsHelper = overrideService<AbstractVcsHelper, MockVcsHelper>(myProject)

    myGitRepositoryManager = GitUtil.getRepositoryManager(myProject)
    myGit = overrideService<Git, TestGitImpl>()
    myVcs = GitVcs.getInstance(myProject)!!
    myVcs.doActivate()

    assumeSupportedGitVersion(myVcs)
    addSilently()
    removeSilently()
  }

  @Throws(Exception::class)
  override fun tearDown() {
    try {
      if (wasInit { myDialogManager }) { myDialogManager.cleanup() }
      if (wasInit { myVcsNotifier }) { myVcsNotifier.cleanup() }
      myGit.reset()
      myGitSettings.appSettings.setPathToGit(null)<commit_msg>Teardown lateinit property only if it was initialized<commit_after>/*
 * Copyright 2000-2015 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package git4idea.test

import com.intellij.notification.Notification
import com.intellij.notification.NotificationType
import com.intellij.openapi.components.service
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.vcs.*
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.testFramework.vcs.AbstractVcsTestCase
import com.intellij.vcs.test.VcsPlatformTest
import git4idea.DialogManager
import git4idea.GitUtil
import git4idea.GitVcs
import git4idea.commands.Git
import git4idea.commands.GitHandler
import git4idea.config.GitVcsSettings
import git4idea.repo.GitRepository
import git4idea.repo.GitRepositoryManager
import java.io.File

abstract class GitPlatformTest : VcsPlatformTest() {

  protected lateinit var myGitRepositoryManager: GitRepositoryManager
  protected lateinit var myGitSettings: GitVcsSettings
  protected lateinit var myGit: TestGitImpl
  protected lateinit var myVcs: GitVcs
  protected lateinit var myDialogManager: TestDialogManager
  protected lateinit var myVcsNotifier: TestVcsNotifier
  protected lateinit var vcsHelper: MockVcsHelper

  @Throws(Exception::class)
  override fun setUp() {
    super.setUp()

    myGitSettings = GitVcsSettings.getInstance(myProject)
    myGitSettings.appSettings.setPathToGit(gitExecutable())

    myDialogManager = service<DialogManager>() as TestDialogManager
    myVcsNotifier = myProject.service<VcsNotifier>() as TestVcsNotifier

    vcsHelper = overrideService<AbstractVcsHelper, MockVcsHelper>(myProject)

    myGitRepositoryManager = GitUtil.getRepositoryManager(myProject)
    myGit = overrideService<Git, TestGitImpl>()
    myVcs = GitVcs.getInstance(myProject)!!
    myVcs.doActivate()

    assumeSupportedGitVersion(myVcs)
    addSilently()
    removeSilently()
  }

  @Throws(Exception::class)
  override fun tearDown() {
    try {
      if (wasInit { myDialogManager }) { myDialogManager.cleanup() }
      if (wasInit { myVcsNotifier }) { myVcsNotifier.cleanup() }
      if (wasInit {myGit}) { myGit.reset() }
      if (wasInit {myGitSettings}) { myGitSettings.appSettings.setPathToGit(null) }
{'fraction_non_alphanumeric': 0.0775165319617928, 'fraction_numerical': 0.007714915503306392, 'mean_word_length': 5.023230088495575, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7554761', 'n_tokens_mistral': 1646, 'n_tokens_neox': 1568, 'n_words': 418}