Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings revision, 2nd iteration #977 #1088

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1154,12 +1154,12 @@ enum class MockStrategyApi(
NO_MOCKS("No mocks", "Do not mock", "Do not use mock frameworks at all"),
OTHER_PACKAGES(
"Other packages: Mockito",
"Mock package environment",
"Mock everything outside the package",
"Mock all classes outside the current package except system ones"
),
OTHER_CLASSES(
"Other classes: Mockito",
"Mock class environment",
"Mock everything outside the class",
"Mock all classes outside the class under test except system ones"
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,9 @@ object TestNg : TestFramework(id = "TestNG",displayName = "TestNG") {
""".trimIndent()
}

object Junit4 : TestFramework(id = "JUnit4",displayName = "JUnit4") {
object Junit4 : TestFramework(id = "JUnit4",displayName = "JUnit 4") {
private val parametrizedTestsNotSupportedError: Nothing
get() = error("Parametrized tests are not supported for JUnit4")
get() = error("Parametrized tests are not supported for JUnit 4")

override val mainPackage: String = JUNIT4_PACKAGE
override val testAnnotation = "@$mainPackage.Test"
Expand Down Expand Up @@ -453,7 +453,7 @@ object Junit4 : TestFramework(id = "JUnit4",displayName = "JUnit4") {
}
}

object Junit5 : TestFramework(id = "JUnit5", displayName = "JUnit5") {
object Junit5 : TestFramework(id = "JUnit5", displayName = "JUnit 5") {
override val mainPackage: String = JUNIT5_PACKAGE
override val testAnnotation = "@$mainPackage.Test"
override val testAnnotationFqn: String = "$mainPackage.Test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ class SettingsWindow(val project: Project) {
step = 50,
)

label("milliseconds")
label("milliseconds per method")
.apply {
ContextHelpLabel.create(
"Test generation may hang due to infinite loops or other code conditions. " +
"Set timeout to stop waiting for hanging process."
"Set this timeout to define which test is \"hanging\". Increase it to test the " +
"time-consuming method or decrease if the execution speed is critical for you."
)()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import com.intellij.util.ui.UIUtil
import com.intellij.util.ui.components.BorderLayoutPanel
import java.awt.BorderLayout
import java.awt.Color
import java.awt.Dimension
import java.awt.event.ActionEvent
import java.nio.file.Files
import java.nio.file.Path
Expand All @@ -90,6 +91,8 @@ import javax.swing.JComboBox
import javax.swing.JComponent
import javax.swing.JList
import javax.swing.JPanel
import javax.swing.JSpinner
import javax.swing.text.DefaultFormatter
import kotlin.streams.toList
import org.jetbrains.concurrency.Promise
import org.jetbrains.concurrency.thenRun
Expand Down Expand Up @@ -179,8 +182,16 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
MINIMUM_TIMEOUT_VALUE_IN_SECONDS,
Int.MAX_VALUE,
MINIMUM_TIMEOUT_VALUE_IN_SECONDS
)
private val parametrizedTestSources = JCheckBox("Parametrized tests")
).also {
when(val editor = it.editor) {
is JSpinner.DefaultEditor -> {
when(val formatter = editor.textField.formatter) {
is DefaultFormatter -> {formatter.allowsInvalid = false}
}
}
}
}
private val parametrizedTestSources = JCheckBox("Parameterized tests")

private lateinit var panel: DialogPanel

Expand All @@ -193,7 +204,16 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
)

private fun <T : CodeGenerationSettingItem> createComboBox(values: Array<T>) : ComboBox<T> {
return ComboBox<T>(DefaultComboBoxModel(values)).also {
val comboBox = object:ComboBox<T>(DefaultComboBoxModel(values)) {
var maxWidth = 0
//Don't shrink strategy
override fun getPreferredSize(): Dimension {
val size = super.getPreferredSize()
if (size.width > maxWidth) maxWidth = size.width
return size.apply { width = maxWidth }
}
}
return comboBox.also {
it.renderer = CodeGenerationSettingItemRenderer()
}
}
Expand Down Expand Up @@ -243,7 +263,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
@Suppress("UNCHECKED_CAST")
override fun createCenterPanel(): JComponent {
panel = panel {
row("Test source root:") {
row("Test sources root:") {
component(testSourceFolderField)
}
row("Testing framework:") {
Expand All @@ -253,25 +273,21 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
)
}
row { component(parametrizedTestSources) }
row("Mock strategy:") {
row("Mocking strategy:") {
makePanelWithHelpTooltip(
mockStrategies,
ContextHelpLabel.create("Mock everything around the target class or the whole package except the system classes. Otherwise mock nothing.")
ContextHelpLabel.create("Mock everything around the target class or the whole package except the system classes. " +
"Otherwise, mock nothing. Mockito will be installed, if you don't have one.")
)
}
row { component(staticsMocking)}
row("Test generation timeout:") {
cell{
cell {
component(timeoutSpinner)
label("seconds per class")
component(ContextHelpLabel.create("Set the timeout for all test generation processes per class to complete."))
}
}
row {
component(cbSpecifyTestPackage)
}.apply { visible = false }
row("Destination package:") {
component(testPackageField)
}.apply { visible = false }

row("Generate tests for:") {}
row {
Expand Down Expand Up @@ -380,7 +396,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
srcClasses.flatMap { it.extractFirstLevelMembers(false) }
} else {
srcClasses.map { MemberInfo(it) }
}
}.toSortedSet { o1, o2 -> o1.displayName.compareTo(o2.displayName, true) }

checkMembers(items)
membersTable.setMemberInfos(items)
Expand All @@ -392,7 +408,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
membersTable.preferredScrollableViewportSize = size(-1, height)
}

private fun checkMembers(allMembers: List<MemberInfo>) {
private fun checkMembers(allMembers: Collection<MemberInfo>) {
val selectedDisplayNames = model.selectedMembers.map { it.displayName }
val selectedMembers = allMembers.filter { it.displayName in selectedDisplayNames }

Expand Down