Update AndroidTestCase to AS 2.3 + Android tests refactoring
This commit is contained in:
+2
-7
@@ -43,19 +43,14 @@ abstract class AbstractAndroidCompletionTest : KotlinAndroidTestCase() {
|
||||
|
||||
private fun completionType() = CompletionType.BASIC
|
||||
|
||||
fun doTest(path: String?) {
|
||||
getResourceDirs(path).forEach { myFixture.copyDirectoryToProject(it.name, it.name) }
|
||||
fun doTest(path: String) {
|
||||
copyResourceDirectoryForTest(path)
|
||||
val virtualFile = myFixture.copyFileToProject(path + getTestName(true) + ".kt", "src/" + getTestName(true) + ".kt")
|
||||
myFixture.configureFromExistingVirtualFile(virtualFile)
|
||||
val fileText = FileUtil.loadFile(File(path + getTestName(true) + ".kt"), true)
|
||||
testCompletion(fileText, JvmPlatform, { completionType, count -> myFixture.complete(completionType, count) })
|
||||
}
|
||||
|
||||
|
||||
override fun getTestDataPath(): String {
|
||||
return KotlinAndroidTestCaseBase.getPluginTestDataPathBase() + "/completion/" + getTestName(true) + "/"
|
||||
}
|
||||
|
||||
override fun tearDown() {
|
||||
val settings = CodeInsightSettings.getInstance()
|
||||
settings.AUTOCOMPLETE_ON_CODE_COMPLETION = codeCompletionOldValue
|
||||
|
||||
+6
-15
@@ -16,26 +16,17 @@
|
||||
|
||||
package org.jetbrains.kotlin.android
|
||||
|
||||
import com.intellij.codeInsight.TargetElementUtil
|
||||
|
||||
abstract class AbstractAndroidFindUsagesTest : KotlinAndroidTestCase() {
|
||||
|
||||
override fun getTestDataPath() = KotlinAndroidTestCaseBase.getPluginTestDataPathBase() + "/findUsages/" + getTestName(true) + "/"
|
||||
|
||||
fun doTest(path: String) {
|
||||
if (true) return // Muted (actually works in IDEA)
|
||||
|
||||
val f = myFixture!!
|
||||
getResourceDirs(path).forEach { myFixture.copyDirectoryToProject(it.name, it.name) }
|
||||
val virtualFile = f.copyFileToProject(path + getTestName(true) + ".kt", "src/" + getTestName(true) + ".kt")
|
||||
f.configureFromExistingVirtualFile(virtualFile)
|
||||
|
||||
val targetElement = TargetElementUtil.findTargetElement(
|
||||
f.editor, TargetElementUtil.ELEMENT_NAME_ACCEPTED or TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED)
|
||||
assertNotNull(targetElement)
|
||||
|
||||
val propUsages = f.findUsages(targetElement!!)
|
||||
return // TODO: investigate and fix this test
|
||||
copyResourceDirectoryForTest(path)
|
||||
val testFileName = getTestName(true) + ".kt"
|
||||
val virtualFile = myFixture.copyFileToProject(path + testFileName, "src/" + getTestName(true) + ".kt")
|
||||
myFixture.configureFromExistingVirtualFile(virtualFile)
|
||||
|
||||
val propUsages = myFixture.findUsages(myFixture.elementAtCaret)
|
||||
assertTrue(propUsages.isNotEmpty())
|
||||
}
|
||||
}
|
||||
+5
-10
@@ -31,22 +31,17 @@ import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
|
||||
abstract class AbstractAndroidGotoTest : KotlinAndroidTestCase() {
|
||||
|
||||
override fun getTestDataPath(): String {
|
||||
return KotlinAndroidTestCaseBase.getPluginTestDataPathBase() + "/goto/" + getTestName(true) + "/"
|
||||
}
|
||||
|
||||
fun doTest(path: String) {
|
||||
val f = myFixture!!
|
||||
getResourceDirs(path).forEach { myFixture.copyDirectoryToProject(it.name, it.name) }
|
||||
val virtualFile = f.copyFileToProject(path + getTestName(true) + ".kt", "src/" + getTestName(true) + ".kt")
|
||||
f.configureFromExistingVirtualFile(virtualFile)
|
||||
copyResourceDirectoryForTest(path)
|
||||
val virtualFile = myFixture.copyFileToProject(path + getTestName(true) + ".kt", "src/" + getTestName(true) + ".kt")
|
||||
myFixture.configureFromExistingVirtualFile(virtualFile)
|
||||
|
||||
val expression = TargetElementUtil.findReference(f.editor, f.caretOffset)!!.element as KtElement
|
||||
val expression = TargetElementUtil.findReference(myFixture.editor, myFixture.caretOffset)!!.element as KtElement
|
||||
val bindingContext = expression.analyzeFully()
|
||||
val resolvedCall = bindingContext[BindingContext.RESOLVED_CALL, bindingContext[BindingContext.CALL, expression]]!!
|
||||
val property = resolvedCall.resultingDescriptor as? PropertyDescriptor ?: throw AssertionError("PropertyDescriptor expected")
|
||||
|
||||
val targetElement = GotoDeclarationAction.findTargetElement(f.project, f.editor, f.caretOffset)!!
|
||||
val targetElement = GotoDeclarationAction.findTargetElement(myFixture.project, myFixture.editor, myFixture.caretOffset)!!
|
||||
|
||||
assert(targetElement is XmlAttributeValue) { "XmlAttributeValue expected, got ${targetElement::class.java}" }
|
||||
assertEquals("@+id/${property.name}", (targetElement as XmlAttributeValue).value)
|
||||
|
||||
+6
-9
@@ -29,12 +29,11 @@ abstract class AbstractAndroidLayoutRenameTest : KotlinAndroidTestCase() {
|
||||
private val NEW_NAME_XML = "$NEW_NAME.xml"
|
||||
|
||||
fun doTest(path: String) {
|
||||
val f = myFixture!!
|
||||
getResourceDirs(path).forEach { myFixture.copyDirectoryToProject(it.name, it.name) }
|
||||
val virtualFile = f.copyFileToProject(path + getTestName(true) + ".kt", "src/" + getTestName(true) + ".kt")
|
||||
f.configureFromExistingVirtualFile(virtualFile)
|
||||
copyResourceDirectoryForTest(path)
|
||||
val virtualFile = myFixture.copyFileToProject(path + getTestName(true) + ".kt", "src/" + getTestName(true) + ".kt")
|
||||
myFixture.configureFromExistingVirtualFile(virtualFile)
|
||||
|
||||
val completionEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(f.editor, f.file)
|
||||
val completionEditor = InjectedLanguageUtil.getEditorForInjectedLanguageNoCommit(myFixture.editor, myFixture.file)
|
||||
|
||||
val element = TargetElementUtil.findTargetElement(
|
||||
completionEditor,
|
||||
@@ -42,10 +41,8 @@ abstract class AbstractAndroidLayoutRenameTest : KotlinAndroidTestCase() {
|
||||
|
||||
val file = element.containingFile as XmlFile
|
||||
|
||||
RenameProcessor(f.project, file, NEW_NAME_XML, false, true).run()
|
||||
RenameProcessor(myFixture.project, file, NEW_NAME_XML, false, true).run()
|
||||
|
||||
(f.file as KtFile).importDirectives.any { it.importedFqName!!.asString() == AndroidConst.SYNTHETIC_PACKAGE + ".main." + NEW_NAME }
|
||||
(myFixture.file as KtFile).importDirectives.any { it.importedFqName!!.asString() == AndroidConst.SYNTHETIC_PACKAGE + ".main." + NEW_NAME }
|
||||
}
|
||||
|
||||
override fun getTestDataPath() = KotlinAndroidTestCaseBase.getPluginTestDataPathBase() + "/rename/" + getTestName(true) + "/"
|
||||
}
|
||||
|
||||
+2
-9
@@ -16,24 +16,19 @@
|
||||
|
||||
package org.jetbrains.kotlin.android
|
||||
|
||||
import com.intellij.codeInsight.TargetElementUtil
|
||||
import com.intellij.openapi.vfs.LocalFileSystem
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil
|
||||
import com.intellij.refactoring.rename.RenameProcessor
|
||||
import com.intellij.psi.impl.source.xml.XmlAttributeValueImpl
|
||||
import com.intellij.testFramework.PlatformTestUtil
|
||||
import org.jetbrains.kotlin.psi.KtNameReferenceExpression
|
||||
|
||||
abstract class AbstractAndroidRenameTest : KotlinAndroidTestCase() {
|
||||
private val NEW_NAME = "NEWNAME"
|
||||
private val NEW_ID_NAME = "@+id/$NEW_NAME"
|
||||
|
||||
fun doTest(path: String) {
|
||||
getResourceDirs(path).forEach { myFixture.copyDirectoryToProject(it.name, it.name) }
|
||||
copyResourceDirectoryForTest(path)
|
||||
val virtualFile = myFixture.copyFileToProject("$path${getTestName(true)}.kt", "src/${getTestName(true)}.kt")
|
||||
myFixture.configureFromExistingVirtualFile(virtualFile)
|
||||
myFixture.renameElement(myFixture.elementAtCaret, NEW_ID_NAME)
|
||||
myFixture.checkResultByFile("expected/${getTestName(true)}.kt")
|
||||
myFixture.checkResultByFile("$path/expected/${getTestName(true)}.kt")
|
||||
assertResourcesEqual("$path/expected/res")
|
||||
}
|
||||
|
||||
@@ -42,6 +37,4 @@ abstract class AbstractAndroidRenameTest : KotlinAndroidTestCase() {
|
||||
}
|
||||
|
||||
fun getResourceDirectory() = LocalFileSystem.getInstance().findFileByPath(myFixture.tempDirPath + "/res")
|
||||
|
||||
override fun getTestDataPath() = KotlinAndroidTestCaseBase.getPluginTestDataPathBase() + "/rename/" + getTestName(true) + "/"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user