@@ -11,37 +11,36 @@ import com.intellij.ui.layout.labelTable
1111import com.intellij.ui.layout.panel
1212import com.intellij.ui.layout.slider
1313import 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
1420import org.utbot.framework.UtSettings
1521import org.utbot.framework.codegen.ForceStaticMocking
1622import org.utbot.framework.codegen.HangingTestsTimeout
1723import org.utbot.framework.codegen.RuntimeExceptionTestsBehaviour
1824import org.utbot.framework.plugin.api.CodeGenerationSettingItem
1925import org.utbot.framework.plugin.api.CodegenLanguage
20- import org.utbot.framework.plugin.api.MockStrategyApi
2126import 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
2627
27- @Suppress(" UNCHECKED_CAST" )
2828class SettingsWindow (val project : Project ) {
2929 private val settings = project.service<Settings >()
30+
3031 // TODO it is better to use something like SearchEverywhere for classes but it is complicated to implement
3132 private val excludeTable = MockAlwaysClassesTable (project)
33+ private lateinit var forceMockCheckBox: JCheckBox
3234
3335 val panel: JPanel = panel {
3436 val valuesComboBox: LayoutBuilder .(KClass <* >, Array <* >) -> Unit = { loader, values ->
3537 val serviceLabels = mapOf (
36- MockStrategyApi ::class to "Mock strategy:",
37- CodegenLanguage ::class to "Language generation:",
38+ CodegenLanguage ::class to "Generated test language:",
3839 RuntimeExceptionTestsBehaviour ::class to "Test with exceptions:",
39- ForceStaticMocking ::class to "Force static mocking:",
4040 TreatOverflowAsError ::class to "Overflow detection:",
4141 )
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."
4544 )
4645
4746 row(serviceLabels[loader] ? : error(" Unknown service loader: $loader " )) {
@@ -50,24 +49,12 @@ class SettingsWindow(val project: Project) {
5049 DefaultComboBoxModel (values),
5150 getter = { settings.providerNameByServiceLoader(loader) },
5251 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)() }
5953 }
6054 }
6155 }
6256
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())
7158
7259 row(" Hanging test timeout:" ) {
7360 cell {
@@ -76,26 +63,62 @@ class SettingsWindow(val project: Project) {
7663 settings.hangingTestsTimeout.timeoutMs
7764 .coerceIn(HangingTestsTimeout .MIN_TIMEOUT_MS , HangingTestsTimeout .MAX_TIMEOUT_MS ).toInt()
7865 },
79- setter = { settings.hangingTestsTimeout = HangingTestsTimeout (it.toLong()) },
66+ setter = {
67+ settings.hangingTestsTimeout = HangingTestsTimeout (it.toLong())
68+ },
8069 minValue = HangingTestsTimeout .MIN_TIMEOUT_MS .toInt(),
8170 maxValue = HangingTestsTimeout .MAX_TIMEOUT_MS .toInt(),
8271 step = 50 ,
8372 )
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+ }
8581 }
8682 }
87-
8883 mapOf (
89- ForceStaticMocking ::class to ForceStaticMocking .values(),
84+ RuntimeExceptionTestsBehaviour ::class to RuntimeExceptionTestsBehaviour .values(),
85+ TreatOverflowAsError ::class to TreatOverflowAsError .values()
9086 ).forEach { (loader, values) ->
9187 valuesComboBox(loader, values)
9288 }
9389
90+
91+
9492 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
96113 .onApply { excludeTable.apply () }
97- .onReset { excludeTable.reset() }
114+ .onReset {
115+ excludeTable.reset()
116+ updater.run ()
117+ }
98118 .onIsModified { excludeTable.isModified() }
119+ forceMockCheckBox.addActionListener { updater.run () }
120+
121+
99122 }
100123
101124 row(" Code analysis:" ) {
@@ -128,4 +151,4 @@ class SettingsWindow(val project: Project) {
128151 excludeTable.reset()
129152 (panel as DialogPanel ).reset()
130153 }
131- }
154+ }
0 commit comments