Skip to content

Commit

Permalink
Improve plugin behavior classes/packages with no methods #516 (#533)
Browse files Browse the repository at this point in the history
  • Loading branch information
volivan239 authored Jul 18, 2022
1 parent 3d91def commit 4f9cc2e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -215,6 +216,16 @@ object UtTestsDialogProcessor {
processedClasses++
}

if (processedClasses == 0) {
invokeLater {
Messages.showInfoMessage(
model.project,
"No methods for test generation were found among selected items",
"No methods found")
}
return
}

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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 4f9cc2e

Please sign in to comment.