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

Mockito-inline dependency after upgrade 5.0.0 #2877

Closed
EugenMayer opened this issue Jan 18, 2023 · 6 comments · Fixed by #2945
Closed

Mockito-inline dependency after upgrade 5.0.0 #2877

EugenMayer opened this issue Jan 18, 2023 · 6 comments · Fixed by #2945

Comments

@EugenMayer
Copy link

After reading that mockito switched to mockito-inline by default (with 5.0.0) i expected either mockito-core to have a mockito-inline dependency, or mockito-inline has been merged into mockito-core.

Interestingly neither of this is the case (since mockito-inline has a 5.0.0 release and no mockito-inline transitive dependency is found in https://mvnrepository.com/artifact/org.mockito/mockito-core/5.0.0 )

The concrete question is, how should we go about the current explicit dependency on mockito-inline. Should it be removed with 5.0.0 or should it stay?

@TimvdLippe
Copy link
Contributor

Good question. For explicitness, you can still depend on mockito-inline, but behaviourally it will have no effect. It would be similar if you would use mockito-subclass on Mockito 4. That said, I guess we can remove it in the next release, as it was only used during the transition period for Mockito 5. Not sure if we should simply stop publishing the artifact or we consider that a breaking change for the BOM. @raphw WDYT?

@raphw
Copy link
Member

raphw commented Jan 23, 2023

I would also say that we remove it. Typically, you'd depend on standard Mockito but we wanted to give a simple pom choice to switch the default as it normally is related to a project's setup. Mockito core contains all code for all mock-makers, but its a configuration file that defines what mock maker is used.

@TimvdLippe
Copy link
Contributor

Okay, in that case we should remove mockito-inline as our subproject (

"inline",
) and the actual subproject (https://github.com/mockito/mockito/tree/main/subprojects/inline)

valfirst added a commit to valfirst/saucerest-java that referenced this issue Jan 27, 2023
As of Mockito 5.0.0 the default mockmaker was switched to `mockito-inline`: https://github.com/mockito/mockito/releases/tag/v5.0.0.

More details and discussions: mockito/mockito#2877.
@EugenMayer
Copy link
Author

Nice that the removal took the price here, since i also think this makes life easier for all sides IMHO. It is easier to maintain (less packages to publish), easier to upgrade for the user and easier in the dependency handling / docs too.

Thank you for working on that @valfirst !

@CharlelieBouvier
Copy link

What about performance issues. Bytecode injection is very slow compared to subclass. Why is this not mentioned si the changelog ?

krzyk added a commit to krzyk/mockito that referenced this issue Mar 16, 2023
krzyk added a commit to krzyk/mockito that referenced this issue Mar 17, 2023
krzyk added a commit to krzyk/mockito that referenced this issue Mar 17, 2023
krzyk added a commit to krzyk/mockito that referenced this issue Mar 17, 2023
krzyk added a commit to krzyk/mockito that referenced this issue Mar 17, 2023
krzyk added a commit to krzyk/mockito that referenced this issue Mar 18, 2023
TimvdLippe pushed a commit that referenced this issue Mar 18, 2023
The tests will remain in the new `inlineTest` subproject.

Fixes #2877
TiagoMSSantos pushed a commit to TiagoMSSantos/MobileRT that referenced this issue Apr 19, 2023
fp024 added a commit to fp024/struts2-study that referenced this issue Apr 22, 2023
- mockito-inline 디펜던시 제거
  mockito 5.3.0 부터 mocktio-core에 통합된 것 같다.
  > * https://github.com/mockito/mockito/releases/tag/v5.3.0
  > * mockito/mockito#2877
fp024 added a commit to fp024/spring-5-recipes-study that referenced this issue Apr 22, 2023
- mockito-inline 디펜던시 제거
  mockito 5.3.0 부터 mocktio-core에 통합된 것 같다.
  > * https://github.com/mockito/mockito/releases/tag/v5.3.0
  > * mockito/mockito#2877
mklinkj added a commit to mklinkj/the-art-of-java-web-programming-study that referenced this issue Apr 22, 2023
- mockito-inline 디펜던시 제거
  mockito 5.3.0 부터 mocktio-core에 통합된 것 같다.
  > * https://github.com/mockito/mockito/releases/tag/v5.3.0
  > * mockito/mockito#2877
yrodiere added a commit to yrodiere/quarkus-github-lottery that referenced this issue May 30, 2023
yrodiere added a commit to yrodiere/hibernate-github-bot that referenced this issue May 30, 2023
yrodiere added a commit to hibernate/hibernate-github-bot that referenced this issue May 30, 2023
@dhrubo-os
Copy link

I tried :

testImplementation group: 'org.mockito', name: 'mockito-core', version: '5.5.0'

and

testImplementation group: 'org.mockito', name: 'mockito-inline', version: '5.2.0'

But both cases I'm facing issue like:

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.
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.

My code is:

    try (MockedStatic<RestActionUtils> loader = Mockito.mockStatic(RestActionUtils.class)) {
            loader.when(() -> RestActionUtils.isSuperAdminUser(clusterService, client)).thenReturn(true);
        }

where isSuperAdminUser is a static method

Any guidance will be helpful. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants