Skip to content

Commit 825b853

Browse files
committedOct 5, 2022
Improve verification that static mocking is configured
1 parent 1260c8f commit 825b853

File tree

2 files changed

+13
-13
lines changed

2 files changed

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

@@ -1011,14 +1010,15 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
10111010
.map { f -> Paths.get(urlToPath(f.url)) }
10121011
}
10131012

1014-
return entriesPaths.all { path ->
1015-
if (Files.exists(path)) {
1016-
val fileNames = Files.walk(path).map { it.fileName }.toList()
1017-
fileNames.any { it.toString() == MOCKITO_MOCKMAKER_FILE_NAME }
1018-
} else {
1019-
false
1013+
return entriesPaths.all { entryPath ->
1014+
if (!Files.exists(entryPath)) return false
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
10201021
}
1021-
}
10221022
}
10231023
}
10241024

0 commit comments

Comments
 (0)