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 Public API Support Roadmap #726

Closed
5 tasks done
thekingn0thing opened this issue Dec 1, 2016 · 14 comments
Closed
5 tasks done

Mockito Public API Support Roadmap #726

thekingn0thing opened this issue Dec 1, 2016 · 14 comments
Assignees
Labels

Comments

@thekingn0thing
Copy link
Member

thekingn0thing commented Dec 1, 2016

Powermock is heavily relying on the internal workings of Mockito. As result hight cost of compatibility maintenance. We should move to using public SPI. Mockito team is ready to help and provide change in API.

Main goal: clean code without dirty hacks to get internals of Mockito.

We need:

Current mockito 2 compatibility issues:

@thekingn0thing thekingn0thing added this to the PowerMock 2.0.0 milestone Dec 1, 2016
@thekingn0thing thekingn0thing mentioned this issue Dec 1, 2016
6 tasks
@zyl0501
Copy link

zyl0501 commented Dec 26, 2016

How to use PowerMockito.mockStatic()?
It return error when I call this method, like https://github.com/powermock/powermock/issues/720.
What is the alternative?

@thekingn0thing
Copy link
Member Author

@zyl0501,

Unfortunately, there is no alternative, except use PowerMock with Mockito 1.

@thekingn0thing
Copy link
Member Author

Experimental supporting Mockito 2.4.0 has been added in PowerMock 1.7.0RC in pull request #740

@ChristianSchwarz
Copy link

@thekingnothing
I am contributing to mockito, if you need support or additional APIs for Mockito 2 let me know, i try to help!

@TheKlint
Copy link

TheKlint commented Mar 22, 2017

I am trying to use the combo below - but I still get "Exception in thread "main" java.lang.NoClassDefFoundError: org/mockito/exceptions/Reporter"

Is there currently any working combo for Mockito 2 and PowerMockito.mockStatic()?

testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.4.0'
testCompile "org.powermock:powermock-module-junit4:1.7.0RC2"
testCompile "org.powermock:powermock-api-mockito:1.7.0RC2"

@thekingn0thing
Copy link
Member Author

@TheKlint, could you provide full stack trace? How throw exception?

@HCL-Balaji
Copy link

@thekingnothing I think below exception is mentioned by @TheKlint

Exception in thread "main" java.lang.NoClassDefFoundError: org/mockito/exceptions/Reporter
	at sun.reflect.GeneratedSerializationConstructorAccessor5.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:45)
	at org.powermock.reflect.internal.WhiteboxImpl.newInstance(WhiteboxImpl.java:260)
	at org.powermock.reflect.Whitebox.newInstance(Whitebox.java:139)
	at org.powermock.api.extension.reporter.AbstractMockingFrameworkReporterFactory.getInstanceForClassLoader(AbstractMockingFrameworkReporterFactory.java:41)
	at org.powermock.api.extension.reporter.AbstractMockingFrameworkReporterFactory.create(AbstractMockingFrameworkReporterFactory.java:35)
	at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.getMockingFrameworkReporter(JUnit4TestSuiteChunkerImpl.java:140)
	at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:119)
	at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
	at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.lang.ClassNotFoundException: org.mockito.exceptions.Reporter
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:190)
	at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass1(DeferSupportingClassLoader.java:77)
	at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:67)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 21 more

@AlekseiMarkov
Copy link

AlekseiMarkov commented Apr 6, 2017

Hi, same problem
powermock 1.7.0RC2
org.mockito:mockito-core 2.4.0

Exception in thread "main" java.lang.NoClassDefFoundError: org/mockito/exceptions/Reporter at sun.reflect.GeneratedSerializationConstructorAccessor4.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:45) at org.powermock.reflect.internal.WhiteboxImpl.newInstance(WhiteboxImpl.java:260) at org.powermock.reflect.Whitebox.newInstance(Whitebox.java:139) at org.powermock.api.extension.reporter.AbstractMockingFrameworkReporterFactory.getInstanceForClassLoader(AbstractMockingFrameworkReporterFactory.java:41) at org.powermock.api.extension.reporter.AbstractMockingFrameworkReporterFactory.create(AbstractMockingFrameworkReporterFactory.java:35) at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.getMockingFrameworkReporter(JUnit4TestSuiteChunkerImpl.java:140) at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:119) at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53) at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59) at org.junit.runner.JUnitCore.run(JUnitCore.java:160) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

@drayan85
Copy link

I am facing the same issue with below configuration.
testCompile 'org.mockito:mockito-core:2.4.0'
testCompile 'org.powermock:powermock-module-junit4:1.7.0RC2'
testCompile 'org.powermock:powermock-api-mockito:1.7.0RC2'

java.lang.NoClassDefFoundError: org/mockito/exceptions/Reporter
at sun.reflect.GeneratedSerializationConstructorAccessor5.newInstance(Unknown Source) at java.lang.reflect.Constructor.newInstance(Constructor.java:408) at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:45) at org.powermock.reflect.internal.WhiteboxImpl.newInstance(WhiteboxImpl.java:260) at org.powermock.reflect.Whitebox.newInstance(Whitebox.java:139) at org.powermock.api.extension.reporter.AbstractMockingFrameworkReporterFactory.getInstanceForClassLoader(AbstractMockingFrameworkReporterFactory.java:41) at org.powermock.api.extension.reporter.AbstractMockingFrameworkReporterFactory.create(AbstractMockingFrameworkReporterFactory.java:35) at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.getMockingFrameworkReporter(JUnit4TestSuiteChunkerImpl.java:140) at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:119) at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53) at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:59) at org.junit.runners.Suite.runChild(Suite.java:128) at org.junit.runners.Suite.runChild(Suite.java:27) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:262) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: org.mockito.exceptions.Reporter
at java.net.URLClassLoader$1.run(URLClassLoader.java:372) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:360) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:190) at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass1(DeferSupportingClassLoader.java:77) at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:67) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 29 more

