Skip to content

Commit b39d01a

Browse files
Improve settings, part 1 (#898)
1 parent eb1bb8a commit b39d01a

File tree

6 files changed

+118
-107
lines changed

6 files changed

+118
-107
lines changed

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,13 +1053,13 @@ enum class MockStrategyApi(
10531053
override val displayName: String,
10541054
override val description: String
10551055
) : CodeGenerationSettingItem {
1056-
NO_MOCKS("No mocks", "Do not use mock frameworks at all"),
1056+
NO_MOCKS("Do not mock", "Do not use mock frameworks at all"),
10571057
OTHER_PACKAGES(
1058-
"Other packages: $MOCKITO",
1058+
"Mock package environment",
10591059
"Mock all classes outside the current package except system ones"
10601060
),
10611061
OTHER_CLASSES(
1062-
"Other classes: $MOCKITO",
1062+
"Mock class environment",
10631063
"Mock all classes outside the class under test except system ones"
10641064
);
10651065

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/Domain.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,11 @@ enum class RuntimeExceptionTestsBehaviour(
593593
override val description: String
594594
) : CodeGenerationSettingItem {
595595
PASS(
596-
displayName = "Passing",
596+
displayName = "Pass",
597597
description = "Tests that produce Runtime exceptions should pass (by inserting throwable assertion)"
598598
),
599599
FAIL(
600-
displayName = "Failing",
600+
displayName = "Fail",
601601
description = "Tests that produce Runtime exceptions should fail" +
602602
"(WARNING!: failing tests may appear in testing class)"
603603
);

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/SettingsWindow.kt

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,36 @@ import com.intellij.ui.layout.labelTable
1111
import com.intellij.ui.layout.panel
1212
import com.intellij.ui.layout.slider
1313
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
1420
import org.utbot.framework.UtSettings
1521
import org.utbot.framework.codegen.ForceStaticMocking
1622
import org.utbot.framework.codegen.HangingTestsTimeout
1723
import org.utbot.framework.codegen.RuntimeExceptionTestsBehaviour
1824
import org.utbot.framework.plugin.api.CodeGenerationSettingItem
1925
import org.utbot.framework.plugin.api.CodegenLanguage
20-
import org.utbot.framework.plugin.api.MockStrategyApi
2126
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
2627

27-
@Suppress("UNCHECKED_CAST")
2828
class 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

Comments
 (0)