🌐
Maven Repository
mvnrepository.com › artifact › org.mockito › mockito-inline
Maven Repository: org.mockito » mockito-inline
March 9, 2023 - Mockito preconfigured inline mock maker (intermediate and to be superseeded by automatic usage in a future version)
🌐
GitHub
github.com › mockito › mockito › issues › 2272
mockito-inline failed to mock · Issue #2272 · mockito/mockito
April 21, 2021 - Without using mockito-inline, the failing test works. I need mockito-inline for a test that mocks static class, but this ruins other tests. Mockito cannot mock this class: class pse.shop.product.description.DescriptionElement. If you're not sure why you're getting this error, please report to the mailing list.
Author   cdalexndr
🌐
GitHub
github.com › mockito › mockito › issues › 3328
Tests failures after adding mockito-inline on Java 21 · Issue #3328 · mockito/mockito
April 27, 2024 - It appears that Mockito cannot mock several classes after adding mockito-inline dependency to the project · Mockito cannot mock this class: class org.apache.http.impl.client.CloseableHttpClient. If you're not sure why you're getting this error, please open an issue on GitHub.
Author   MikhailNavitski
🌐
Stack Overflow
stackoverflow.com › questions › 70797537 › dependency-org-mockitomockito-inline3-8-0-not-found
java - Dependency 'org.mockito:mockito-inline:3.8.0' not found - Stack Overflow
It can be activated explicitly by the mockito extension mechanism, just create in the classpath a file /mockito-extensions/org.mockito.plugins.MockMaker containing the value mock-maker-inline. So I would suggest you to create that file, also you can refer to this section in the Official Mockito Documentation
🌐
GitHub
github.com › mockito › mockito › issues › 3039
Mockito BOM doesn't include `mockito-inline` · Issue #3039 · mockito/mockito
June 15, 2023 - Unfortunately unless I'm mistaken it looks like the Mockito BOM does not include org.mockito:mockito-inline.
Author   garretwilson
🌐
GitHub
github.com › mockito › mockito › issues › 2877
Mockito-inline dependency after upgrade 5.0.0 · Issue #2877 · mockito/mockito
January 18, 2023 - 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 )
Author   EugenMayer
🌐
GitHub
github.com › quarkusio › quarkus › issues › 32952
Quarkus 3 : mockito-inline don't work anymore after upgrade · Issue #32952 · quarkusio/quarkus
April 27, 2023 - Caused by: java.lang.IllegalSt... the Instrumentation API. You can simply enable this mock mode, by placing the 'mockito-inline' artifact where you are currently using 'mockito-core'....
Author   fmarissel
🌐
GitHub
github.com › mockito › mockito › issues › 2082
'this' is not available - when enabling mock-maker-inline · Issue #2082 · mockito/mockito
October 28, 2020 - When we enable mock-maker-inline in our project and debug a class with @Spy annotated on it IntelliJ reports that 'this' is not available: When we unset mock-maker-inline then things work as expected and we can inspect the class variables: It appears to be the same as this report: https://stackoverflow.com/questions/62661996/unable-to-debug-junit-test-anywhere · Is this expected Mockito behaviour?
Author   leonroy
🌐
GitHub
github.com › mockito › mockito › issues › 2436
mockito-inline on OpenJDK 17 fails to start due to ByteBuddy agent failure · Issue #2436 · mockito/mockito
September 26, 2021 - It appears that GraalVM JDK 17 does not allow inline mocks of final classes to be made using mockito-inline or by adding the mockito inline extension file. org.mockito.exceptions.base.MockitoInitializationException: Could not initialize ...
Author   ascopes
🌐
GitHub
github.com › mockito › mockito › issues › 1083
Mockito 2 mock-maker-inline not able to mock Object methods on an interface · Issue #1083 · mockito/mockito
May 15, 2017 - It appears to be that the inline mock maker cannot mock Object methods on an interface, using a class (HashSet for the below example) or mockito-core instead of mockito-inline makes it work.
Published   May 15, 2017
Author   mina-asham
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › tagged › mockito-inline
Newest 'mockito-inline' Questions - Stack Overflow
I'm having issues getting mockito-inline to handle a case that I would encounter when using PowerMock; mocking a construction, but only when certain arguments are in the construction. For example ... ... Context: We are using Junit 5, Spring-Boot 2.6.3 Spring-Boot comes with its dependency on mockito-core Problem I am looking to create a mock for a static method.
🌐
Davidvlijmincx
davidvlijmincx.com › posts › writing_higher_quality_tests_with_mockitos_inline_mock_maker
How to use the Mockito's inline mock maker
July 30, 2024 - If you are using Mockito 4 you need to do some extra work to enable the mock-maker-inline. There are a few ways of doing this. I listed the options below. Add this dependency in your pom. Create a resources directory in your test directory if you do not have one.
🌐
Google Groups
groups.google.com › g › mockito › c › -JbyoOdLNtw
Mockito Inline Fails with "Java.lang.ExceptionInitializerError"
I have tried to implement the solution for mocking final classes using the Mockito version "org.mockito:mockito-core:2.+". There are a few problems: When I use the solution linked above, I get the error (see withResourcesFolder file): ... When I remove the solution, I get the original error ([ ] are my addition) (see withoutResourcesFolder): Cannot mock/spy class [multiple classes cannot be mocked] ... I've also noticed that when I get this error the issue is not always that the class is final or an anonymous class or a primitive type...
🌐
GitHub
github.com › mockito › mockito › issues › 3042
mockito-inline on Oracle 17 and Amazon Correto 17 fails to start because cannot initialize inline ByteBuddy mock maker · Issue #3042 · mockito/mockito
June 20, 2023 - mockito-inline on Oracle 17 and Amazon Correto 17 fails to start because cannot initialize inline ByteBuddy mock maker#3042
Author   plmakoc
Top answer
1 of 9
70

Weird that your solution seems to work.
According to their documentation on Github it says.

Mocking of final classes and methods is an incubating, opt-in feature. It uses a combination of Java agent instrumentation and subclassing in order to enable mockability of these types. As this works differently to our current mechanism and this one has different limitations and as we want to gather experience and user feedback, this feature had to be explicitly activated to be available ; it can be done via the mockito extension mechanism by creating the file src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker containing a single line:

mock-maker-inline

After you created this file, Mockito will automatically use this new engine and one can do :

 final class FinalClass {
   final String finalMethod() { return "something"; }
 }

 FinalClass concrete = new FinalClass(); 

 FinalClass mock = mock(FinalClass.class);
 given(mock.finalMethod()).willReturn("not anymore");

 assertThat(mock.finalMethod()).isNotEqualTo(concrete.finalMethod());

In subsequent milestones, the team will bring a programmatic way of using this feature. We will identify and provide support for all unmockable scenarios. Stay tuned and please let us know what you think of this feature!

My working structure now looks like this.

2 of 9
36

I couldn't get it working with the configuration file either; however, the Mockito team is so kind and also provides a pre-configured Mockito artifact that requires no configuration in the target project.

As a convenience, the Mockito team provides an artifact where this mock maker is preconfigured. Instead of using the mockito-core artifact, include the mockito-inline artifact in your project. Note that this artifact is likely to be discontinued once mocking of final classes and methods gets integrated into the default mock maker.

So, if you use Gradle and want to test your Kotlin code, just add this to your project's dependencies:

testCompile 'org.mockito:mockito-inline:2.8.9'
testCompile('com.nhaarman:mockito-kotlin:1.5.0') {
    exclude group: 'org.jetbrains.kotlin'
    exclude group: 'org.mockito'
}
🌐
GitHub
github.com › mockito › mockito › issues › 2499
Obscure issue with mockito-inline: mock object in a test seems to be corrupting mock in later test · Issue #2499 · mockito/mockito
December 7, 2021 - The issue is that the constructor for MyClass is not being called when mocking the TestSubInterface in Test2 (I guess because mockito-inline still sees MyClass as a mock from the previous test?).
Author   smas321
🌐
GitHub
github.com › mockito › mockito › issues › 1943
Mockito-inline fails to choose correct method to mock for Kotlin classes with "reified" methods in Java tests · Issue #1943 · mockito/mockito
June 3, 2020 - Create the file resources/mockito-extensions/org.mockito.plugins.MockMaker with content mock-maker-inline so that final Kotlin classes can be mocked
Author   juv
🌐
GitHub
github.com › mockito › mockito › issues › 929
New 'mockito-inline' artifact does not work · Issue #929 · mockito/mockito
April 2, 2017 - mockito-extensions/org.mockito.plugins.MockMaker is not included in the mockito-inline.jar. $ jar tvf mockito-inline-2.7.2.jar 0 Sat Feb 04 12:02:54 JST 2017 META-INF/ 25 Sat Feb 04 12:02:54 JST 2017 META-INF/MANIFEST.MF · In the inline subproject, org.mockito.plugins.MockMaker is in src/resources/mockito-extensions directory.
🌐
Maven Central
central.sonatype.com › artifact › org.mockito › mockito-inline
Maven Central: org.mockito:mockito-inline
<dependency> <groupId>org.mockito</groupId> <artifactId>mockito-inline</artifactId> <version>5.2.0</version> </dependency>