Skip to content

Commit ff827eb

Browse files
committed
Improve verification that static mocking is configured
1 parent f83f62c commit ff827eb

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/util/DependencyPatterns.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,6 @@ val mockitoPatterns = listOf(MOCKITO_JAR_PATTERN, MOCKITO_MVN_PATTERN)
8787
val MOCKITO_BASIC_MODULE_PATTERN = Regex("mockito-core")
8888
val mockitoModulePatterns = listOf(MOCKITO_BASIC_MODULE_PATTERN)
8989

90-
const val MOCKITO_EXTENSIONS_STORAGE = "mockito-extensions"
90+
const val MOCKITO_EXTENSIONS_FOLDER = "mockito-extensions"
9191
const val MOCKITO_MOCKMAKER_FILE_NAME = "org.mockito.plugins.MockMaker"
92-
val MOCKITO_EXTENSIONS_FILE_CONTENT = listOf("mock-maker-inline")
92+
val MOCKITO_EXTENSIONS_FILE_CONTENT = "mock-maker-inline"

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt

+11-10
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ import org.utbot.framework.codegen.StaticsMocking
109109
import org.utbot.framework.codegen.TestFramework
110110
import org.utbot.framework.codegen.TestNg
111111
import org.utbot.framework.codegen.model.util.MOCKITO_EXTENSIONS_FILE_CONTENT
112-
import org.utbot.framework.codegen.model.util.MOCKITO_EXTENSIONS_STORAGE
112+
import org.utbot.framework.codegen.model.util.MOCKITO_EXTENSIONS_FOLDER
113113
import org.utbot.framework.codegen.model.util.MOCKITO_MOCKMAKER_FILE_NAME
114114
import org.utbot.framework.plugin.api.CodeGenerationSettingItem
115115
import org.utbot.framework.plugin.api.CodegenLanguage
@@ -762,15 +762,15 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
762762
* for further details.
763763
*/
764764
private fun configureMockitoResources(testResourcesPath: Path) {
765-
val mockitoExtensionsPath = "$testResourcesPath/$MOCKITO_EXTENSIONS_STORAGE".toPath()
765+
val mockitoExtensionsPath = "$testResourcesPath/$MOCKITO_EXTENSIONS_FOLDER".toPath()
766766
val mockitoMockMakerPath = "$mockitoExtensionsPath/$MOCKITO_MOCKMAKER_FILE_NAME".toPath()
767767

768768
if (!testResourcesPath.exists()) Files.createDirectory(testResourcesPath)
769769
if (!mockitoExtensionsPath.exists()) Files.createDirectory(mockitoExtensionsPath)
770770

771771
if (!mockitoMockMakerPath.exists()) {
772772
Files.createFile(mockitoMockMakerPath)
773-
Files.write(mockitoMockMakerPath, MOCKITO_EXTENSIONS_FILE_CONTENT)
773+
Files.write(mockitoMockMakerPath, listOf(MOCKITO_EXTENSIONS_FILE_CONTENT))
774774
}
775775
}
776776

@@ -1027,14 +1027,15 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
10271027
.map { f -> Paths.get(urlToPath(f.url)) }
10281028
}
10291029

1030-
return entriesPaths.all { path ->
1031-
if (Files.exists(path)) {
1032-
val fileNames = Files.walk(path).map { it.fileName }.toList()
1033-
fileNames.any { it.toString() == MOCKITO_MOCKMAKER_FILE_NAME }
1034-
} else {
1035-
false
1030+
return entriesPaths.all { entryPath ->
1031+
if (!Files.exists(entryPath)) return false
1032+
1033+
val mockMakerPath = "$entryPath/$MOCKITO_EXTENSIONS_FOLDER/$MOCKITO_MOCKMAKER_FILE_NAME".toPath()
1034+
if (!Files.exists(mockMakerPath)) return false
1035+
1036+
val fileLines = Files.readAllLines(mockMakerPath)
1037+
fileLines.singleOrNull() == MOCKITO_EXTENSIONS_FILE_CONTENT
10361038
}
1037-
}
10381039
}
10391040
}
10401041

0 commit comments

Comments
 (0)