From ab136c500a32f4fc11f228a4cef02c3d37326863 Mon Sep 17 00:00:00 2001 From: Ivan Volkov Date: Fri, 15 Jul 2022 16:12:06 +0300 Subject: [PATCH 1/2] Improve plugin behavior classes/packages with no methods --- .../plugin/generator/UtTestsDialogProcessor.kt | 10 ++++++++++ .../intellij/plugin/ui/actions/GenerateTestsAction.kt | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt index ab357d3aef..afac7c755f 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt @@ -13,6 +13,7 @@ import com.intellij.openapi.progress.ProgressIndicator import com.intellij.openapi.progress.Task import com.intellij.openapi.project.Project import com.intellij.openapi.roots.OrderEnumerator +import com.intellij.openapi.ui.Messages import com.intellij.openapi.util.text.StringUtil import com.intellij.psi.PsiClass import com.intellij.refactoring.util.classMembers.MemberInfo @@ -215,6 +216,15 @@ object UtTestsDialogProcessor { processedClasses++ } + if (processedClasses == 0) { + invokeLater { + Messages.showInfoMessage( + model.project, + "No methods for test generation were found among selected items", + "No methods found") + } + } + indicator.fraction = indicator.fraction.coerceAtLeast(0.9) indicator.text = "Generate code for tests" // Commented out to generate tests for collected executions even if action was canceled. diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/actions/GenerateTestsAction.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/actions/GenerateTestsAction.kt index 7e4d60357e..65dcb81f53 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/actions/GenerateTestsAction.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/actions/GenerateTestsAction.kt @@ -54,7 +54,7 @@ class GenerateTestsAction : AnAction() { val matchingRoot = ModuleRootManager.getInstance(module).contentEntries .flatMap { entry -> entry.sourceFolders.toList() } .singleOrNull { folder -> folder.file == srcSourceRoot } - if (matchingRoot == null || matchingRoot.rootType.isForTests) { + if (srcMethods.isEmpty() || matchingRoot == null || matchingRoot.rootType.isForTests) { return null } From c163ae6af795134c1792611728f8ac3fe7572f48 Mon Sep 17 00:00:00 2001 From: Ivan Volkov Date: Mon, 18 Jul 2022 10:55:02 +0300 Subject: [PATCH 2/2] Added return after "No methods found" warning in ui --- .../utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt index afac7c755f..3f2cc26e79 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt @@ -223,6 +223,7 @@ object UtTestsDialogProcessor { "No methods for test generation were found among selected items", "No methods found") } + return } indicator.fraction = indicator.fraction.coerceAtLeast(0.9)