diff --git a/.idea/libraries/junit_plugin.xml b/.idea/libraries/junit_plugin.xml index b4b2f738e58..e06c7313023 100644 --- a/.idea/libraries/junit_plugin.xml +++ b/.idea/libraries/junit_plugin.xml @@ -5,6 +5,7 @@ + diff --git a/.idea/libraries/testng_plugin.xml b/.idea/libraries/testng_plugin.xml index eb3ee15d7d5..7a0d27c4cdc 100644 --- a/.idea/libraries/testng_plugin.xml +++ b/.idea/libraries/testng_plugin.xml @@ -7,6 +7,7 @@ + diff --git a/core/util.runtime/src/org/jetbrains/kotlin/utils/collections.kt b/core/util.runtime/src/org/jetbrains/kotlin/utils/collections.kt index 829b8d66c86..e8623750942 100644 --- a/core/util.runtime/src/org/jetbrains/kotlin/utils/collections.kt +++ b/core/util.runtime/src/org/jetbrains/kotlin/utils/collections.kt @@ -83,7 +83,7 @@ public fun Iterable.mapToIndex(): Map { return map } -public fun > C.ifEmpty(body: () -> C): C = if (isEmpty()) body() else this +public inline fun > C.ifEmpty(body: () -> C): C = if (isEmpty()) body() else this public fun emptyOrSingletonList(item: T?): List = if (item == null) listOf() else listOf(item) diff --git a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index 48e12581573..28e12756785 100644 --- a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -42,6 +42,7 @@ import org.jetbrains.kotlin.generators.tests.reservedWords.generateTestDataForRe import org.jetbrains.kotlin.idea.AbstractExpressionSelectionTest import org.jetbrains.kotlin.idea.AbstractSmartSelectionTest import org.jetbrains.kotlin.idea.codeInsight.* +import org.jetbrains.kotlin.idea.codeInsight.generate.AbstractGenerateActionTest import org.jetbrains.kotlin.idea.codeInsight.moveUpDown.AbstractCodeMoverTest import org.jetbrains.kotlin.idea.codeInsight.surroundWith.AbstractSurroundWithTest import org.jetbrains.kotlin.idea.codeInsight.unwrap.AbstractUnwrapRemoveTest @@ -723,6 +724,10 @@ fun main(args: Array) { testClass() { model("kdoc/typing") } + + testClass() { + model("codeInsight/generate") + } } testGroup("idea/tests", "compiler/testData") { diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/overrideImplement/OverrideMemberChooserObject.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/overrideImplement/OverrideMemberChooserObject.kt index a28a4c1f250..dfd03ef3511 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/overrideImplement/OverrideMemberChooserObject.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/overrideImplement/OverrideMemberChooserObject.kt @@ -138,7 +138,7 @@ private fun generateFunction(project: Project, descriptor: FunctionDescriptor, b return JetPsiFactory(project).createFunction(OVERRIDE_RENDERER.render(newDescriptor) + body) } -private fun generateUnsupportedOrSuperCall(descriptor: CallableMemberDescriptor, bodyType: OverrideMemberChooserObject.BodyType): String { +public fun generateUnsupportedOrSuperCall(descriptor: CallableMemberDescriptor, bodyType: OverrideMemberChooserObject.BodyType): String { if (bodyType == OverrideMemberChooserObject.BodyType.EMPTY) { return "throw UnsupportedOperationException()" } diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index b6bc68ef4ea..b4063c0edb7 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -161,6 +161,23 @@ description="Execute Kotlin code in console"> + + + + + + + + + diff --git a/idea/src/org/jetbrains/kotlin/idea/actions/generate/KotlinGenerateActionBase.kt b/idea/src/org/jetbrains/kotlin/idea/actions/generate/KotlinGenerateActionBase.kt new file mode 100644 index 00000000000..77e76887cbb --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/actions/generate/KotlinGenerateActionBase.kt @@ -0,0 +1,61 @@ +/* + * Copyright 2010-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.kotlin.idea.actions.generate + +import com.intellij.codeInsight.CodeInsightActionHandler +import com.intellij.codeInsight.actions.CodeInsightAction +import com.intellij.lang.ContextAwareActionHandler +import com.intellij.openapi.actionSystem.DataContext +import com.intellij.openapi.actionSystem.Presentation +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiDocumentManager +import com.intellij.psi.PsiFile +import org.jetbrains.kotlin.idea.core.refactoring.canRefactor +import org.jetbrains.kotlin.psi.JetClassOrObject +import org.jetbrains.kotlin.psi.JetFile +import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType + +abstract class KotlinGenerateActionBase() : CodeInsightAction() { + override fun update( + presentation: Presentation, + project: Project, + editor: Editor, + file: PsiFile, + dataContext: DataContext, + actionPlace: String? + ) { + super.update(presentation, project, editor, file, dataContext, actionPlace) + val actionHandler = handler + if (actionHandler is ContextAwareActionHandler && presentation.isEnabled) { + presentation.isEnabled = actionHandler.isAvailableForQuickList(editor, file, dataContext) + } + } + + override fun isValidForFile(project: Project, editor: Editor, file: PsiFile): Boolean { + if (file !is JetFile || file.isCompiled) return false + + val targetClass = getTargetClass(editor, file) ?: return false + return targetClass.canRefactor() && isValidForClass(targetClass) + } + + protected open fun getTargetClass(editor: Editor, file: PsiFile): JetClassOrObject? { + return file.findElementAt(editor.caretModel.offset)?.getNonStrictParentOfType() + } + + protected abstract fun isValidForClass(targetClass: JetClassOrObject): Boolean +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/actions/generate/KotlinGenerateTestSupportActionBase.kt b/idea/src/org/jetbrains/kotlin/idea/actions/generate/KotlinGenerateTestSupportActionBase.kt new file mode 100644 index 00000000000..a6f459b7042 --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/actions/generate/KotlinGenerateTestSupportActionBase.kt @@ -0,0 +1,227 @@ +/* + * Copyright 2010-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.kotlin.idea.actions.generate + +import com.intellij.codeInsight.CodeInsightActionHandler +import com.intellij.codeInsight.generation.actions.GenerateActionPopupTemplateInjector +import com.intellij.codeInsight.hint.HintManager +import com.intellij.ide.fileTemplates.FileTemplateManager +import com.intellij.ide.fileTemplates.impl.AllFileTemplatesConfigurable +import com.intellij.lang.java.JavaLanguage +import com.intellij.openapi.actionSystem.AnAction +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.actionSystem.CommonDataKeys +import com.intellij.openapi.actionSystem.DataContext +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.extensions.Extensions +import com.intellij.openapi.project.Project +import com.intellij.openapi.ui.InputValidator +import com.intellij.openapi.ui.Messages +import com.intellij.openapi.ui.popup.PopupChooserBuilder +import com.intellij.openapi.util.io.FileUtil +import com.intellij.psi.PsiDocumentManager +import com.intellij.psi.PsiElementFactory +import com.intellij.psi.PsiFile +import com.intellij.testIntegration.JavaTestFramework +import com.intellij.testIntegration.TestFramework +import com.intellij.testIntegration.TestIntegrationUtils.MethodKind +import com.intellij.ui.components.JBList +import com.intellij.util.IncorrectOperationException +import com.intellij.util.SmartList +import org.jetbrains.kotlin.asJava.toLightClass +import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor +import org.jetbrains.kotlin.idea.core.KotlinNameSuggester +import org.jetbrains.kotlin.idea.core.overrideImplement.OverrideMemberChooserObject.BodyType +import org.jetbrains.kotlin.idea.core.overrideImplement.generateUnsupportedOrSuperCall +import org.jetbrains.kotlin.idea.core.refactoring.j2k +import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.setupEditorSelection +import org.jetbrains.kotlin.idea.quickfix.generateMember +import org.jetbrains.kotlin.idea.util.application.executeWriteCommand +import org.jetbrains.kotlin.lexer.JetTokens +import org.jetbrains.kotlin.psi.JetClassOrObject +import org.jetbrains.kotlin.psi.JetNamedFunction +import org.jetbrains.kotlin.psi.JetPsiFactory +import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf +import org.jetbrains.kotlin.utils.ifEmpty + +abstract class KotlinGenerateTestSupportActionBase( + private val methodKind : MethodKind +) : KotlinGenerateActionBase(), GenerateActionPopupTemplateInjector { + companion object { + private fun findTargetClass(editor: Editor, file: PsiFile): JetClassOrObject? { + val elementAtCaret = file.findElementAt(editor.caretModel.offset) ?: return null + return elementAtCaret.parentsWithSelf.filterIsInstance().firstOrNull { !it.isLocal() } + } + + private fun findSuitableFrameworks(klass: JetClassOrObject): List { + val lightClass = klass.toLightClass() ?: return emptyList() + val frameworks = Extensions.getExtensions(TestFramework.EXTENSION_NAME).filter { it.language == JavaLanguage.INSTANCE } + return frameworks.firstOrNull { it.isTestClass(lightClass) }?.let { listOf(it) } + ?: frameworks.filterTo(SmartList()) { it.isPotentialTestClass(lightClass) } + } + + private fun chooseAndPerform(editor: Editor, frameworks: List, consumer: (TestFramework) -> Unit) { + frameworks.ifEmpty { return } + frameworks.singleOrNull()?.let { return consumer(it) } + + if (ApplicationManager.getApplication().isUnitTestMode) return consumer(frameworks.first()) + + val list = JBList(*frameworks.toTypedArray()) + list.cellRenderer = TestFrameworkListCellRenderer() + + PopupChooserBuilder(list) + .setFilteringEnabled { (it as TestFramework).name } + .setTitle("Choose Framework") + .setItemChoosenCallback { consumer(list.selectedValue as TestFramework) } + .setMovable(true) + .createPopup() + .showInBestPositionFor(editor) + } + + private val BODY_VAR = "\${BODY}" + private val NAME_VAR = "\${NAME}" + + private val NAME_VALIDATOR = object : InputValidator { + override fun checkInput(inputString: String) = KotlinNameSuggester.isIdentifier(inputString) + override fun canClose(inputString: String) = true + } + } + + public class SetUp : KotlinGenerateTestSupportActionBase(MethodKind.SET_UP) { + override fun isApplicableTo(framework: TestFramework, targetClass: JetClassOrObject): Boolean { + return framework.findSetUpMethod(targetClass.toLightClass()!!) == null + } + } + + public class Test : KotlinGenerateTestSupportActionBase(MethodKind.TEST) { + override fun isApplicableTo(framework: TestFramework, targetClass: JetClassOrObject) = true + } + + public class Data : KotlinGenerateTestSupportActionBase(MethodKind.DATA) { + override fun isApplicableTo(framework: TestFramework, targetClass: JetClassOrObject): Boolean { + if (framework !is JavaTestFramework) return false + return framework.findParametersMethod(targetClass.toLightClass()) == null + } + } + + public class TearDown : KotlinGenerateTestSupportActionBase(MethodKind.TEAR_DOWN) { + override fun isApplicableTo(framework: TestFramework, targetClass: JetClassOrObject): Boolean { + return framework.findTearDownMethod(targetClass.toLightClass()!!) == null + } + } + + private inner class HandlerImpl : CodeInsightActionHandler { + override fun startInWriteAction() = false + + override fun invoke(project: Project, editor: Editor, file: PsiFile) { + val klass = findTargetClass(editor, file) ?: return + val frameworks = findSuitableFrameworks(klass) + .filter { methodKind.getFileTemplateDescriptor(it) != null && isApplicableTo(it, klass) } + chooseAndPerform(editor, frameworks) { doGenerate(editor, file, klass, it) } + } + + private fun doGenerate(editor: Editor, file: PsiFile, klass: JetClassOrObject, framework: TestFramework) { + val project = file.project + val commandName = "Generate test function" + project.executeWriteCommand(commandName) { + try { + PsiDocumentManager.getInstance(project).commitAllDocuments() + + val fileTemplateDescriptor = methodKind.getFileTemplateDescriptor(framework) + val fileTemplate = FileTemplateManager.getInstance(project).getCodeTemplate(fileTemplateDescriptor.fileName) + var templateText = fileTemplate.text.replace(BODY_VAR, "") + if (templateText.contains(NAME_VAR)) { + var name = "Name" + if (!ApplicationManager.getApplication().isUnitTestMode) { + name = Messages.showInputDialog("Choose test name: ", commandName, null, name, NAME_VALIDATOR) + ?: return@executeWriteCommand + } + + templateText = fileTemplate.text.replace(NAME_VAR, name) + } + val factory = PsiElementFactory.SERVICE.getInstance(project) + val psiMethod = factory.createMethodFromText(templateText, null) + psiMethod.throwsList.referenceElements.forEach { it.delete() } + val function = psiMethod.j2k() as? JetNamedFunction + if (function == null) { + HintManager.getInstance().showErrorHint(editor, "Couldn't convert Java template to Kotlin") + return@executeWriteCommand + } + val functionInPlace = generateMember(editor, klass, function) + + val functionDescriptor = functionInPlace.resolveToDescriptor() as FunctionDescriptor + val overriddenDescriptors = functionDescriptor.overriddenDescriptors + val bodyText = when (overriddenDescriptors.size()) { + 0 -> generateUnsupportedOrSuperCall(functionDescriptor, BodyType.EMPTY) + 1 -> generateUnsupportedOrSuperCall(overriddenDescriptors.single(), BodyType.SUPER) + else -> generateUnsupportedOrSuperCall(overriddenDescriptors.first(), BodyType.QUALIFIED_SUPER) + } + functionInPlace.bodyExpression?.delete() + functionInPlace.add(JetPsiFactory(project).createBlock(bodyText)) + + if (overriddenDescriptors.isNotEmpty()) { + functionInPlace.addModifier(JetTokens.OVERRIDE_KEYWORD) + } + + setupEditorSelection(editor, functionInPlace) + } + catch (e: IncorrectOperationException) { + HintManager.getInstance().showErrorHint(editor, "Cannot generate method: " + e.getMessage()) + } + } + } + } + + private val handler = HandlerImpl() + + override fun getHandler() = handler + + override fun getTargetClass(editor: Editor, file: PsiFile): JetClassOrObject? { + return findTargetClass(editor, file) + } + + override fun isValidForClass(targetClass: JetClassOrObject): Boolean { + return findSuitableFrameworks(targetClass).any { isApplicableTo(it, targetClass) } + } + + protected abstract fun isApplicableTo(framework: TestFramework, targetClass: JetClassOrObject): Boolean + + override fun createEditTemplateAction(dataContext: DataContext): AnAction? { + val project = CommonDataKeys.PROJECT.getData(dataContext) ?: return null + val editor = CommonDataKeys.EDITOR.getData(dataContext) ?: return null + val file = CommonDataKeys.PSI_FILE.getData(dataContext) ?: return null + + val targetClass = getTargetClass(editor, file) ?: return null + val frameworks = findSuitableFrameworks(targetClass).ifEmpty { return null } + + return object : AnAction("Edit Template") { + override fun actionPerformed(e: AnActionEvent) { + chooseAndPerform(editor, frameworks) { + val descriptor = methodKind.getFileTemplateDescriptor(it) + if (descriptor == null) { + HintManager.getInstance().showErrorHint(editor, "No template found for ${it.name}:${templatePresentation.text}") + return@chooseAndPerform + } + + AllFileTemplatesConfigurable.editCodeTemplate(FileUtil.getNameWithoutExtension(descriptor.fileName), project) + } + } + } + } +} \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/actions/generate/TestFrameworkListCellRenderer.java b/idea/src/org/jetbrains/kotlin/idea/actions/generate/TestFrameworkListCellRenderer.java new file mode 100644 index 00000000000..71f59e13dae --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/actions/generate/TestFrameworkListCellRenderer.java @@ -0,0 +1,35 @@ +/* + * Copyright 2010-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.kotlin.idea.actions.generate; + +import com.intellij.testIntegration.TestFramework; + +import javax.swing.*; +import java.awt.*; + +public class TestFrameworkListCellRenderer extends DefaultListCellRenderer { + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + Component result = super.getListCellRendererComponent(list, "", index, isSelected, cellHasFocus); + if (value == null) return result; + + TestFramework framework = (TestFramework) value; + setIcon(framework.getIcon()); + setText(framework.getName()); + return result; + } +} diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/dataMethod.kt b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/dataMethod.kt new file mode 100644 index 00000000000..1fec155600d --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/dataMethod.kt @@ -0,0 +1,5 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$Data +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +class A { + +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/dataMethod.kt.after b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/dataMethod.kt.after new file mode 100644 index 00000000000..c3494692a51 --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/dataMethod.kt.after @@ -0,0 +1,10 @@ +import org.junit.runners.Parameterized + +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$Data +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +class A { + @Parameterized.Parameters + fun data(): Collection> { + throw UnsupportedOperationException() + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUp.kt b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUp.kt new file mode 100644 index 00000000000..cdb241b0f27 --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUp.kt @@ -0,0 +1,5 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +class A { + +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUp.kt.after b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUp.kt.after new file mode 100644 index 00000000000..04288c9f0db --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUp.kt.after @@ -0,0 +1,10 @@ +import org.junit.Before + +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +class A { + @Before + fun setUp() { + throw UnsupportedOperationException() + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUpExists.kt b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUpExists.kt new file mode 100644 index 00000000000..c260bde9f3a --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUpExists.kt @@ -0,0 +1,10 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +import org.junit.Before + +class A { + @Before + fun setUp() { + throw UnsupportedOperationException() + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUpExists.kt.after b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUpExists.kt.after new file mode 100644 index 00000000000..931c803d3f4 --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUpExists.kt.after @@ -0,0 +1,15 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +import org.junit.Before + +class A { + @org.testng.annotations.BeforeMethod + fun setUp() { + throw UnsupportedOperationException() + } + + @Before + fun setUp() { + throw UnsupportedOperationException() + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUpOverrides.kt b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUpOverrides.kt new file mode 100644 index 00000000000..5db6146900c --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUpOverrides.kt @@ -0,0 +1,11 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +open class A { + open fun setUp() { + + } +} + +class B : A() { + +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUpOverrides.kt.after b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUpOverrides.kt.after new file mode 100644 index 00000000000..2eaf72052e4 --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUpOverrides.kt.after @@ -0,0 +1,16 @@ +import org.junit.Before + +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +open class A { + open fun setUp() { + + } +} + +class B : A() { + @Before + override fun setUp() { + super.setUp() + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/tearDown.kt b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/tearDown.kt new file mode 100644 index 00000000000..c9ac2501bd7 --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/tearDown.kt @@ -0,0 +1,5 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$TearDown +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +class A { + +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/tearDown.kt.after b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/tearDown.kt.after new file mode 100644 index 00000000000..346de8ab39d --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/tearDown.kt.after @@ -0,0 +1,10 @@ +import org.junit.After + +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$TearDown +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +class A { + @After + fun tearDown() { + throw UnsupportedOperationException() + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/tearDownExists.kt b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/tearDownExists.kt new file mode 100644 index 00000000000..ac5a7798595 --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/tearDownExists.kt @@ -0,0 +1,10 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$TearDown +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +import org.junit.After + +class A { + @After + fun tearDown() { + throw UnsupportedOperationException() + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/tearDownExists.kt.after b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/tearDownExists.kt.after new file mode 100644 index 00000000000..3f827fdc79f --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/tearDownExists.kt.after @@ -0,0 +1,15 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$TearDown +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +import org.junit.After + +class A { + @org.testng.annotations.AfterMethod + fun tearDown() { + throw UnsupportedOperationException() + } + + @After + fun tearDown() { + throw UnsupportedOperationException() + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/testMethod.kt b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/testMethod.kt new file mode 100644 index 00000000000..6d63f9cb750 --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/testMethod.kt @@ -0,0 +1,5 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$Test +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +class A { + +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/testMethod.kt.after b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/testMethod.kt.after new file mode 100644 index 00000000000..5a74fbd0dca --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/testMethod.kt.after @@ -0,0 +1,10 @@ +import org.junit.Test + +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$Test +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +class A { + @Test + fun testName() { + throw UnsupportedOperationException() + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/setUp.kt b/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/setUp.kt new file mode 100644 index 00000000000..f5cf2b491e9 --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/setUp.kt @@ -0,0 +1,7 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +import junit.framework.TestCase + +class A : TestCase() { + +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/setUp.kt.after b/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/setUp.kt.after new file mode 100644 index 00000000000..2e4ebed50cc --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/setUp.kt.after @@ -0,0 +1,9 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +import junit.framework.TestCase + +class A : TestCase() { + override fun setUp() { + super.setUp() + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/setUpExists.kt b/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/setUpExists.kt new file mode 100644 index 00000000000..97c81985214 --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/setUpExists.kt @@ -0,0 +1,10 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp +// NOT_APPLICABLE +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +import junit.framework.TestCase + +class A : TestCase() { + override fun setUp() { + super.setUp() + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/tearDown.kt b/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/tearDown.kt new file mode 100644 index 00000000000..462658667ff --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/tearDown.kt @@ -0,0 +1,7 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$TearDown +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +import junit.framework.TestCase + +class A : TestCase() { + +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/tearDown.kt.after b/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/tearDown.kt.after new file mode 100644 index 00000000000..32be9ed9c74 --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/tearDown.kt.after @@ -0,0 +1,9 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$TearDown +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +import junit.framework.TestCase + +class A : TestCase() { + override fun tearDown() { + super.tearDown() + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/tearDownExists.kt b/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/tearDownExists.kt new file mode 100644 index 00000000000..33b2e83b7e8 --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/tearDownExists.kt @@ -0,0 +1,10 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$TearDown +// NOT_APPLICABLE +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +import junit.framework.TestCase + +class A : TestCase() { + override fun tearDown() { + super.tearDown() + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/testMethod.kt b/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/testMethod.kt new file mode 100644 index 00000000000..d941eaecf11 --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/testMethod.kt @@ -0,0 +1,7 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$Test +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +import junit.framework.TestCase + +class A : TestCase() { + +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/testMethod.kt.after b/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/testMethod.kt.after new file mode 100644 index 00000000000..e076c9ab16c --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/junit3/testMethod.kt.after @@ -0,0 +1,9 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$Test +// CONFIGURE_LIBRARY: JUnit@lib/junit-4.12.jar +import junit.framework.TestCase + +class A : TestCase() { + fun testName() { + throw UnsupportedOperationException() + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/dataMethod.kt b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/dataMethod.kt new file mode 100644 index 00000000000..970538f34d8 --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/dataMethod.kt @@ -0,0 +1,7 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$Data +// CONFIGURE_LIBRARY: TestNG@plugins/testng/lib/testng.jar +import org.testng.annotations.Test + +@Test class A { + +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/dataMethod.kt.after b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/dataMethod.kt.after new file mode 100644 index 00000000000..163ec0930c8 --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/dataMethod.kt.after @@ -0,0 +1,11 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$Data +// CONFIGURE_LIBRARY: TestNG@plugins/testng/lib/testng.jar +import org.testng.annotations.DataProvider +import org.testng.annotations.Test + +@Test class A { + @DataProvider(name = "Name") + fun Name(): Array> { + throw UnsupportedOperationException() + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUp.kt b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUp.kt new file mode 100644 index 00000000000..5adc76182d3 --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUp.kt @@ -0,0 +1,7 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp +// CONFIGURE_LIBRARY: TestNG@plugins/testng/lib/testng.jar +import org.testng.annotations.Test + +@Test class A { + +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUp.kt.after b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUp.kt.after new file mode 100644 index 00000000000..c1a8a04968b --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUp.kt.after @@ -0,0 +1,11 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp +// CONFIGURE_LIBRARY: TestNG@plugins/testng/lib/testng.jar +import org.testng.annotations.BeforeMethod +import org.testng.annotations.Test + +@Test class A { + @BeforeMethod + fun setUp() { + throw UnsupportedOperationException() + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUpExists.kt b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUpExists.kt new file mode 100644 index 00000000000..3e947d04231 --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUpExists.kt @@ -0,0 +1,12 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp +// NOT_APPLICABLE +// CONFIGURE_LIBRARY: TestNG@plugins/testng/lib/testng.jar +import org.testng.annotations.BeforeMethod +import org.testng.annotations.Test + +@Test class A { + @BeforeMethod + fun setUp() { + throw UnsupportedOperationException() + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUpOverrides.kt b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUpOverrides.kt new file mode 100644 index 00000000000..8dca3ff24e2 --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUpOverrides.kt @@ -0,0 +1,13 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp +// CONFIGURE_LIBRARY: TestNG@plugins/testng/lib/testng.jar +import org.testng.annotations.Test + +open class A { + open fun setUp() { + + } +} + +@Test class B : A() { + +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUpOverrides.kt.after b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUpOverrides.kt.after new file mode 100644 index 00000000000..31cc26f4e67 --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUpOverrides.kt.after @@ -0,0 +1,17 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$SetUp +// CONFIGURE_LIBRARY: TestNG@plugins/testng/lib/testng.jar +import org.testng.annotations.BeforeMethod +import org.testng.annotations.Test + +open class A { + open fun setUp() { + + } +} + +@Test class B : A() { + @BeforeMethod + override fun setUp() { + super.setUp() + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/tearDown.kt b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/tearDown.kt new file mode 100644 index 00000000000..24e07f520b9 --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/tearDown.kt @@ -0,0 +1,7 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$TearDown +// CONFIGURE_LIBRARY: TestNG@plugins/testng/lib/testng.jar +import org.testng.annotations.Test + +@Test class A { + +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/tearDown.kt.after b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/tearDown.kt.after new file mode 100644 index 00000000000..7ef8bc78e3c --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/tearDown.kt.after @@ -0,0 +1,11 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$TearDown +// CONFIGURE_LIBRARY: TestNG@plugins/testng/lib/testng.jar +import org.testng.annotations.AfterMethod +import org.testng.annotations.Test + +@Test class A { + @AfterMethod + fun tearDown() { + throw UnsupportedOperationException() + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/tearDownExists.kt b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/tearDownExists.kt new file mode 100644 index 00000000000..2625e573020 --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/tearDownExists.kt @@ -0,0 +1,12 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$TearDown +// NOT_APPLICABLE +// CONFIGURE_LIBRARY: TestNG@plugins/testng/lib/testng.jar +import org.testng.annotations.AfterMethod +import org.testng.annotations.Test + +@Test class A { + @AfterMethod + fun tearDown() { + throw UnsupportedOperationException() + } +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/testMethod.kt b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/testMethod.kt new file mode 100644 index 00000000000..837f83e459f --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/testMethod.kt @@ -0,0 +1,7 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$Test +// CONFIGURE_LIBRARY: TestNG@plugins/testng/lib/testng.jar +import org.testng.annotations.Test + +@Test class A { + +} \ No newline at end of file diff --git a/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/testMethod.kt.after b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/testMethod.kt.after new file mode 100644 index 00000000000..91ff040c4a9 --- /dev/null +++ b/idea/testData/codeInsight/generate/testFrameworkSupport/testNG/testMethod.kt.after @@ -0,0 +1,10 @@ +// ACTION_CLASS: org.jetbrains.kotlin.idea.actions.generate.KotlinGenerateTestSupportActionBase$Test +// CONFIGURE_LIBRARY: TestNG@plugins/testng/lib/testng.jar +import org.testng.annotations.Test + +@Test class A { + @Test + fun testName() { + throw UnsupportedOperationException() + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/generate/AbstractGenerateActionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/generate/AbstractGenerateActionTest.kt new file mode 100644 index 00000000000..d81d94c64fa --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/generate/AbstractGenerateActionTest.kt @@ -0,0 +1,75 @@ +/* + * Copyright 2010-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.kotlin.idea.codeInsight.generate + +import com.intellij.codeInsight.actions.CodeInsightAction +import com.intellij.openapi.roots.ModuleRootManager +import com.intellij.openapi.util.io.FileUtil +import com.intellij.testFramework.PlatformTestUtil +import junit.framework.TestCase +import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil +import org.jetbrains.kotlin.idea.test.JetLightCodeInsightFixtureTestCase +import org.jetbrains.kotlin.idea.test.JetWithJdkAndRuntimeLightProjectDescriptor +import org.jetbrains.kotlin.idea.util.application.runWriteAction +import org.jetbrains.kotlin.test.InTextDirectivesUtils +import java.io.File + +abstract class AbstractGenerateActionTest : JetLightCodeInsightFixtureTestCase() { + private fun setUpTestSourceRoot() { + val module = myModule + val model = ModuleRootManager.getInstance(module).modifiableModel + val entry = model.contentEntries.single() + val sourceFolderFile = entry.sourceFolderFiles.single() + entry.removeSourceFolder(entry.sourceFolders.single()) + entry.addSourceFolder(sourceFolderFile, true) + runWriteAction { + model.commit() + module.project.save() + } + } + + protected fun doTest(path: String) { + setUpTestSourceRoot() + + val fileText = FileUtil.loadFile(File(path), true) + + try { + ConfigLibraryUtil.configureLibrariesByDirective(myModule, PlatformTestUtil.getCommunityPath(), fileText) + + myFixture.configureByFile(path) + + val actionClassName = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// ACTION_CLASS: ") + val action = Class.forName(actionClassName).newInstance() as CodeInsightAction + + val isApplicableExpected = !InTextDirectivesUtils.isDirectiveDefined(fileText, "// NOT_APPLICABLE") + + val presentation = myFixture.testAction(action) + TestCase.assertEquals(isApplicableExpected, presentation.isEnabled) + + if (isApplicableExpected) { + val afterFile = File(path + ".after") + TestCase.assertTrue(afterFile.exists()) + myFixture.checkResult(FileUtil.loadFile(afterFile, true)) + } + } + finally { + ConfigLibraryUtil.unconfigureLibrariesByDirective(myModule, fileText) + } + } + + override fun getProjectDescriptor() = JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE +} diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/generate/GenerateActionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/generate/GenerateActionTestGenerated.java new file mode 100644 index 00000000000..05584bf8822 --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/generate/GenerateActionTestGenerated.java @@ -0,0 +1,187 @@ +/* + * Copyright 2010-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.kotlin.idea.codeInsight.generate; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; +import org.jetbrains.kotlin.test.JetTestUtils; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.runner.RunWith; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("idea/testData/codeInsight/generate") +@TestDataPath("$PROJECT_ROOT") +@RunWith(JUnit3RunnerWithInners.class) +public class GenerateActionTestGenerated extends AbstractGenerateActionTest { + public void testAllFilesPresentInGenerate() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/codeInsight/generate"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("idea/testData/codeInsight/generate/testFrameworkSupport") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class TestFrameworkSupport extends AbstractGenerateActionTest { + public void testAllFilesPresentInTestFrameworkSupport() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/codeInsight/generate/testFrameworkSupport"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class JUnit4 extends AbstractGenerateActionTest { + public void testAllFilesPresentInJUnit4() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("dataMethod.kt") + public void testDataMethod() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/dataMethod.kt"); + doTest(fileName); + } + + @TestMetadata("setUp.kt") + public void testSetUp() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUp.kt"); + doTest(fileName); + } + + @TestMetadata("setUpExists.kt") + public void testSetUpExists() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUpExists.kt"); + doTest(fileName); + } + + @TestMetadata("setUpOverrides.kt") + public void testSetUpOverrides() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/setUpOverrides.kt"); + doTest(fileName); + } + + @TestMetadata("tearDown.kt") + public void testTearDown() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/tearDown.kt"); + doTest(fileName); + } + + @TestMetadata("tearDownExists.kt") + public void testTearDownExists() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/tearDownExists.kt"); + doTest(fileName); + } + + @TestMetadata("testMethod.kt") + public void testTestMethod() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/testFrameworkSupport/jUnit4/testMethod.kt"); + doTest(fileName); + } + } + + @TestMetadata("idea/testData/codeInsight/generate/testFrameworkSupport/junit3") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Junit3 extends AbstractGenerateActionTest { + public void testAllFilesPresentInJunit3() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/codeInsight/generate/testFrameworkSupport/junit3"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("setUp.kt") + public void testSetUp() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/testFrameworkSupport/junit3/setUp.kt"); + doTest(fileName); + } + + @TestMetadata("setUpExists.kt") + public void testSetUpExists() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/testFrameworkSupport/junit3/setUpExists.kt"); + doTest(fileName); + } + + @TestMetadata("tearDown.kt") + public void testTearDown() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/testFrameworkSupport/junit3/tearDown.kt"); + doTest(fileName); + } + + @TestMetadata("tearDownExists.kt") + public void testTearDownExists() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/testFrameworkSupport/junit3/tearDownExists.kt"); + doTest(fileName); + } + + @TestMetadata("testMethod.kt") + public void testTestMethod() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/testFrameworkSupport/junit3/testMethod.kt"); + doTest(fileName); + } + } + + @TestMetadata("idea/testData/codeInsight/generate/testFrameworkSupport/testNG") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class TestNG extends AbstractGenerateActionTest { + public void testAllFilesPresentInTestNG() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/codeInsight/generate/testFrameworkSupport/testNG"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("dataMethod.kt") + public void testDataMethod() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/testFrameworkSupport/testNG/dataMethod.kt"); + doTest(fileName); + } + + @TestMetadata("setUp.kt") + public void testSetUp() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUp.kt"); + doTest(fileName); + } + + @TestMetadata("setUpExists.kt") + public void testSetUpExists() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUpExists.kt"); + doTest(fileName); + } + + @TestMetadata("setUpOverrides.kt") + public void testSetUpOverrides() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/testFrameworkSupport/testNG/setUpOverrides.kt"); + doTest(fileName); + } + + @TestMetadata("tearDown.kt") + public void testTearDown() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/testFrameworkSupport/testNG/tearDown.kt"); + doTest(fileName); + } + + @TestMetadata("tearDownExists.kt") + public void testTearDownExists() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/testFrameworkSupport/testNG/tearDownExists.kt"); + doTest(fileName); + } + + @TestMetadata("testMethod.kt") + public void testTestMethod() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/generate/testFrameworkSupport/testNG/testMethod.kt"); + doTest(fileName); + } + } + } +}