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

IllegalArgumentException: Static mocking cannot be used without mock framework #1936

Closed
tyuldashev opened this issue Mar 13, 2023 · 0 comments · Fixed by #1942
Closed

IllegalArgumentException: Static mocking cannot be used without mock framework #1936

tyuldashev opened this issue Mar 13, 2023 · 0 comments · Fixed by #1942
Assignees
Labels
comp-codegen Issue is related to code generator ctg-bug Issue is a bug

Comments

@tyuldashev
Copy link
Collaborator

Description
In case user generates tests with mocking static methods and later removes dependency on Mockito then tests can not generated any more.

To Reproduce

Steps to reproduce the behavior:

  1. Create new Java project
  2. Create or copy some Java class there, for instance copy org.utbot.examples.exceptions.ExceptionExamples from UTBot Java project.
  3. Invoke test generation on that class with enabled:
    • Mock everything outside the class
    • Mock static methods
  4. After tests are generated remove added dependency on Mockito from Gradle/Maven config file. That's emulate situation when user doesn't want mocks in the project anymore.
  5. Invoke test generation again with "Do not mock" option now

Expected behavior

Test without mocks are generated.

Actual behavior

Exception is thrown at first execution. No tests are generated.

Visual proofs (screenshots, logs, images)

Exception thrown:

java.lang.IllegalArgumentException: Static mocking cannot be used without mock framework
	at org.utbot.framework.plugin.api.StandardApplicationContext.<init>(Api.kt:1163)
	at org.utbot.intellij.plugin.generator.UtTestsDialogProcessor$createTests$1$1.run(UtTestsDialogProcessor.kt:173)
	at com.intellij.openapi.progress.impl.CoreProgressManager.startTask(CoreProgressManager.java:442)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.startTask(ProgressManagerImpl.java:114)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcessWithProgressAsynchronously$5(CoreProgressManager.java:493)
	at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$3(ProgressRunner.java:244)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:189)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$12(CoreProgressManager.java:608)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:683)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:639)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:607)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:176)
	at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:244)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
	at java.base/java.lang.Thread.run(Thread.java:829)

Additional context
The problem is in resources/mockito-extensions/org.mockito.plugins.MockMaker file generated at step #3, should user remove it then no problems occur.

@tyuldashev tyuldashev added ctg-bug Issue is a bug comp-codegen Issue is related to code generator labels Mar 13, 2023
@EgorkaKulikov EgorkaKulikov linked a pull request Mar 14, 2023 that will close this issue
6 tasks
@github-project-automation github-project-automation bot moved this from Todo to Done in UTBot Java Mar 14, 2023
denis-fokin pushed a commit that referenced this issue Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-codegen Issue is related to code generator ctg-bug Issue is a bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants