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

Quarkus 3 : mockito-inline don't work anymore after upgrade #32952

Closed
fmarissel opened this issue Apr 27, 2023 · 12 comments
Closed

Quarkus 3 : mockito-inline don't work anymore after upgrade #32952

fmarissel opened this issue Apr 27, 2023 · 12 comments
Labels
area/testing kind/bug Something isn't working

Comments

@fmarissel
Copy link

Describe the bug

After upgrading a project with :
curl -Ls https://sh.jbang.dev | bash -s - --fresh upgrade-to-quarkus3@quarkusio

Junit tests containing static mocks don't work anymore.
Same issue with new project initialized with Quarkus 3.

Caused by: java.lang.IllegalStateException: Cannot set up environment mocking:
The used MockMaker SubclassByteBuddyMockMaker does not support the creation of static mocks

Mockito's inline mock maker supports static mocks based on the Instrumentation API.
You can simply enable this mock mode, by placing the 'mockito-inline' artifact where you are currently using 'mockito-core'.
Note that Mockito's inline mock maker is not supported on Android.. This may be a result of not having the right mockito-inline installed, or may be down to a Java internals change.
at uk.org.webcompere.systemstubs.environment.EnvironmentVariableMocker.(EnvironmentVariableMocker.java:45)
... 66 more
Caused by: org.mockito.exceptions.base.MockitoException:
The used MockMaker SubclassByteBuddyMockMaker does not support the creation of static mocks

Mockito's inline mock maker supports static mocks based on the Instrumentation API.
You can simply enable this mock mode, by placing the 'mockito-inline' artifact where you are currently using 'mockito-core'.
Note that Mockito's inline mock maker is not supported on Android.
at uk.org.webcompere.systemstubs.environment.EnvironmentVariableMocker.(EnvironmentVariableMocker.java:29)
... 66 more

I am using uk.org.webcompere:system-stubs-core and uk.org.webcompere:system-stubs-core to mock environment variables.

You can pull my repo to reproduce :
https://github.com/fmarissel/quarkus3-mockito-inline

Expected behavior

No response

Actual behavior

No response

How to Reproduce?

https://github.com/fmarissel/quarkus3-mockito-inline

Output of uname -a or ver

Darwin FRL-HJ6N529V4W 22.4.0 Darwin Kernel Version 22.4.0: Mon Mar 6 20:59:28 PST 2023; root:xnu-8796.101.5~3/RELEASE_ARM64_T6000 arm64

Output of java -version

17

GraalVM version (if different from Java)

No response

Quarkus version or git rev

3.0.1.Final

Build tool (ie. output of mvnw --version or gradlew --version)

3.9.1

Additional information

No response

@fmarissel fmarissel added the kind/bug Something isn't working label Apr 27, 2023
@quarkus-bot quarkus-bot bot added the area/jbang Issues related to when using jbang.dev with Quarkus label Apr 27, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Apr 27, 2023

/cc @maxandersen (jbang), @quarkusio/devtools (jbang)

@famod famod added area/testing and removed area/jbang Issues related to when using jbang.dev with Quarkus labels Apr 28, 2023
@famod
Copy link
Member

famod commented Apr 28, 2023

Please try removing the mockito-inline dependency from your project.
Quarkus 3.0.1 uses Mockito 5.3.0 and from that version on there is no mockito-inline anymore: https://redirect.github.com/mockito/mockito/issues/2877

@aduursma
Copy link

aduursma commented May 1, 2023

It looks like Quarkus 3.0.1 is not using the latest 5.3.1 Mockito version, but still Mockito version 5.2.0.

Could that perhaps have to do with the issue related to the mockito-inline dependency?

@famod
Copy link
Member

famod commented May 1, 2023

It looks like Quarkus 3.0.1 is not using the latest 5.3.1 Mockito version, but still Mockito version 5.2.0.

You are right. I was mislead by #32554 (which did not touch the BOM).

Could that perhaps have to do with the issue related to the mockito-inline dependency?

This commit says it all: ed74dd7

I'll let @geoand take it from here.

@famod
Copy link
Member

famod commented May 1, 2023

PS: You can work around this by adding the following exclusion to quarkus-junit5-mockito:

      <exclusions>
        <exclusion>
          <groupId>org.mockito</groupId>
          <artifactId>mockito-subclass</artifactId>
        </exclusion>
      </exclusions>

and then add a dependency to mockito-core to your project.
You might then run into #31251 though.

@famod
Copy link
Member

famod commented May 2, 2023

@gsmet looks like @geoand is not around (?), so I'm asking you: Should we add something to the migration guide?
With Q3 it's not obvious:

  1. how to use inline until Quarkus properly supports it (see my workaround above), which is particularly irritating given that Mockito normally uses inline by default
  2. that you can run into situations like Quarkus 3, memory leak, NotAMockException when using mockito clearInlineMocks #31251 (once you've figured out how to use inline in the first place)

@geoand
Copy link
Contributor

geoand commented May 2, 2023

Yup, out for team meetings most of the week.

I'm gonna have a lot of catching up next week...

@gsmet
Copy link
Member

gsmet commented May 2, 2023

@famod does upgrading to Mockito 5.3 somehow fix the issue? If so, maybe we should do it in 3.0.2.Final.

@famod
Copy link
Member

famod commented May 2, 2023

@gsmet no, it doesn't.
Some might say updating to 5.3 makes it worse because there is no mockito-inline in Mockito 5.3+ anymore.
Personally I'd say it doesn't make much of a difference, given you'll have to fiddle around with exclusions and dependencies anyway (if you want inline behaviour).

@gsmet
Copy link
Member

gsmet commented May 2, 2023

@famod yeah so please let's add something to the migration guide. And we should probably stay away from upgrading Mockito to 5.3 then.
And hopefully, we will be able to improve the situation a bit in upcoming micros.

@famod
Copy link
Member

famod commented May 2, 2023

@famod yeah so please let's add something to the migration guide.

https://github.com/quarkusio/quarkus/wiki/Migration-Guide-3.0#fixation-of-the-mockito-subclass-mockmaker

And we should probably stay away from upgrading Mockito to 5.3 then. And hopefully, we will be able to improve the situation a bit in upcoming micros.

TBH, I personally would bring the mockito deps in sync already in 3.0.2 (5.3.1 everywhere including the BOM) but as you suggested I'll remove the backport label from #33037.

@HerrDerb
Copy link
Contributor

Should this be closed? 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/testing kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants