Skip to content

Fix wrong mocking configuration #1942

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

Merged
merged 2 commits into from
Mar 14, 2023
Merged
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 @@ -1156,11 +1156,24 @@ class WildcardTypeParameter : TypeParameters(emptyList())
*/
open class StandardApplicationContext(
val mockFrameworkInstalled: Boolean = true,
val staticsMockingIsConfigured: Boolean = true,
staticsMockingIsConfigured: Boolean = true,
) {
var staticsMockingIsConfigured = staticsMockingIsConfigured
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.staticsMockingIsConfigured = false
}
}
}
Expand Down