Extract base class for goto action tests

(cherry picked from commit 0b25723)
This commit is contained in:
Nikolay Krasko
2016-09-05 19:05:37 +03:00
committed by Nikolay Krasko
parent 115bc7e73b
commit acc7c3286c
3 changed files with 51 additions and 38 deletions
@@ -0,0 +1,42 @@
/*
* Copyright 2010-2016 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.kotlin.idea.navigation
import com.intellij.codeInsight.CodeInsightActionHandler
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.junit.Assert
abstract class AbstractGotoActionTest : LightCodeInsightFixtureTestCase() {
protected abstract val actionName: String
protected fun doTest(testPath: String) {
val parts = KotlinTestUtils.loadBeforeAfterText(testPath)
myFixture.configureByText(KotlinFileType.INSTANCE, parts[0])
val gotoSuperAction = ActionManager.getInstance().getAction(actionName) as CodeInsightActionHandler
gotoSuperAction.invoke(project, myFixture.editor, myFixture.file)
val text = myFixture.getDocument(myFixture.file).text
val afterText = StringBuilder(text).insert(editor.caretModel.offset, "<caret>").toString()
Assert.assertEquals(parts[1], afterText)
}
}
@@ -16,25 +16,13 @@
package org.jetbrains.kotlin.idea.navigation;
import com.intellij.codeInsight.CodeInsightActionHandler;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import org.jetbrains.kotlin.idea.KotlinFileType;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public abstract class AbstractGotoSuperTest extends LightCodeInsightFixtureTestCase {
protected void doTest(String testPath) {
List<String> parts = KotlinTestUtils.loadBeforeAfterText(testPath);
myFixture.configureByText(KotlinFileType.INSTANCE, parts.get(0));
CodeInsightActionHandler gotoSuperAction =
(CodeInsightActionHandler) ActionManager.getInstance().getAction(IdeActions.ACTION_GOTO_SUPER);
gotoSuperAction.invoke(getProject(), myFixture.getEditor(), myFixture.getFile());
myFixture.checkResult(parts.get(1));
public abstract class AbstractGotoSuperTest extends AbstractGotoActionTest {
@NotNull
@Override
protected String getActionName() {
return IdeActions.ACTION_GOTO_SUPER;
}
}
@@ -16,26 +16,9 @@
package org.jetbrains.kotlin.idea.navigation
import com.intellij.codeInsight.CodeInsightActionHandler
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.IdeActions
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.idea.KotlinFileType
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.junit.Assert
abstract class AbstractGotoTypeDeclarationTest : LightCodeInsightFixtureTestCase() {
protected fun doTest(testPath: String) {
val parts = KotlinTestUtils.loadBeforeAfterText(testPath)
myFixture.configureByText(KotlinFileType.INSTANCE, parts[0])
val gotoSuperAction = ActionManager.getInstance().getAction(IdeActions.ACTION_GOTO_TYPE_DECLARATION) as CodeInsightActionHandler
gotoSuperAction.invoke(project, myFixture.editor, myFixture.file)
val afterText = StringBuilder(myFixture.getDocument(myFixture.file).text).insert(editor.caretModel.offset, "<caret>").toString()
Assert.assertEquals(parts[1], afterText)
}
abstract class AbstractGotoTypeDeclarationTest : AbstractGotoActionTest() {
override val actionName: String
get() = IdeActions.ACTION_GOTO_TYPE_DECLARATION
}