File tree Expand file tree Collapse file tree 7 files changed +102
-6
lines changed
utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain
utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin
utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python
utbot-ui-commons/src/main/kotlin/org/utbot/intellij/plugin/settings Expand file tree Collapse file tree 7 files changed +102
-6
lines changed Original file line number Diff line number Diff line change @@ -256,6 +256,29 @@ abstract class TestFramework(
256
256
}
257
257
}
258
258
259
+ class UnknownTestFramework (id : String ) : TestFramework(id = id, displayName = id) {
260
+ override val mainPackage: String = id
261
+ override val assertionsClass: ClassId = ClassId (id)
262
+ override val arraysAssertionsClass: ClassId = ClassId (id)
263
+ override val kotlinFailureAssertionsClass: ClassId = ClassId (id)
264
+ override val testAnnotationId: ClassId = ClassId (id)
265
+ override val beforeMethodId: ClassId = ClassId (id)
266
+ override val afterMethodId: ClassId = ClassId (id)
267
+ override val parameterizedTestAnnotationId: ClassId = ClassId (id)
268
+ override val methodSourceAnnotationId: ClassId = ClassId (id)
269
+ override val nestedClassesShouldBeStatic: Boolean = false
270
+ override val argListClassId: ClassId = ClassId (id)
271
+
272
+ override fun getRunTestsCommand (
273
+ executionInvoke : String ,
274
+ classPath : String ,
275
+ classesNames : List <String >,
276
+ buildDirectory : String ,
277
+ additionalArguments : List <String >
278
+ ): List <String > = emptyList()
279
+
280
+ }
281
+
259
282
object TestNg : TestFramework(id = " TestNG" ,displayName = " TestNG" ) {
260
283
override val mainPackage: String = TEST_NG_PACKAGE
261
284
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import com.jetbrains.python.psi.PyClass
16
16
import com.jetbrains.python.psi.PyFunction
17
17
import org.utbot.framework.codegen.domain.ProjectType
18
18
import org.utbot.framework.codegen.domain.TestFramework
19
+ import org.utbot.intellij.plugin.language.python.settings.PythonTestFrameworkMapper
19
20
import org.utbot.intellij.plugin.language.python.settings.loadStateFromModel
20
21
import org.utbot.intellij.plugin.language.python.table.UtPyClassItem
21
22
import org.utbot.intellij.plugin.language.python.table.UtPyFunctionItem
@@ -93,8 +94,9 @@ class PythonDialogWindow(val model: PythonTestsModel) : DialogWrapper(model.proj
93
94
private fun initDefaultValues () {
94
95
val settings = model.project.service<Settings >()
95
96
96
- val installedTestFramework = TestFramework .allItems.singleOrNull { it.isInstalled }
97
- currentFrameworkItem = installedTestFramework ? : settings.testFramework
97
+ val installedTestFramework = PythonTestFrameworkMapper .allItems.singleOrNull { it.isInstalled }
98
+ val testFramework = PythonTestFrameworkMapper .handleUnknown(settings.testFramework)
99
+ currentFrameworkItem = installedTestFramework ? : testFramework
98
100
99
101
updateTestFrameworksList()
100
102
}
Original file line number Diff line number Diff line change
1
+ package org.utbot.intellij.plugin.language.python.settings
2
+
3
+ import org.utbot.framework.codegen.domain.TestFramework
4
+ import org.utbot.intellij.plugin.settings.TestFrameworkMapper
5
+ import org.utbot.python.framework.codegen.PythonTestFrameworkManager
6
+ import org.utbot.python.framework.codegen.model.Pytest
7
+ import org.utbot.python.framework.codegen.model.Unittest
8
+
9
+ object PythonTestFrameworkMapper: TestFrameworkMapper {
10
+ override fun toString (value : TestFramework ): String = value.id
11
+
12
+ override fun fromString (value : String ): TestFramework = when (value) {
13
+ Unittest .id -> Unittest
14
+ Pytest .id -> Pytest
15
+ else -> error(" Unknown TestFramework $value " )
16
+ }
17
+
18
+ override fun handleUnknown (testFramework : TestFramework ): TestFramework {
19
+ if (allItems.contains(testFramework)) {
20
+ return testFramework
21
+ }
22
+ return try {
23
+ fromString(testFramework.id)
24
+ } catch (ex: IllegalStateException ) {
25
+ defaultItem
26
+ }
27
+ }
28
+
29
+ val defaultItem: TestFramework get() = PythonTestFrameworkManager ().defaultTestFramework
30
+ val allItems: List <TestFramework > get() = PythonTestFrameworkManager ().testFrameworks
31
+ }
Original file line number Diff line number Diff line change
1
+ package org.utbot.intellij.plugin.settings
2
+
3
+ import org.utbot.framework.codegen.domain.Junit4
4
+ import org.utbot.framework.codegen.domain.Junit5
5
+ import org.utbot.framework.codegen.domain.TestFramework
6
+ import org.utbot.framework.codegen.domain.TestNg
7
+
8
+ object JavaTestFrameworkMapper : TestFrameworkMapper {
9
+ override fun toString (value : TestFramework ): String = value.id
10
+
11
+ override fun fromString (value : String ): TestFramework = when (value) {
12
+ Junit4 .id -> Junit4
13
+ Junit5 .id -> Junit5
14
+ TestNg .id -> TestNg
15
+ else -> error(" Unknown TestFramework $value " )
16
+ }
17
+
18
+ override fun handleUnknown (testFramework : TestFramework ): TestFramework {
19
+ if (TestFramework .allItems.contains(testFramework)) {
20
+ return testFramework
21
+ }
22
+ return try {
23
+ fromString(testFramework.id)
24
+ } catch (ex: IllegalStateException ) {
25
+ TestFramework .defaultItem
26
+ }
27
+ }
28
+ }
Original file line number Diff line number Diff line change @@ -114,6 +114,7 @@ import org.utbot.intellij.plugin.models.springBootTestLibraryDescriptor
114
114
import org.utbot.intellij.plugin.models.springTestLibraryDescriptor
115
115
import org.utbot.intellij.plugin.models.testNgNewLibraryDescriptor
116
116
import org.utbot.intellij.plugin.models.testNgOldLibraryDescriptor
117
+ import org.utbot.intellij.plugin.settings.JavaTestFrameworkMapper
117
118
import org.utbot.intellij.plugin.settings.Settings
118
119
import org.utbot.intellij.plugin.settings.loadStateFromModel
119
120
import org.utbot.intellij.plugin.ui.components.CodeGenerationSettingItemRenderer
@@ -851,10 +852,11 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
851
852
codegenLanguages.item = model.codegenLanguage
852
853
853
854
val installedTestFramework = TestFramework .allItems.singleOrNull { it.isInstalled }
855
+ val testFramework = JavaTestFrameworkMapper .handleUnknown(settings.testFramework)
854
856
currentFrameworkItem = when (parametrizedTestSources.isSelected) {
855
- false -> installedTestFramework ? : settings. testFramework
857
+ false -> installedTestFramework ? : testFramework
856
858
true -> installedTestFramework
857
- ? : if (settings. testFramework != Junit4 ) settings. testFramework else TestFramework .parametrizedDefaultItem
859
+ ? : if (testFramework != Junit4 ) testFramework else TestFramework .parametrizedDefaultItem
858
860
}
859
861
860
862
springTestsType.item = if (isSpringConfigSelected()) settings.springTestsType else SpringTestsType .defaultItem
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ import java.util.concurrent.CompletableFuture
36
36
import kotlin.reflect.KClass
37
37
import org.utbot.common.isWindows
38
38
import org.utbot.framework.SummariesGenerationType
39
+ import org.utbot.framework.codegen.domain.UnknownTestFramework
39
40
import org.utbot.framework.plugin.api.SpringTestsType
40
41
import org.utbot.framework.plugin.api.isSummarizationCompatible
41
42
@@ -252,13 +253,13 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
252
253
253
254
// use it to serialize testFramework in State
254
255
private class TestFrameworkConverter : Converter <TestFramework >() {
255
- override fun toString (value : TestFramework ): String = " $ value"
256
+ override fun toString (value : TestFramework ): String = value.id
256
257
257
258
override fun fromString (value : String ): TestFramework = when (value) {
258
259
Junit4 .id -> Junit4
259
260
Junit5 .id -> Junit5
260
261
TestNg .id -> TestNg
261
- else -> error( " Unknown TestFramework $ value" )
262
+ else -> UnknownTestFramework ( value)
262
263
}
263
264
}
264
265
Original file line number Diff line number Diff line change
1
+ package org.utbot.intellij.plugin.settings
2
+
3
+ import org.utbot.framework.codegen.domain.TestFramework
4
+
5
+ interface TestFrameworkMapper {
6
+ fun toString (value : TestFramework ): String
7
+ fun fromString (value : String ): TestFramework
8
+ fun handleUnknown (testFramework : TestFramework ): TestFramework
9
+ }
You can’t perform that action at this time.
0 commit comments