Skip to content

Commit 6444031

Browse files
committed
Improve verification that static mocking is configured
1 parent c42e9f4 commit 6444031

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
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

+9-5
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ import javax.swing.JComboBox
9090
import javax.swing.JComponent
9191
import javax.swing.JList
9292
import javax.swing.JPanel
93-
import kotlin.streams.toList
9493
import org.jetbrains.concurrency.Promise
9594
import org.jetbrains.concurrency.thenRun
9695
import org.jetbrains.kotlin.asJava.classes.KtUltraLightClass
@@ -106,7 +105,7 @@ import org.utbot.framework.codegen.StaticsMocking
106105
import org.utbot.framework.codegen.TestFramework
107106
import org.utbot.framework.codegen.TestNg
108107
import org.utbot.framework.codegen.model.util.MOCKITO_EXTENSIONS_FILE_CONTENT
109-
import org.utbot.framework.codegen.model.util.MOCKITO_EXTENSIONS_STORAGE
108+
import org.utbot.framework.codegen.model.util.MOCKITO_EXTENSIONS_FOLDER
110109
import org.utbot.framework.codegen.model.util.MOCKITO_MOCKMAKER_FILE_NAME
111110
import org.utbot.framework.plugin.api.CodeGenerationSettingItem
112111
import org.utbot.framework.plugin.api.CodegenLanguage
@@ -746,15 +745,15 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
746745
* for further details.
747746
*/
748747
private fun configureMockitoResources(testResourcesPath: Path) {
749-
val mockitoExtensionsPath = "$testResourcesPath/$MOCKITO_EXTENSIONS_STORAGE".toPath()
748+
val mockitoExtensionsPath = "$testResourcesPath/$MOCKITO_EXTENSIONS_FOLDER".toPath()
750749
val mockitoMockMakerPath = "$mockitoExtensionsPath/$MOCKITO_MOCKMAKER_FILE_NAME".toPath()
751750

752751
if (!testResourcesPath.exists()) Files.createDirectory(testResourcesPath)
753752
if (!mockitoExtensionsPath.exists()) Files.createDirectory(mockitoExtensionsPath)
754753

755754
if (!mockitoMockMakerPath.exists()) {
756755
Files.createFile(mockitoMockMakerPath)
757-
Files.write(mockitoMockMakerPath, MOCKITO_EXTENSIONS_FILE_CONTENT)
756+
Files.write(mockitoMockMakerPath, listOf(MOCKITO_EXTENSIONS_FILE_CONTENT))
758757
}
759758
}
760759

@@ -1013,7 +1012,12 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
10131012

10141013
return entriesPaths.all { entryPath ->
10151014
if (!Files.exists(entryPath)) return false
1016-
Files.walk(entryPath).anyMatch { it.fileName.toString() == MOCKITO_MOCKMAKER_FILE_NAME }
1015+
1016+
val mockMakerPath = "$entryPath/$MOCKITO_EXTENSIONS_FOLDER/$MOCKITO_MOCKMAKER_FILE_NAME".toPath()
1017+
if (!Files.exists(mockMakerPath)) return false
1018+
1019+
val fileLines = Files.readAllLines(mockMakerPath)
1020+
fileLines.singleOrNull() == MOCKITO_EXTENSIONS_FILE_CONTENT
10171021
}
10181022
}
10191023
}

0 commit comments

Comments
 (0)