@thekingn0thing
Copy link
Member Author

thekingn0thing commented Apr 14, 2017

@TheKlint @HCL-Balaji @drayan85 @AlekseiMarkov

I am trying to use the combo below - but I still get "Exception in thread "main" java.lang.NoClassDefFoundError: org/mockito/exceptions/Reporter"

Please, check dependencies, to use PowerMock with Mockito 2+ it should be not a
testCompile "org.powermock:powermock-api-mockito:1.7.0RC2"

but

org.powermock:powermock-api-mockito2:1.7.0RC2

https://github.com/powermock/powermock/wiki/Mockito-2-(Maven)

@drayan85
Copy link

@thekingnothing , thanks . with mokito2 working for now.

@thekingn0thing thekingn0thing changed the title Mockito 2 Support Roadmap Mockito Public API Support Roadmap Jul 7, 2017
@thekingn0thing thekingn0thing self-assigned this Jul 8, 2017
thekingn0thing pushed a commit that referenced this issue Jul 9, 2017
Use a new MockSetting API when mock is being created.
thekingn0thing pushed a commit that referenced this issue Jul 15, 2017
Use  Mockito Public API to create a mock
thekingn0thing pushed a commit that referenced this issue Jul 15, 2017
Use  Mockito Public API to create a mock
thekingn0thing pushed a commit that referenced this issue Jul 16, 2017
Refactoring to isolate Mockito internal code.
@Stianhn
Copy link

Stianhn commented Jul 24, 2017

@thekingnothing All the "current mockito 2 compatibility issues" listed in the first post are closed, but the wiki still states that Mockito2 support is experimental. What has to be in place before the Mockito2 support is no longer experimental?

@thekingn0thing
Copy link
Member Author

thekingn0thing commented Jul 24, 2017 via email

thekingn0thing pushed a commit that referenced this issue Aug 5, 2017
Using Mockito API for stubbing and creating invocation.
thekingn0thing pushed a commit that referenced this issue Aug 5, 2017
Replace using ThrowsException and other Mockito's internals answers by calling public API.
thekingn0thing pushed a commit that referenced this issue Aug 6, 2017
Use  Mockito Public API to create a mock
thekingn0thing pushed a commit that referenced this issue Aug 6, 2017
Using Mockito API for stubbing and creating invocation.
thekingn0thing pushed a commit that referenced this issue Aug 6, 2017
Replace using ThrowsException and other Mockito's internals answers by calling public API.
thekingn0thing pushed a commit that referenced this issue Aug 13, 2017
Using Mockito API for stubbing and creating invocation.
thekingn0thing pushed a commit that referenced this issue Sep 10, 2017
Clearing code and fixing test.
thekingn0thing pushed a commit that referenced this issue Sep 10, 2017
Upgrade Mockito to 2.10.0 - release with a new Mockito API.
thekingn0thing pushed a commit that referenced this issue Sep 10, 2017
Fix tests that are failed only on travis due different order of executing.
thekingn0thing pushed a commit that referenced this issue Sep 10, 2017
Delete unnecessary mockito-modules file, because there is no mockito modules any more.
thekingn0thing pushed a commit that referenced this issue Sep 10, 2017
Using Mockito API for stubbing and creating invocation.
thekingn0thing pushed a commit that referenced this issue Sep 10, 2017
Replace using ThrowsException and other Mockito's internals answers by calling public API.
thekingn0thing pushed a commit that referenced this issue Sep 10, 2017
Using Mockito API for stubbing and creating invocation.
thekingn0thing pushed a commit that referenced this issue Sep 10, 2017
Replace using ThrowsException and other Mockito's internals answers by calling public API.
thekingn0thing pushed a commit that referenced this issue Sep 10, 2017
Remove deprecated `verifyStatic()`.
thekingn0thing pushed a commit that referenced this issue Sep 10, 2017
Remove reseting mocking process in PowerMockito
thekingn0thing pushed a commit that referenced this issue Sep 10, 2017
Remove unused Mockito related code.
thekingn0thing pushed a commit that referenced this issue Sep 10, 2017
Replace dirty approach for checking if call to real method was handled by mockito.
thekingn0thing pushed a commit that referenced this issue Sep 10, 2017
Remove using Mockito internal class in default.properties
thekingn0thing pushed a commit that referenced this issue Sep 10, 2017
Remove `MockingFrameworkReporterFactory`  because it does not make sense anymore.
thekingn0thing pushed a commit that referenced this issue Sep 10, 2017
Clearing code: fix todo and refactor tests,
thekingn0thing pushed a commit that referenced this issue Sep 10, 2017
Clearing code and fixing test.
thekingn0thing pushed a commit that referenced this issue Sep 10, 2017
Upgrade Mockito to 2.10.0 - release with a new Mockito API.
thekingn0thing pushed a commit that referenced this issue Sep 10, 2017
Fix tests that are failed only on travis due different order of executing.
thekingn0thing pushed a commit that referenced this issue Sep 10, 2017
Delete unnecessary mockito-modules file, because there is no mockito modules any more.
@thekingn0thing thekingn0thing added this to Done in PowerMock 2.x Dec 15, 2017
@thekingn0thing
Copy link
Member Author

These changes have been released to Maven Central
https://github.com/powermock/powermock/releases/tag/powermock-2.0.0-RC.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
PowerMock 2.x
  
Done
Development

No branches or pull requests

8 participants