From 2ca7045228592b31fa7cdfd99a3beec0dacb2db9 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Fri, 12 Jan 2018 19:38:57 +0300 Subject: [PATCH] Rewrite KotlinNameSuggesterTest test with KotlinLightCodeInsightFixtureTestCase Use proper project descriptors and avoid reconfigure for test project. --- .../nameSuggester/KotlinNameSuggesterTest.kt | 88 ++++++++----------- 1 file changed, 39 insertions(+), 49 deletions(-) diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/nameSuggester/KotlinNameSuggesterTest.kt b/idea/tests/org/jetbrains/kotlin/idea/refactoring/nameSuggester/KotlinNameSuggesterTest.kt index d8a4d79cbf1..a5f440ec795 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/nameSuggester/KotlinNameSuggesterTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/nameSuggester/KotlinNameSuggesterTest.kt @@ -17,99 +17,89 @@ package org.jetbrains.kotlin.idea.refactoring.nameSuggester import com.intellij.openapi.util.text.StringUtil -import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils import org.jetbrains.kotlin.idea.core.KotlinNameSuggester import org.jetbrains.kotlin.idea.refactoring.IntroduceRefactoringException import org.jetbrains.kotlin.idea.refactoring.selectElement -import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil +import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode -import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.jetbrains.kotlin.test.KotlinTestUtils import java.lang.AssertionError -class KotlinNameSuggesterTest : LightCodeInsightFixtureTestCase() { - fun testArrayList() { doTest() } +class KotlinNameSuggesterTest : KotlinLightCodeInsightFixtureTestCase() { + fun testArrayList() = doTest() - fun testGetterSure() { doTest() } + fun testGetterSure() = doTest() - fun testNameArrayOfClasses() { doTest() } + fun testNameArrayOfClasses() = doTest() - fun testNameArrayOfStrings() { doTest() } + fun testNameArrayOfStrings() = doTest() - fun testNamePrimitiveArray() { doTest() } + fun testNamePrimitiveArray() = doTest() - fun testNameCallExpression() { doTest() } + fun testNameCallExpression() = doTest() - fun testNameClassCamelHump() { doTest() } + fun testNameClassCamelHump() = doTest() - fun testNameLong() { doTest() } + fun testNameLong() = doTest() - fun testNameReferenceExpression() { doTest() } + fun testNameReferenceExpression() = doTest() - fun testNameString() { doTest() } + fun testNameString() = doTest() - fun testAnonymousObject() { doTest() } + fun testAnonymousObject() = doTest() - fun testAnonymousObjectWithSuper() { doTest() } + fun testAnonymousObjectWithSuper() = doTest() - fun testArrayOfObjectsType() { doTest() } + fun testArrayOfObjectsType() = doTest() - fun testURL() { doTest() } + fun testURL() = doTest() - fun testParameterNameByArgumentExpression() { doTest() } + fun testParameterNameByArgumentExpression() = doTest() - fun testParameterNameByParenthesizedArgumentExpression() { doTest() } + fun testParameterNameByParenthesizedArgumentExpression() = doTest() - fun testIdWithDigits() { doTest() } + fun testIdWithDigits() = doTest() - fun testIdWithNonASCII() { doTest() } + fun testIdWithNonASCII() = doTest() - fun testFunction1() { doTest() } + fun testFunction1() = doTest() - fun testFunction2() { doTest() } + fun testFunction2() = doTest() - fun testExtensionFunction1() { doTest() } + fun testExtensionFunction1() = doTest() - fun testExtensionFunction2() { doTest() } + fun testExtensionFunction2() = doTest() - override fun setUp() { - super.setUp() - myFixture.testDataPath = PluginTestCaseBase.getTestDataPathBase() + "/refactoring/nameSuggester" + override fun getTestDataPath(): String { + return PluginTestCaseBase.getTestDataPathBase() + "/refactoring/nameSuggester" } private fun doTest() { - myFixture.configureByFile(getTestName(false) + ".kt") - val file = myFixture.file as KtFile - val expectedResultText = KotlinTestUtils.getLastCommentInFile(file) - val withRuntime = InTextDirectivesUtils.isDirectiveDefined(file.text, "//WITH_RUNTIME") try { - if (withRuntime) { - ConfigLibraryUtil.configureKotlinRuntimeAndSdk(myModule, PluginTestCaseBase.mockJdk()) - } + myFixture.configureByFile(getTestName(false) + ".kt") + val file = myFixture.file as KtFile + val expectedResultText = KotlinTestUtils.getLastCommentInFile(file) + selectElement(myFixture.editor, file, listOf(CodeInsightUtils.ElementKind.EXPRESSION)) { val names = KotlinNameSuggester - .suggestNamesByExpressionAndType(it as KtExpression, - null, - it.analyze(BodyResolveMode.PARTIAL), - { true }, - "value") - .sorted() + .suggestNamesByExpressionAndType( + it as KtExpression, + null, + it.analyze(BodyResolveMode.PARTIAL), + { true }, + "value" + ) + .sorted() val result = StringUtil.join(names, "\n").trim() assertEquals(expectedResultText, result) } - } - catch (e: IntroduceRefactoringException) { + } catch (e: IntroduceRefactoringException) { throw AssertionError("Failed to find expression: " + e.message) } - finally { - if (withRuntime) { - ConfigLibraryUtil.unConfigureKotlinRuntimeAndSdk(myModule, PluginTestCaseBase.mockJdk()) - } - } } }