mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
avoid static members usage in tests —GitTest doesn't use application level icsManager anymore
This commit is contained in:
@@ -16,10 +16,17 @@
|
||||
package com.intellij.testFramework
|
||||
|
||||
import com.intellij.openapi.application.invokeAndWaitIfNeed
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
|
||||
import org.junit.rules.ExternalResource
|
||||
|
||||
public class FixtureRule() : ExternalResource() {
|
||||
companion object {
|
||||
init {
|
||||
Logger.setFactory(javaClass<TestLoggerFactory>())
|
||||
}
|
||||
}
|
||||
|
||||
val projectFixture = IdeaTestFixtureFactory.getFixtureFactory().createLightFixtureBuilder().getFixture()
|
||||
|
||||
override fun before() {
|
||||
|
||||
@@ -84,7 +84,7 @@ class IcsManager(dir: File) {
|
||||
|
||||
val readOnlySourcesManager = ReadOnlySourcesManager(settings, dir)
|
||||
|
||||
public val repositoryService: RepositoryService = GitRepositoryService()
|
||||
val repositoryService: RepositoryService = GitRepositoryService()
|
||||
|
||||
private val commitAlarm = SingleAlarm(object : Runnable {
|
||||
override fun run() {
|
||||
@@ -238,19 +238,27 @@ class IcsManager(dir: File) {
|
||||
}
|
||||
|
||||
class IcsApplicationLoadListener : ApplicationLoadListener {
|
||||
private val pluginSystemDir = getPluginSystemDir()
|
||||
|
||||
val icsManager = IcsManager(pluginSystemDir)
|
||||
var icsManager: IcsManager by Delegates.notNull()
|
||||
private set
|
||||
|
||||
override fun beforeApplicationLoaded(application: Application) {
|
||||
try {
|
||||
val oldPluginDir = File(PathManager.getSystemPath(), "settingsRepository")
|
||||
if (oldPluginDir.exists() && !pluginSystemDir.exists()) {
|
||||
FileUtil.rename(oldPluginDir, pluginSystemDir)
|
||||
}
|
||||
if (application.isUnitTestMode()) {
|
||||
return
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
LOG.error(e)
|
||||
|
||||
val pluginSystemDir = getPluginSystemDir()
|
||||
icsManager = IcsManager(pluginSystemDir)
|
||||
|
||||
if (!pluginSystemDir.exists()) {
|
||||
try {
|
||||
val oldPluginDir = File(PathManager.getSystemPath(), "settingsRepository")
|
||||
if (oldPluginDir.exists()) {
|
||||
FileUtil.rename(oldPluginDir, pluginSystemDir)
|
||||
}
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
LOG.error(e)
|
||||
}
|
||||
}
|
||||
|
||||
icsManager.beforeApplicationLoaded(application)
|
||||
|
||||
@@ -16,21 +16,15 @@
|
||||
package org.jetbrains.settingsRepository.test
|
||||
|
||||
import com.intellij.mock.MockVirtualFileSystem
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.application.impl.ApplicationImpl
|
||||
import com.intellij.openapi.components.RoamingType
|
||||
import com.intellij.openapi.components.impl.stores.StreamProvider
|
||||
import com.intellij.openapi.progress.EmptyProgressIndicator
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.util.io.FileUtilRt
|
||||
import com.intellij.openapi.vfs.CharsetToolkit
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.util.PathUtilRt
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.lib.Repository
|
||||
import org.hamcrest.CoreMatchers
|
||||
import org.hamcrest.CoreMatchers.equalTo
|
||||
import org.hamcrest.Matchers
|
||||
import org.hamcrest.Matchers.contains
|
||||
import org.hamcrest.Matchers.empty
|
||||
import org.jetbrains.jgit.dirCache.AddFile
|
||||
@@ -38,53 +32,27 @@ import org.jetbrains.jgit.dirCache.deletePath
|
||||
import org.jetbrains.jgit.dirCache.edit
|
||||
import org.jetbrains.jgit.dirCache.writePath
|
||||
import org.jetbrains.settingsRepository.AM
|
||||
import org.jetbrains.settingsRepository.IcsManager
|
||||
import org.jetbrains.settingsRepository.SyncType
|
||||
import org.jetbrains.settingsRepository.git.GitRepositoryManager
|
||||
import org.jetbrains.settingsRepository.git.commit
|
||||
import org.jetbrains.settingsRepository.git.computeIndexDiff
|
||||
import org.jetbrains.settingsRepository.git.resetHard
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertThat
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import javax.swing.SwingUtilities
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
class GitTest : TestCase() {
|
||||
companion object {
|
||||
private var ICS_DIR: File? = null
|
||||
|
||||
// BeforeClass doesn't work in Kotlin
|
||||
public fun setIcsDir() {
|
||||
val icsDirPath = System.getProperty("ics.settingsRepository")
|
||||
if (icsDirPath == null) {
|
||||
// we must not create file (i.e. this file doesn't exist)
|
||||
ICS_DIR = FileUtilRt.generateRandomTemporaryPath()
|
||||
System.setProperty("ics.settingsRepository", ICS_DIR!!.getAbsolutePath())
|
||||
}
|
||||
else {
|
||||
ICS_DIR = File(FileUtil.expandUserHome(icsDirPath))
|
||||
FileUtil.delete(ICS_DIR!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override val icsManager: IcsManager
|
||||
get() = org.jetbrains.settingsRepository.icsManager
|
||||
|
||||
private val repositoryManager: GitRepositoryManager
|
||||
get() = icsManager.repositoryManager as GitRepositoryManager
|
||||
|
||||
private val repository: Repository
|
||||
get() = repositoryManager.repository
|
||||
|
||||
private val provider: StreamProvider
|
||||
get() {
|
||||
val provider = (ApplicationManager.getApplication() as ApplicationImpl).getStateStore().getStateStorageManager().getStreamProvider()
|
||||
assertThat(provider, CoreMatchers.notNullValue())
|
||||
return provider!!
|
||||
}
|
||||
val remoteRepository by Delegates.lazy {
|
||||
tempDirManager.createRepository("upstream")
|
||||
}
|
||||
|
||||
private fun delete(data: ByteArray, directory: Boolean) {
|
||||
val addedFile = "\$APP_CONFIG$/remote.xml"
|
||||
@@ -92,13 +60,13 @@ class GitTest : TestCase() {
|
||||
provider.delete(if (directory) "\$APP_CONFIG$" else addedFile, RoamingType.PER_USER)
|
||||
|
||||
val diff = repository.computeIndexDiff()
|
||||
assertThat(diff.diff(), CoreMatchers.equalTo(false))
|
||||
assertThat(diff.getAdded(), Matchers.empty())
|
||||
assertThat(diff.getChanged(), Matchers.empty())
|
||||
assertThat(diff.getRemoved(), Matchers.empty())
|
||||
assertThat(diff.getModified(), Matchers.empty())
|
||||
assertThat(diff.getUntracked(), Matchers.empty())
|
||||
assertThat(diff.getUntrackedFolders(), Matchers.empty())
|
||||
assertThat(diff.diff(), equalTo(false))
|
||||
assertThat(diff.getAdded(), empty())
|
||||
assertThat(diff.getChanged(), empty())
|
||||
assertThat(diff.getRemoved(), empty())
|
||||
assertThat(diff.getModified(), empty())
|
||||
assertThat(diff.getUntracked(), empty())
|
||||
assertThat(diff.getUntrackedFolders(), empty())
|
||||
}
|
||||
|
||||
private fun addAndCommit(path: String): FileInfo {
|
||||
@@ -108,22 +76,6 @@ class GitTest : TestCase() {
|
||||
return FileInfo(path, data)
|
||||
}
|
||||
|
||||
Before
|
||||
public fun setUp() {
|
||||
if (ICS_DIR == null) {
|
||||
setIcsDir()
|
||||
}
|
||||
|
||||
(icsManager.repositoryManager as GitRepositoryManager).createRepositoryIfNeed()
|
||||
icsManager.repositoryActive = true
|
||||
}
|
||||
|
||||
After
|
||||
public fun tearDown() {
|
||||
icsManager.repositoryActive = false
|
||||
repositoryManager.deleteRepository()
|
||||
}
|
||||
|
||||
public Test fun add() {
|
||||
val data = FileUtil.loadFileBytes(File(testDataPath, "remote.xml"))
|
||||
val addedFile = "\$APP_CONFIG$/remote.xml"
|
||||
@@ -308,7 +260,6 @@ class GitTest : TestCase() {
|
||||
provider.save("\$APP_CONFIG$/remote.xml", data)
|
||||
repositoryManager.commit(EmptyProgressIndicator())
|
||||
|
||||
val remoteRepository = testHelper.repository!!
|
||||
remoteRepository.deletePath("\$APP_CONFIG$/remote.xml")
|
||||
remoteRepository.commit("delete remote.xml")
|
||||
|
||||
@@ -325,7 +276,6 @@ class GitTest : TestCase() {
|
||||
provider.delete("\$APP_CONFIG$/remote.xml", RoamingType.PER_USER)
|
||||
repositoryManager.commit(EmptyProgressIndicator())
|
||||
|
||||
val remoteRepository = testHelper.repository!!
|
||||
remoteRepository.writePath("\$APP_CONFIG$/remote.xml", AM.MARKER_ACCEPT_THEIRS)
|
||||
remoteRepository.commit("")
|
||||
|
||||
@@ -362,7 +312,7 @@ class GitTest : TestCase() {
|
||||
}
|
||||
|
||||
fun getRemoteRepository(branchName: String? = null): Repository {
|
||||
val repository = testHelper.getRepository(ICS_DIR!!)
|
||||
val repository = remoteRepository
|
||||
if (branchName != null) {
|
||||
// jgit cannot checkout&create branch if no HEAD (no commits in our empty repository), so we create initial empty commit
|
||||
repository.commit("")
|
||||
@@ -398,7 +348,7 @@ class GitTest : TestCase() {
|
||||
"
|
||||
so, we do "git reset --hard"
|
||||
*/
|
||||
testHelper.repository!!.resetHard()
|
||||
remoteRepository.resetHard()
|
||||
}
|
||||
|
||||
private fun sync(syncType: SyncType) {
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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 org.jetbrains.settingsRepository.test
|
||||
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.Suite
|
||||
|
||||
RunWith(Suite::class)
|
||||
Suite.SuiteClasses(GitTest::class, BareGitTest::class, LoadTest::class)
|
||||
class IcsTestSuite
|
||||
@@ -29,13 +29,10 @@ import org.jetbrains.settingsRepository.git.commit
|
||||
import org.junit.Assert.assertThat
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
class LoadTest : TestCase() {
|
||||
private val dirPath = "\$ROOT_CONFIG$/keymaps"
|
||||
|
||||
val provider by Delegates.lazy { icsManager.ApplicationLevelProvider() }
|
||||
|
||||
private fun createSchemeManager(dirPath: String) = SchemeManagerImpl<TestScheme, TestScheme>(dirPath, TestSchemesProcessor(), RoamingType.PER_USER, provider, tempDirManager.newDirectory("schemes"))
|
||||
|
||||
public Test fun `load scheme`() {
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* 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 org.jetbrains.settingsRepository.test
|
||||
|
||||
import com.intellij.mock.MockVirtualFileSystem
|
||||
@@ -5,36 +20,12 @@ import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.util.ArrayUtil
|
||||
import org.eclipse.jgit.lib.Constants
|
||||
import org.eclipse.jgit.lib.Repository
|
||||
import org.hamcrest.CoreMatchers.equalTo
|
||||
import org.jetbrains.settingsRepository.git.createRepository
|
||||
import org.junit.Assert.assertThat
|
||||
import org.junit.rules.TestName
|
||||
import org.junit.runner.Description
|
||||
import java.io.File
|
||||
import java.util.Arrays
|
||||
import java.util.Comparator
|
||||
|
||||
class RespositoryHelper : TestName() {
|
||||
var repository: Repository? = null
|
||||
|
||||
public fun getRepository(baseDir: File): Repository {
|
||||
if (repository == null) {
|
||||
repository = createRepository(File(baseDir, "upstream"))
|
||||
}
|
||||
return repository!!
|
||||
}
|
||||
|
||||
override fun finished(description: Description) {
|
||||
super.finished(description)
|
||||
|
||||
if (repository != null) {
|
||||
FileUtil.delete(repository!!.getWorkTree())
|
||||
repository = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class FileInfo(val name: String, val data: ByteArray)
|
||||
|
||||
fun fs(vararg paths: String): MockVirtualFileSystem {
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package org.jetbrains.settingsRepository.test
|
||||
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.Suite
|
||||
|
||||
RunWith(Suite::class)
|
||||
Suite.SuiteClasses(GitTest::class, BareGitTest::class, LoadTest::class)
|
||||
class SettingsRepositoryTestSuite
|
||||
@@ -17,12 +17,10 @@ package org.jetbrains.settingsRepository.test
|
||||
|
||||
import com.intellij.openapi.components.RoamingType
|
||||
import com.intellij.openapi.components.impl.stores.StreamProvider
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.testFramework.FixtureRule
|
||||
import com.intellij.testFramework.PlatformTestUtil
|
||||
import com.intellij.testFramework.TemporaryDirectory
|
||||
import com.intellij.testFramework.TestLoggerFactory
|
||||
import org.eclipse.jgit.lib.Repository
|
||||
import org.jetbrains.jgit.dirCache.AddFile
|
||||
import org.jetbrains.jgit.dirCache.edit
|
||||
@@ -53,26 +51,14 @@ abstract class TestCase {
|
||||
|
||||
public Rule fun getFixtureRule(): TestRule = fixtureManager
|
||||
|
||||
val testHelper = RespositoryHelper()
|
||||
|
||||
open val icsManager by Delegates.lazy {
|
||||
val icsManager by Delegates.lazy {
|
||||
val icsManager = IcsManager(tempDirManager.newDirectory())
|
||||
icsManager.repositoryManager.createRepositoryIfNeed()
|
||||
icsManager.repositoryActive = true
|
||||
icsManager
|
||||
}
|
||||
|
||||
Rule
|
||||
public fun getTestWatcher(): RespositoryHelper = testHelper
|
||||
|
||||
val remoteRepository: Repository
|
||||
get() = testHelper.repository!!
|
||||
|
||||
companion object {
|
||||
init {
|
||||
Logger.setFactory(javaClass<TestLoggerFactory>())
|
||||
}
|
||||
}
|
||||
val provider by Delegates.lazy { icsManager.ApplicationLevelProvider() }
|
||||
}
|
||||
|
||||
fun TemporaryDirectory.createRepository(directoryName: String? = null) = git.createRepository(newDirectory(directoryName))
|
||||
|
||||
Reference in New Issue
Block a user