@@ -10,9 +10,9 @@ import com.intellij.openapi.command.WriteCommandAction
10
10
import com.intellij.openapi.components.service
11
11
import com.intellij.openapi.editor.colors.EditorColorsManager
12
12
import com.intellij.openapi.module.Module
13
+ import com.intellij.openapi.module.ModuleUtil
13
14
import com.intellij.openapi.options.ShowSettingsUtil
14
15
import com.intellij.openapi.projectRoots.JavaSdkVersion
15
- import com.intellij.openapi.roots.ContentEntry
16
16
import com.intellij.openapi.roots.DependencyScope
17
17
import com.intellij.openapi.roots.ExternalLibraryDescriptor
18
18
import com.intellij.openapi.roots.JavaProjectModelModificationService
@@ -423,12 +423,14 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
423
423
return null
424
424
}
425
425
426
+ private fun VirtualFile.toRealFile ():VirtualFile = if (this is FakeVirtualFile ) this .parent else this
427
+
426
428
override fun doValidate (): ValidationInfo ? {
427
429
val testRoot = getTestRoot()
428
430
? : return ValidationInfo (" Test source root is not configured" , testSourceFolderField.childComponent)
429
431
430
- if (! model.project.isBuildWithGradle && findReadOnlyContentEntry (testRoot) == null ) {
431
- return ValidationInfo (" Test source root is located out of content entry " , testSourceFolderField.childComponent)
432
+ if (! model.project.isBuildWithGradle && ModuleUtil .findModuleForFile (testRoot.toRealFile(), model.project ) == null ) {
433
+ return ValidationInfo (" Test source root is located out of any module " , testSourceFolderField.childComponent)
432
434
}
433
435
434
436
membersTable.tableHeader?.background = UIUtil .getTableBackground()
@@ -606,16 +608,6 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
606
608
" Generation error"
607
609
)
608
610
609
- private fun findReadOnlyContentEntry (testSourceRoot : VirtualFile ? ): ContentEntry ? {
610
- if (testSourceRoot == null ) return null
611
- if (testSourceRoot is FakeVirtualFile ) {
612
- return findReadOnlyContentEntry(testSourceRoot.parent)
613
- }
614
- return ModuleRootManager .getInstance(model.testModule).contentEntries
615
- .filterNot { it.file == null }
616
- .firstOrNull { VfsUtil .isAncestor(it.file!! , testSourceRoot, false ) }
617
- }
618
-
619
611
private fun getOrCreateTestRoot (testSourceRoot : VirtualFile ): Boolean {
620
612
val modifiableModel = ModuleRootManager .getInstance(model.testModule).modifiableModel
621
613
try {
0 commit comments