@@ -11,37 +11,36 @@ import com.intellij.ui.layout.labelTable
11
11
import com.intellij.ui.layout.panel
12
12
import com.intellij.ui.layout.slider
13
13
import com.intellij.ui.layout.withValueBinding
14
+ import com.intellij.util.ui.UIUtil
15
+ import javax.swing.DefaultComboBoxModel
16
+ import javax.swing.JCheckBox
17
+ import javax.swing.JLabel
18
+ import javax.swing.JPanel
19
+ import kotlin.reflect.KClass
14
20
import org.utbot.framework.UtSettings
15
21
import org.utbot.framework.codegen.ForceStaticMocking
16
22
import org.utbot.framework.codegen.HangingTestsTimeout
17
23
import org.utbot.framework.codegen.RuntimeExceptionTestsBehaviour
18
24
import org.utbot.framework.plugin.api.CodeGenerationSettingItem
19
25
import org.utbot.framework.plugin.api.CodegenLanguage
20
- import org.utbot.framework.plugin.api.MockStrategyApi
21
26
import org.utbot.framework.plugin.api.TreatOverflowAsError
22
- import javax.swing.DefaultComboBoxModel
23
- import javax.swing.JLabel
24
- import javax.swing.JPanel
25
- import kotlin.reflect.KClass
26
27
27
- @Suppress(" UNCHECKED_CAST" )
28
28
class SettingsWindow (val project : Project ) {
29
29
private val settings = project.service<Settings >()
30
+
30
31
// TODO it is better to use something like SearchEverywhere for classes but it is complicated to implement
31
32
private val excludeTable = MockAlwaysClassesTable (project)
33
+ private lateinit var forceMockCheckBox: JCheckBox
32
34
33
35
val panel: JPanel = panel {
34
36
val valuesComboBox: LayoutBuilder .(KClass <* >, Array <* >) -> Unit = { loader, values ->
35
37
val serviceLabels = mapOf (
36
- MockStrategyApi ::class to "Mock strategy:",
37
- CodegenLanguage ::class to "Language generation:",
38
+ CodegenLanguage ::class to "Generated test language:",
38
39
RuntimeExceptionTestsBehaviour ::class to "Test with exceptions:",
39
- ForceStaticMocking ::class to "Force static mocking:",
40
40
TreatOverflowAsError ::class to "Overflow detection:",
41
41
)
42
-
43
- val serviceComments = mapOf (
44
- RuntimeExceptionTestsBehaviour ::class to "Test behavior when runtime exception occurs",
42
+ val tooltipLabels = mapOf (
43
+ CodegenLanguage ::class to "You can generate test methods in Java or Kotlin regardless of your source code language."
45
44
)
46
45
47
46
row(serviceLabels[loader] ? : error(" Unknown service loader: $loader " )) {
@@ -50,24 +49,12 @@ class SettingsWindow(val project: Project) {
50
49
DefaultComboBoxModel (values),
51
50
getter = { settings.providerNameByServiceLoader(loader) },
52
51
setter = { settings.setProviderByLoader(loader, it as CodeGenerationSettingItem ) },
53
- ).apply {
54
- val comment = serviceComments[loader]
55
- if (comment != null ) {
56
- ContextHelpLabel .create(comment)()
57
- }
58
- }
52
+ ).apply { ContextHelpLabel .create(tooltipLabels[loader] ? : return @apply)() }
59
53
}
60
54
}
61
55
}
62
56
63
- mapOf (
64
- MockStrategyApi ::class to MockStrategyApi .values(),
65
- CodegenLanguage ::class to CodegenLanguage .values(),
66
- RuntimeExceptionTestsBehaviour ::class to RuntimeExceptionTestsBehaviour .values(),
67
- TreatOverflowAsError ::class to TreatOverflowAsError .values()
68
- ).forEach { (loader, values) ->
69
- valuesComboBox(loader, values)
70
- }
57
+ valuesComboBox(CodegenLanguage ::class , CodegenLanguage .values())
71
58
72
59
row(" Hanging test timeout:" ) {
73
60
cell {
@@ -76,26 +63,62 @@ class SettingsWindow(val project: Project) {
76
63
settings.hangingTestsTimeout.timeoutMs
77
64
.coerceIn(HangingTestsTimeout .MIN_TIMEOUT_MS , HangingTestsTimeout .MAX_TIMEOUT_MS ).toInt()
78
65
},
79
- setter = { settings.hangingTestsTimeout = HangingTestsTimeout (it.toLong()) },
66
+ setter = {
67
+ settings.hangingTestsTimeout = HangingTestsTimeout (it.toLong())
68
+ },
80
69
minValue = HangingTestsTimeout .MIN_TIMEOUT_MS .toInt(),
81
70
maxValue = HangingTestsTimeout .MAX_TIMEOUT_MS .toInt(),
82
71
step = 50 ,
83
72
)
84
- comment(" milliseconds" )
73
+
74
+ label(" milliseconds" )
75
+ .apply {
76
+ ContextHelpLabel .create(
77
+ " Test generation may hang due to infinite loops or other code conditions. " +
78
+ " Set timeout to stop waiting for hanging process."
79
+ )()
80
+ }
85
81
}
86
82
}
87
-
88
83
mapOf (
89
- ForceStaticMocking ::class to ForceStaticMocking .values(),
84
+ RuntimeExceptionTestsBehaviour ::class to RuntimeExceptionTestsBehaviour .values(),
85
+ TreatOverflowAsError ::class to TreatOverflowAsError .values()
90
86
).forEach { (loader, values) ->
91
87
valuesComboBox(loader, values)
92
88
}
93
89
90
+
91
+
94
92
row {
95
- excludeTable.component(CCFlags .grow)
93
+ cell {
94
+ forceMockCheckBox = checkBox(" Force mocking static methods" )
95
+ .onApply {
96
+ settings.state.forceStaticMocking =
97
+ if (forceMockCheckBox.isSelected) ForceStaticMocking .FORCE else ForceStaticMocking .DO_NOT_FORCE
98
+ }
99
+ .onReset { forceMockCheckBox.isSelected = settings.forceStaticMocking == ForceStaticMocking .FORCE }
100
+ .onIsModified { forceMockCheckBox.isSelected xor (settings.forceStaticMocking != ForceStaticMocking .DO_NOT_FORCE ) }
101
+ .apply { ContextHelpLabel .create(" Overrides other mocking settings" )() }
102
+ .component
103
+ }
104
+ }
105
+
106
+ row(" Classes to be forcedly mocked:" ) {}
107
+ row {
108
+ val excludeTableCellBuilder = excludeTable.component(CCFlags .grow)
109
+ val updater = Runnable {
110
+ UIUtil .setEnabled(excludeTableCellBuilder.component, forceMockCheckBox.isSelected, true )
111
+ }
112
+ excludeTableCellBuilder
96
113
.onApply { excludeTable.apply () }
97
- .onReset { excludeTable.reset() }
114
+ .onReset {
115
+ excludeTable.reset()
116
+ updater.run ()
117
+ }
98
118
.onIsModified { excludeTable.isModified() }
119
+ forceMockCheckBox.addActionListener { updater.run () }
120
+
121
+
99
122
}
100
123
101
124
row(" Code analysis:" ) {
@@ -128,4 +151,4 @@ class SettingsWindow(val project: Project) {
128
151
excludeTable.reset()
129
152
(panel as DialogPanel ).reset()
130
153
}
131
- }
154
+ }
0 commit comments