Skip to content

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

Closed
@tyuldashev

Description

@tyuldashev

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.

Metadata

Metadata

Assignees

Labels

comp-codegenIssue is related to code generatorctg-bugIssue is a bug

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions