@@ -27,9 +27,11 @@ import com.intellij.openapi.ui.ComboBox
2727import com.intellij.openapi.ui.DialogPanel
2828import com.intellij.openapi.ui.DialogWrapper
2929import com.intellij.openapi.ui.Messages
30+ import com.intellij.openapi.ui.OptionAction
3031import com.intellij.openapi.ui.ValidationInfo
3132import com.intellij.openapi.ui.popup.IconButton
3233import com.intellij.openapi.util.Computable
34+ import com.intellij.openapi.util.text.TextWithMnemonic
3335import com.intellij.openapi.vfs.StandardFileSystems
3436import com.intellij.openapi.vfs.VfsUtil
3537import com.intellij.openapi.vfs.VfsUtilCore.urlToPath
@@ -40,7 +42,6 @@ import com.intellij.psi.PsiClass
4042import com.intellij.psi.PsiManager
4143import com.intellij.psi.PsiMethod
4244import com.intellij.psi.SyntheticElement
43- import com.intellij.psi.PsiModifier
4445import com.intellij.refactoring.PackageWrapper
4546import com.intellij.refactoring.ui.MemberSelectionTable
4647import com.intellij.refactoring.ui.PackageNameReferenceEditorCombo
@@ -75,11 +76,28 @@ import com.intellij.util.ui.JBUI.scale
7576import com.intellij.util.ui.JBUI.size
7677import com.intellij.util.ui.UIUtil
7778import com.intellij.util.ui.components.BorderLayoutPanel
79+ import java.awt.BorderLayout
80+ import java.awt.Color
81+ import java.awt.event.ActionEvent
82+ import java.nio.file.Files
83+ import java.nio.file.Path
84+ import java.nio.file.Paths
85+ import java.util.Objects
86+ import java.util.concurrent.TimeUnit
87+ import javax.swing.AbstractAction
88+ import javax.swing.Action
89+ import javax.swing.DefaultComboBoxModel
90+ import javax.swing.JButton
91+ import javax.swing.JComboBox
92+ import javax.swing.JComponent
93+ import javax.swing.JList
94+ import javax.swing.JPanel
95+ import kotlin.streams.toList
7896import org.jetbrains.concurrency.Promise
7997import org.jetbrains.concurrency.thenRun
8098import org.jetbrains.kotlin.asJava.classes.KtUltraLightClass
81- import org.utbot.common.filterWhen
8299import org.utbot.common.PathUtil.toPath
100+ import org.utbot.common.filterWhen
83101import org.utbot.framework.UtSettings
84102import org.utbot.framework.codegen.ForceStaticMocking
85103import org.utbot.framework.codegen.Junit4
@@ -116,20 +134,7 @@ import org.utbot.intellij.plugin.ui.utils.kotlinTargetPlatform
116134import org.utbot.intellij.plugin.ui.utils.parseVersion
117135import org.utbot.intellij.plugin.ui.utils.testResourceRootTypes
118136import org.utbot.intellij.plugin.ui.utils.testRootType
119- import org.utbot.intellij.plugin.util.AndroidApiHelper
120- import java.awt.BorderLayout
121- import java.awt.Color
122- import java.nio.file.Files
123- import java.nio.file.Path
124- import java.nio.file.Paths
125- import java.util.*
126- import java.util.concurrent.TimeUnit
127- import javax.swing.DefaultComboBoxModel
128- import javax.swing.JComboBox
129- import javax.swing.JComponent
130- import javax.swing.JList
131- import javax.swing.JPanel
132- import kotlin.streams.toList
137+ import org.utbot.intellij.plugin.util.IntelliJApiHelper
133138import org.utbot.intellij.plugin.util.isAbstract
134139
135140private const val RECENTS_KEY = " org.utbot.recents"
@@ -140,6 +145,9 @@ private const val WILL_BE_INSTALLED_LABEL = " (will be installed)"
140145private const val WILL_BE_CONFIGURED_LABEL = " (will be configured)"
141146private const val MINIMUM_TIMEOUT_VALUE_IN_SECONDS = 1
142147
148+ private const val ACTION_GENERATE = " Generate Tests"
149+ private const val ACTION_GENERATE_AND_RUN = " Generate && Run" // Note that ampersand has to be escaped (doubled)
150+
143151class GenerateTestsDialogWindow (val model : GenerateTestsModel ) : DialogWrapper(model.project) {
144152 companion object {
145153 const val minSupportedSdkVersion = 8
@@ -213,6 +221,8 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
213221 twm.getToolWindow(" Event Log" )?.activate(null )
214222 }
215223
224+ model.runGeneratedTestsWithCoverage = model.project.service<Settings >().runGeneratedTestsWithCoverage
225+
216226 init ()
217227 }
218228
@@ -302,7 +312,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
302312 override fun createTitlePane (): JComponent ? {
303313 val sdkVersion = findSdkVersion()
304314 // TODO:SAT-1571 investigate Android Studio specific sdk issues
305- if (sdkVersion?.feature in minSupportedSdkVersion.. maxSupportedSdkVersion || AndroidApiHelper .isAndroidStudio()) return null
315+ if (sdkVersion?.feature in minSupportedSdkVersion.. maxSupportedSdkVersion || IntelliJApiHelper .isAndroidStudio()) return null
306316 isOKActionEnabled = false
307317 return SdkNotificationPanel (model, sdkVersion)
308318 }
@@ -438,6 +448,45 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
438448 return null
439449 }
440450
451+ class OKOptionAction (val testsModel : GenerateTestsModel , val okAction : Action ) : AbstractAction(testsModel.getActionText()), OptionAction {
452+ init {
453+ putValue(DEFAULT_ACTION , java.lang.Boolean .TRUE )
454+ putValue(FOCUSED_ACTION , java.lang.Boolean .TRUE )
455+ }
456+ private val generateAction = object : AbstractAction (ACTION_GENERATE ) {
457+ override fun actionPerformed (e : ActionEvent ? ) {
458+ testsModel.runGeneratedTestsWithCoverage = false
459+ updateButtonText(e)
460+ }
461+ }
462+ private val generateAndRunAction = object : AbstractAction (ACTION_GENERATE_AND_RUN ) {
463+ override fun actionPerformed (e : ActionEvent ? ) {
464+ testsModel.runGeneratedTestsWithCoverage = true
465+ updateButtonText(e)
466+ }
467+ }
468+
469+ private fun updateButtonText (e : ActionEvent ? ) {
470+ with (e?.source as JButton ) {
471+ text = TextWithMnemonic .parse(testsModel.getActionText()).dropMnemonic().text
472+ testsModel.project.service<Settings >().runGeneratedTestsWithCoverage =
473+ testsModel.runGeneratedTestsWithCoverage
474+ repaint()
475+ }
476+ }
477+
478+ override fun actionPerformed (e : ActionEvent ? ) {
479+ okAction.actionPerformed(e)
480+ }
481+
482+ override fun getOptions (): Array <Action > {
483+ if (testsModel.runGeneratedTestsWithCoverage) return arrayOf(generateAndRunAction, generateAction)
484+ return arrayOf(generateAction, generateAndRunAction)
485+ }
486+ }
487+
488+ private val okOptionAction: OKOptionAction get() = OKOptionAction (model, super .getOKAction())
489+ override fun getOKAction () = okOptionAction
441490
442491 override fun doOKAction () {
443492 model.testPackageName =
@@ -964,6 +1013,9 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
9641013 }
9651014}
9661015
1016+ fun GenerateTestsModel.getActionText () : String =
1017+ if (this .runGeneratedTestsWithCoverage) ACTION_GENERATE_AND_RUN else ACTION_GENERATE
1018+
9671019private fun ComboBox<CodeGenerationSettingItem>.setHelpTooltipTextChanger (helpLabel : JBLabel ) {
9681020 addActionListener { event ->
9691021 val comboBox = event.source as ComboBox <* >
0 commit comments