From 92fa6c6a1b71a38b47b10436c9efe5463e48a5ab Mon Sep 17 00:00:00 2001 From: Egor Kulikov Date: Tue, 14 Mar 2023 09:54:07 +0300 Subject: [PATCH 1/2] Fix wrong mocking configuration --- .../org/utbot/framework/plugin/api/Api.kt | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt index f3a53670cd..2600208fb8 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt @@ -1155,12 +1155,25 @@ class WildcardTypeParameter : TypeParameters(emptyList()) * @param staticsMockingIsConfigured shows if we have installed static mocking tools */ open class StandardApplicationContext( - val mockFrameworkInstalled: Boolean = true, + mockFrameworkInstalled: Boolean = true, val staticsMockingIsConfigured: Boolean = true, ) { + var mockFrameworkInstalled = mockFrameworkInstalled + private set + init { - if (!mockFrameworkInstalled) { - require(!staticsMockingIsConfigured) { "Static mocking cannot be used without mock framework" } + /** + * Situation when mock framework is not installed but static mocking is configured is semantically incorrect. + * + * However, it may be obtained in real application after this actions: + * - fully configure mocking (dependency installed + resource file created) + * - remove mockito-core dependency from project + * - forget to remove mock-maker file from resource directory + * + * Here we transform this configuration to semantically correct. + */ + if (!mockFrameworkInstalled && staticsMockingIsConfigured) { + this.mockFrameworkInstalled = false } } } From dedf210d04b24197f1befc68ca237d4182164f16 Mon Sep 17 00:00:00 2001 From: Egor Kulikov Date: Tue, 14 Mar 2023 10:04:31 +0300 Subject: [PATCH 2/2] Fix previous implementation --- .../src/main/kotlin/org/utbot/framework/plugin/api/Api.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt index 2600208fb8..977719ba19 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt @@ -1155,10 +1155,10 @@ class WildcardTypeParameter : TypeParameters(emptyList()) * @param staticsMockingIsConfigured shows if we have installed static mocking tools */ open class StandardApplicationContext( - mockFrameworkInstalled: Boolean = true, - val staticsMockingIsConfigured: Boolean = true, + val mockFrameworkInstalled: Boolean = true, + staticsMockingIsConfigured: Boolean = true, ) { - var mockFrameworkInstalled = mockFrameworkInstalled + var staticsMockingIsConfigured = staticsMockingIsConfigured private set init { @@ -1173,7 +1173,7 @@ open class StandardApplicationContext( * Here we transform this configuration to semantically correct. */ if (!mockFrameworkInstalled && staticsMockingIsConfigured) { - this.mockFrameworkInstalled = false + this.staticsMockingIsConfigured = false } } }