diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/Domain.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/Domain.kt index 836f26faba..3b82df3436 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/Domain.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/Domain.kt @@ -256,6 +256,29 @@ abstract class TestFramework( } } +class UnknownTestFramework(id: String) : TestFramework(id = id, displayName = id) { + override val mainPackage: String = id + override val assertionsClass: ClassId = ClassId(id) + override val arraysAssertionsClass: ClassId = ClassId(id) + override val kotlinFailureAssertionsClass: ClassId = ClassId(id) + override val testAnnotationId: ClassId = ClassId(id) + override val beforeMethodId: ClassId = ClassId(id) + override val afterMethodId: ClassId = ClassId(id) + override val parameterizedTestAnnotationId: ClassId = ClassId(id) + override val methodSourceAnnotationId: ClassId = ClassId(id) + override val nestedClassesShouldBeStatic: Boolean = false + override val argListClassId: ClassId = ClassId(id) + + override fun getRunTestsCommand( + executionInvoke: String, + classPath: String, + classesNames: List, + buildDirectory: String, + additionalArguments: List + ): List = emptyList() + +} + object TestNg : TestFramework(id = "TestNG",displayName = "TestNG") { override val mainPackage: String = TEST_NG_PACKAGE diff --git a/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogWindow.kt b/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogWindow.kt index 5f6cb1a165..7f349c0cfd 100644 --- a/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogWindow.kt +++ b/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogWindow.kt @@ -16,6 +16,7 @@ import com.jetbrains.python.psi.PyClass import com.jetbrains.python.psi.PyFunction import org.utbot.framework.codegen.domain.ProjectType import org.utbot.framework.codegen.domain.TestFramework +import org.utbot.intellij.plugin.language.python.settings.PythonTestFrameworkMapper import org.utbot.intellij.plugin.language.python.settings.loadStateFromModel import org.utbot.intellij.plugin.language.python.table.UtPyClassItem import org.utbot.intellij.plugin.language.python.table.UtPyFunctionItem @@ -93,8 +94,9 @@ class PythonDialogWindow(val model: PythonTestsModel) : DialogWrapper(model.proj private fun initDefaultValues() { val settings = model.project.service() - val installedTestFramework = TestFramework.allItems.singleOrNull { it.isInstalled } - currentFrameworkItem = installedTestFramework ?: settings.testFramework + val installedTestFramework = PythonTestFrameworkMapper.allItems.singleOrNull { it.isInstalled } + val testFramework = PythonTestFrameworkMapper.handleUnknown(settings.testFramework) + currentFrameworkItem = installedTestFramework ?: testFramework updateTestFrameworksList() } diff --git a/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/settings/PythonTestFrameworkMapper.kt b/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/settings/PythonTestFrameworkMapper.kt new file mode 100644 index 0000000000..57d8383441 --- /dev/null +++ b/utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/settings/PythonTestFrameworkMapper.kt @@ -0,0 +1,31 @@ +package org.utbot.intellij.plugin.language.python.settings + +import org.utbot.framework.codegen.domain.TestFramework +import org.utbot.intellij.plugin.settings.TestFrameworkMapper +import org.utbot.python.framework.codegen.PythonTestFrameworkManager +import org.utbot.python.framework.codegen.model.Pytest +import org.utbot.python.framework.codegen.model.Unittest + +object PythonTestFrameworkMapper: TestFrameworkMapper { + override fun toString(value: TestFramework): String = value.id + + override fun fromString(value: String): TestFramework = when (value) { + Unittest.id -> Unittest + Pytest.id -> Pytest + else -> error("Unknown TestFramework $value") + } + + override fun handleUnknown(testFramework: TestFramework): TestFramework { + if (allItems.contains(testFramework)) { + return testFramework + } + return try { + fromString(testFramework.id) + } catch (ex: IllegalStateException) { + defaultItem + } + } + + val defaultItem: TestFramework get() = PythonTestFrameworkManager().defaultTestFramework + val allItems: List get() = PythonTestFrameworkManager().testFrameworks +} \ No newline at end of file diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/JavaTestFrameworkMapper.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/JavaTestFrameworkMapper.kt new file mode 100644 index 0000000000..e3aee633cf --- /dev/null +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/JavaTestFrameworkMapper.kt @@ -0,0 +1,28 @@ +package org.utbot.intellij.plugin.settings + +import org.utbot.framework.codegen.domain.Junit4 +import org.utbot.framework.codegen.domain.Junit5 +import org.utbot.framework.codegen.domain.TestFramework +import org.utbot.framework.codegen.domain.TestNg + +object JavaTestFrameworkMapper : TestFrameworkMapper { + override fun toString(value: TestFramework): String = value.id + + override fun fromString(value: String): TestFramework = when (value) { + Junit4.id -> Junit4 + Junit5.id -> Junit5 + TestNg.id -> TestNg + else -> error("Unknown TestFramework $value") + } + + override fun handleUnknown(testFramework: TestFramework): TestFramework { + if (TestFramework.allItems.contains(testFramework)) { + return testFramework + } + return try { + fromString(testFramework.id) + } catch (ex: IllegalStateException) { + TestFramework.defaultItem + } + } +} \ No newline at end of file diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt index 185824a927..012d1814c6 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt @@ -114,6 +114,7 @@ import org.utbot.intellij.plugin.models.springBootTestLibraryDescriptor import org.utbot.intellij.plugin.models.springTestLibraryDescriptor import org.utbot.intellij.plugin.models.testNgNewLibraryDescriptor import org.utbot.intellij.plugin.models.testNgOldLibraryDescriptor +import org.utbot.intellij.plugin.settings.JavaTestFrameworkMapper import org.utbot.intellij.plugin.settings.Settings import org.utbot.intellij.plugin.settings.loadStateFromModel import org.utbot.intellij.plugin.ui.components.CodeGenerationSettingItemRenderer @@ -851,10 +852,11 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m codegenLanguages.item = model.codegenLanguage val installedTestFramework = TestFramework.allItems.singleOrNull { it.isInstalled } + val testFramework = JavaTestFrameworkMapper.handleUnknown(settings.testFramework) currentFrameworkItem = when (parametrizedTestSources.isSelected) { - false -> installedTestFramework ?: settings.testFramework + false -> installedTestFramework ?: testFramework true -> installedTestFramework - ?: if (settings.testFramework != Junit4) settings.testFramework else TestFramework.parametrizedDefaultItem + ?: if (testFramework != Junit4) testFramework else TestFramework.parametrizedDefaultItem } springTestsType.item = if (isSpringConfigSelected()) settings.springTestsType else SpringTestsType.defaultItem diff --git a/utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/settings/CommonSettings.kt b/utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/settings/CommonSettings.kt index 3b33253091..edfec90095 100644 --- a/utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/settings/CommonSettings.kt +++ b/utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/settings/CommonSettings.kt @@ -36,6 +36,7 @@ import java.util.concurrent.CompletableFuture import kotlin.reflect.KClass import org.utbot.common.isWindows import org.utbot.framework.SummariesGenerationType +import org.utbot.framework.codegen.domain.UnknownTestFramework import org.utbot.framework.plugin.api.SpringTestsType import org.utbot.framework.plugin.api.isSummarizationCompatible @@ -252,13 +253,13 @@ class Settings(val project: Project) : PersistentStateComponent // use it to serialize testFramework in State private class TestFrameworkConverter : Converter() { - override fun toString(value: TestFramework): String = "$value" + override fun toString(value: TestFramework): String = value.id override fun fromString(value: String): TestFramework = when (value) { Junit4.id -> Junit4 Junit5.id -> Junit5 TestNg.id -> TestNg - else -> error("Unknown TestFramework $value") + else -> UnknownTestFramework(value) } } diff --git a/utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/settings/TestFrameworkMapper.kt b/utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/settings/TestFrameworkMapper.kt new file mode 100644 index 0000000000..79c290b82e --- /dev/null +++ b/utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/settings/TestFrameworkMapper.kt @@ -0,0 +1,9 @@ +package org.utbot.intellij.plugin.settings + +import org.utbot.framework.codegen.domain.TestFramework + +interface TestFrameworkMapper { + fun toString(value: TestFramework): String + fun fromString(value: String): TestFramework + fun handleUnknown(testFramework: TestFramework): TestFramework +} \ No newline at end of file