@@ -10,9 +10,9 @@ import com.intellij.openapi.command.WriteCommandAction
1010import com.intellij.openapi.components.service
1111import com.intellij.openapi.editor.colors.EditorColorsManager
1212import com.intellij.openapi.module.Module
13+ import com.intellij.openapi.module.ModuleUtil
1314import com.intellij.openapi.options.ShowSettingsUtil
1415import com.intellij.openapi.projectRoots.JavaSdkVersion
15- import com.intellij.openapi.roots.ContentEntry
1616import com.intellij.openapi.roots.DependencyScope
1717import com.intellij.openapi.roots.ExternalLibraryDescriptor
1818import com.intellij.openapi.roots.JavaProjectModelModificationService
@@ -423,12 +423,14 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
423423 return null
424424 }
425425
426+ private fun VirtualFile.toRealFile ():VirtualFile = if (this is FakeVirtualFile ) this .parent else this
427+
426428 override fun doValidate (): ValidationInfo ? {
427429 val testRoot = getTestRoot()
428430 ? : return ValidationInfo (" Test source root is not configured" , testSourceFolderField.childComponent)
429431
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)
432434 }
433435
434436 membersTable.tableHeader?.background = UIUtil .getTableBackground()
@@ -606,16 +608,6 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
606608 " Generation error"
607609 )
608610
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-
619611 private fun getOrCreateTestRoot (testSourceRoot : VirtualFile ): Boolean {
620612 val modifiableModel = ModuleRootManager .getInstance(model.testModule).modifiableModel
621613 try {
0 commit comments