Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve verification that static mocking is configured #1091

Merged
merged 2 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ val mockitoPatterns = listOf(MOCKITO_JAR_PATTERN, MOCKITO_MVN_PATTERN)
val MOCKITO_BASIC_MODULE_PATTERN = Regex("mockito-core")
val mockitoModulePatterns = listOf(MOCKITO_BASIC_MODULE_PATTERN)

const val MOCKITO_EXTENSIONS_STORAGE = "mockito-extensions"
const val MOCKITO_EXTENSIONS_FOLDER = "mockito-extensions"
const val MOCKITO_MOCKMAKER_FILE_NAME = "org.mockito.plugins.MockMaker"
val MOCKITO_EXTENSIONS_FILE_CONTENT = listOf("mock-maker-inline")
val MOCKITO_EXTENSIONS_FILE_CONTENT = "mock-maker-inline"
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ import org.utbot.framework.codegen.StaticsMocking
import org.utbot.framework.codegen.TestFramework
import org.utbot.framework.codegen.TestNg
import org.utbot.framework.codegen.model.util.MOCKITO_EXTENSIONS_FILE_CONTENT
import org.utbot.framework.codegen.model.util.MOCKITO_EXTENSIONS_STORAGE
import org.utbot.framework.codegen.model.util.MOCKITO_EXTENSIONS_FOLDER
import org.utbot.framework.codegen.model.util.MOCKITO_MOCKMAKER_FILE_NAME
import org.utbot.framework.plugin.api.CodeGenerationSettingItem
import org.utbot.framework.plugin.api.CodegenLanguage
Expand Down Expand Up @@ -762,15 +762,15 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
* for further details.
*/
private fun configureMockitoResources(testResourcesPath: Path) {
val mockitoExtensionsPath = "$testResourcesPath/$MOCKITO_EXTENSIONS_STORAGE".toPath()
val mockitoExtensionsPath = "$testResourcesPath/$MOCKITO_EXTENSIONS_FOLDER".toPath()
val mockitoMockMakerPath = "$mockitoExtensionsPath/$MOCKITO_MOCKMAKER_FILE_NAME".toPath()

if (!testResourcesPath.exists()) Files.createDirectory(testResourcesPath)
if (!mockitoExtensionsPath.exists()) Files.createDirectory(mockitoExtensionsPath)

if (!mockitoMockMakerPath.exists()) {
Files.createFile(mockitoMockMakerPath)
Files.write(mockitoMockMakerPath, MOCKITO_EXTENSIONS_FILE_CONTENT)
Files.write(mockitoMockMakerPath, listOf(MOCKITO_EXTENSIONS_FILE_CONTENT))
}
}

Expand Down Expand Up @@ -1027,14 +1027,20 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
.map { f -> Paths.get(urlToPath(f.url)) }
}

return entriesPaths.all { path ->
if (Files.exists(path)) {
val fileNames = Files.walk(path).map { it.fileName }.toList()
fileNames.any { it.toString() == MOCKITO_MOCKMAKER_FILE_NAME }
} else {
false
return entriesPaths.all { entryPath ->
if (!Files.exists(entryPath)) return false

val mockMakerPath = "$entryPath/$MOCKITO_EXTENSIONS_FOLDER/$MOCKITO_MOCKMAKER_FILE_NAME".toPath()
if (!Files.exists(mockMakerPath)) return false

try {
val fileLines = Files.readAllLines(mockMakerPath)
fileLines.singleOrNull() == MOCKITO_EXTENSIONS_FILE_CONTENT
} catch (e: java.io.IOException) {
return false
}

}
}
}
}

Expand Down