- Notifications
You must be signed in to change notification settings - Fork 45
Force mocking without mock framework installed fix #278
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions 21 utbot-framework/src/main/kotlin/org/utbot/engine/util/mockListeners/ForceMockListener.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package org.utbot.engine.util.mockListeners | ||
| import org.utbot.engine.EngineController | ||
| import org.utbot.engine.MockStrategy | ||
| import org.utbot.engine.util.mockListeners.exceptions.ForceMockCancellationException | ||
| | ||
| /** | ||
| * Listener for mocker events in [org.utbot.engine.UtBotSymbolicEngine]. | ||
| * If forced mock happened, cancels the engine job. | ||
| * | ||
| * Supposed to be created only if Mockito is not installed. | ||
| */ | ||
| class ForceMockListener: MockListener { | ||
| var forceMockHappened = false | ||
| private set | ||
| | ||
| override fun onShouldMock(controller: EngineController, strategy: MockStrategy) { | ||
| // If force mocking happened -- сancel engine job | ||
| controller.job?.cancel(ForceMockCancellationException()) | ||
| forceMockHappened = true | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions 11 utbot-framework/src/main/kotlin/org/utbot/engine/util/mockListeners/MockListener.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package org.utbot.engine.util.mockListeners | ||
| | ||
| import org.utbot.engine.EngineController | ||
| import org.utbot.engine.MockStrategy | ||
| | ||
| /** | ||
| * Listener that can be attached using [MockListenerController] to mocker in [org.utbot.engine.UtBotSymbolicEngine]. | ||
| */ | ||
| interface MockListener { | ||
| fun onShouldMock(controller: EngineController, strategy: MockStrategy) | ||
| } |
19 changes: 19 additions & 0 deletions 19 ...t-framework/src/main/kotlin/org/utbot/engine/util/mockListeners/MockListenerController.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package org.utbot.engine.util.mockListeners | ||
| | ||
| import org.utbot.engine.EngineController | ||
| import org.utbot.engine.MockStrategy | ||
| | ||
| /** | ||
| * Controller that allows to attach listeners to mocker in [org.utbot.engine.UtBotSymbolicEngine]. | ||
| */ | ||
| class MockListenerController(private val controller: EngineController) { | ||
| val listeners = mutableListOf<MockListener>() | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What other listeners except | ||
| | ||
| fun attach(listener: MockListener) { | ||
| listeners += listener | ||
| } | ||
| | ||
| fun onShouldMock(strategy: MockStrategy) { | ||
| listeners.map { it.onShouldMock(controller, strategy) } | ||
| } | ||
| } | ||
8 changes: 8 additions & 0 deletions 8 ...n/kotlin/org/utbot/engine/util/mockListeners/exceptions/ForceMockCancellationException.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package org.utbot.engine.util.mockListeners.exceptions | ||
| | ||
| import kotlinx.coroutines.CancellationException | ||
| | ||
| /** | ||
| * Exception used in [org.utbot.engine.util.mockListeners.ForceMockListener]. | ||
| */ | ||
| class ForceMockCancellationException: CancellationException("Forced mocks without Mockito") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions 47 utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/ConfigureWindowCommon.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package org.utbot.intellij.plugin.ui | ||
| | ||
| import com.intellij.openapi.module.Module | ||
| import com.intellij.openapi.project.Project | ||
| import com.intellij.openapi.roots.DependencyScope | ||
| import com.intellij.openapi.roots.ExternalLibraryDescriptor | ||
| import com.intellij.openapi.roots.JavaProjectModelModificationService | ||
| import com.intellij.openapi.ui.Messages | ||
| import org.jetbrains.concurrency.Promise | ||
| import org.utbot.framework.plugin.api.MockFramework | ||
| import org.utbot.intellij.plugin.ui.utils.LibrarySearchScope | ||
| import org.utbot.intellij.plugin.ui.utils.findFrameworkLibrary | ||
| import org.utbot.intellij.plugin.ui.utils.parseVersion | ||
| | ||
| fun createMockFrameworkNotificationDialog(title: String) = Messages.showYesNoDialog( | ||
| """Mock framework ${MockFramework.MOCKITO.displayName} is not installed into current module. | ||
| |Would you like to install it now?""".trimMargin(), | ||
| title, | ||
| "Yes", | ||
| "No", | ||
| Messages.getQuestionIcon(), | ||
| ) | ||
| | ||
| fun configureMockFramework(project: Project, module: Module) { | ||
| val selectedMockFramework = MockFramework.MOCKITO | ||
| | ||
| val libraryInProject = | ||
| findFrameworkLibrary(project, module, selectedMockFramework, LibrarySearchScope.Project) | ||
| val versionInProject = libraryInProject?.libraryName?.parseVersion() | ||
| | ||
| selectedMockFramework.isInstalled = true | ||
| addDependency(project, module, mockitoCoreLibraryDescriptor(versionInProject)) | ||
| .onError { selectedMockFramework.isInstalled = false } | ||
| } | ||
| | ||
| /** | ||
| * Adds the dependency for selected framework via [JavaProjectModelModificationService]. | ||
| * | ||
| * Note that version restrictions will be applied only if they are present on target machine | ||
| * Otherwise latest release version will be installed. | ||
| */ | ||
| fun addDependency(project: Project, module: Module, libraryDescriptor: ExternalLibraryDescriptor): Promise<Void> { | ||
| return JavaProjectModelModificationService | ||
| .getInstance(project) | ||
| //this method returns JetBrains internal Promise that is difficult to deal with, but it is our way | ||
| .addDependency(module, libraryDescriptor, DependencyScope.TEST) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's avoid public setter on it