This commit is contained in:
Vladimir Krivosheev
2015-08-25 17:11:37 +02:00
parent 3b04b8a71c
commit 54e82b7a2b
6 changed files with 23 additions and 48 deletions
@@ -33,8 +33,6 @@ import com.intellij.openapi.vfs.impl.VirtualFilePointerManagerImpl
import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS
import com.intellij.openapi.vfs.newvfs.persistent.PersistentFSImpl
import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory
import com.intellij.util.SmartList
import com.intellij.util.lang.CompoundRuntimeException
import org.junit.rules.ExternalResource
@@ -148,35 +146,6 @@ public fun runInEdtAndWait(runnable: () -> Unit) {
EdtTestUtil.runInEdtAndWait(runnable)
}
public open class FixtureRule() : ExternalResource() {
companion object {
init {
Logger.setFactory(javaClass<TestLoggerFactory>())
}
}
protected var _projectFixture: IdeaProjectTestFixture? = null
public val projectFixture: IdeaProjectTestFixture
get() = _projectFixture!!
open fun createBuilder() = IdeaTestFixtureFactory.getFixtureFactory().createLightFixtureBuilder()
override final fun before() {
val builder = createBuilder()
if (_projectFixture == null) {
_projectFixture = builder.getFixture()
}
TestRunnerUtil.replaceIdeEventQueueSafely()
runInEdtAndWait { projectFixture.setUp() }
}
override final fun after() {
runInEdtAndWait { projectFixture.tearDown() }
}
}
public class RuleChain(vararg val rules: TestRule) : TestRule {
override fun apply(base: Statement, description: Description): Statement {
var statement = base
@@ -151,7 +151,7 @@ class IcsManager(dir: File) {
}
}
fun sync(syncType: SyncType, project: Project?, localRepositoryInitializer: (() -> Unit)? = null) = syncManager.sync(syncType, project, localRepositoryInitializer)
fun sync(syncType: SyncType, project: Project? = null, localRepositoryInitializer: (() -> Unit)? = null) = syncManager.sync(syncType, project, localRepositoryInitializer)
private fun cancelAndDisableAutoCommit() {
if (autoCommitEnabled) {
+1 -1
View File
@@ -37,7 +37,7 @@ class SyncManager(private val icsManager: IcsManager, private val autoSyncManage
volatile var writeAndDeleteProhibited = false
private set
public fun sync(syncType: SyncType, project: Project?, localRepositoryInitializer: (() -> Unit)? = null): UpdateResult? {
public fun sync(syncType: SyncType, project: Project? = null, localRepositoryInitializer: (() -> Unit)? = null): UpdateResult? {
var exception: Throwable? = null
var restartApplication = false
var updateResult: UpdateResult? = null
@@ -21,6 +21,7 @@ import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.vcs.merge.MergeSession
import com.intellij.openapi.vfs.CharsetToolkit
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.testFramework.ProjectRule
import com.intellij.testFramework.path
import com.intellij.util.PathUtilRt
import org.assertj.core.api.Assertions.assertThat
@@ -37,6 +38,7 @@ 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.ClassRule
import org.junit.Test
import java.io.File
import java.util.Arrays
@@ -48,7 +50,11 @@ object AM {
val MARKER_ACCEPT_THEIRS: ByteArray = "__accept theirs__".toByteArray()
}
class GitTest : TestCase() {
class GitTest : IcsTestCase() {
companion object {
@ClassRule val projectRule = ProjectRule()
}
private val repositoryManager: GitRepositoryManager
get() = icsManager.repositoryManager as GitRepositoryManager
@@ -403,6 +409,6 @@ class GitTest : TestCase() {
}
private fun sync(syncType: SyncType) {
icsManager.sync(syncType, fixtureManager.projectFixture.getProject())
icsManager.sync(syncType)
}
}
@@ -18,7 +18,6 @@ package org.jetbrains.settingsRepository.test
import com.intellij.openapi.components.RoamingType
import com.intellij.openapi.components.impl.stores.StreamProvider
import com.intellij.openapi.util.io.FileUtil
import com.intellij.testFramework.FixtureRule
import com.intellij.testFramework.PlatformTestUtil
import com.intellij.testFramework.TemporaryDirectory
import org.eclipse.jgit.lib.Repository
@@ -27,7 +26,6 @@ import org.jetbrains.jgit.dirCache.edit
import org.jetbrains.settingsRepository.IcsManager
import org.jetbrains.settingsRepository.git
import org.junit.Rule
import org.junit.rules.TestRule
import java.io.File
import kotlin.properties.Delegates
@@ -48,13 +46,9 @@ fun Repository.add(data: ByteArray, path: String): Repository {
return this
}
abstract class TestCase {
val fixtureManager = FixtureRule()
abstract class IcsTestCase {
val tempDirManager = TemporaryDirectory()
public Rule fun getTemporaryFolder(): TemporaryDirectory = tempDirManager
public Rule fun getFixtureRule(): TestRule = fixtureManager
@Rule fun getTemporaryFolder() = tempDirManager
val icsManager by Delegates.lazy {
val icsManager = IcsManager(tempDirManager.newDirectory())
@@ -19,6 +19,7 @@ import com.intellij.configurationStore.SchemeManagerImpl
import com.intellij.configurationStore.TestScheme
import com.intellij.configurationStore.TestSchemesProcessor
import com.intellij.openapi.components.RoamingType
import com.intellij.testFramework.ProjectRule
import com.intellij.util.xmlb.serialize
import com.intellij.util.xmlb.toByteArray
import org.assertj.core.api.Assertions.assertThat
@@ -26,15 +27,20 @@ import org.eclipse.jgit.lib.Repository
import org.jetbrains.settingsRepository.ReadonlySource
import org.jetbrains.settingsRepository.git.cloneBare
import org.jetbrains.settingsRepository.git.commit
import org.junit.ClassRule
import org.junit.Test
import java.io.File
class LoadTest : TestCase() {
class LoadTest : IcsTestCase() {
companion object {
@ClassRule val projectRule = ProjectRule()
}
private val dirPath = "\$ROOT_CONFIG$/keymaps"
private fun createSchemeManager(dirPath: String) = SchemeManagerImpl<TestScheme, TestScheme>(dirPath, TestSchemesProcessor(), RoamingType.PER_USER, provider, tempDirManager.newDirectory("schemes"))
public Test fun `load scheme`() {
@Test fun `load scheme`() {
val localScheme = TestScheme("local")
val data = localScheme.serialize().toByteArray()
provider.write("$dirPath/local.xml", data)
@@ -44,7 +50,7 @@ class LoadTest : TestCase() {
assertThat(schemesManager.getAllSchemes()).containsOnly(localScheme)
}
public Test fun `load scheme with the same names`() {
@Test fun `load scheme with the same names`() {
val localScheme = TestScheme("local")
val data = localScheme.serialize().toByteArray()
provider.write("$dirPath/local.xml", data)
@@ -55,7 +61,7 @@ class LoadTest : TestCase() {
assertThat(schemesManager.getAllSchemes()).containsOnly(localScheme)
}
public Test fun `load scheme from repo and read-only repo`() {
@Test fun `load scheme from repo and read-only repo`() {
val localScheme = TestScheme("local")
provider.write("$dirPath/local.xml", localScheme.serialize().toByteArray())
@@ -75,7 +81,7 @@ class LoadTest : TestCase() {
}
}
public Test fun `scheme overrides read-only`() {
@Test fun `scheme overrides read-only`() {
val schemeName = "Emacs"
val localScheme = TestScheme(schemeName, "local")