Open GoogleCodeExporter opened 8 years ago
Try extending from PowerMockTestCase and see if you get the same error.
Original comment by johan.ha...@gmail.com
on 5 Dec 2012 at 8:59
Same (similar) issue here with PowerMock 1.5. See attached pom, test case and
class under test.
Can confirm the problem disappears if I make the test case extend
PowerMockTestCase.
Original comment by joelcap...@gmail.com
on 6 Jan 2013 at 7:38
Attachments:
I think I have a simpler test case. This seems to happen when a mock is created
at instantation time. If I set up my mocks in an @Before method the issue goes
away.
I believe this is a ClassLoader issue - PowerMockMaker is loaded by the system
classloader, but org.mockito.plugins.MockMaker is also loaded by the
org.powermock.core.classloader.MockClassLoader and so PowerMockMaker is not an
instance of MockMaker.
It may be an unavoidable limitation of PowerMock, but the resulting exception
is completely unhelpful and gives no hint of how to fix the issue.
Simpler example test exhibiting the symptoms:
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import static org.junit.Assert.assertFalse;
import static org.mockito.Mockito.mock;
@RunWith(PowerMockRunner.class)
@PrepareForTest(SomeClass.class)
public class TestSomeClass {
private final List list = mock(List.class);
@Test
public void invertTrue() {
assertFalse(false);
}
}
Original comment by mahoney...@gmail.com
on 24 Feb 2013 at 9:34
Thanks for your example. People have run into simliar issues when using mock
policies with PowerMock and Mockito 1.9.5. I've committed a work-around for
that but I'm not sure if it's as easy in this case.
Original comment by johan.ha...@gmail.com
on 25 Feb 2013 at 7:17
Any process here? Having the same issue, which is very annoying because we
would like to upgrade to 1.9.5 to get Java 7 support. We can confirm that this
seems to be a ClassLoading issue.
Original comment by apw.desi...@gmail.com
on 17 Apr 2013 at 10:53
I am facing the same issue using Mockito + powerMock with TestNG. I can't use
@RunWith since it is a JUnit annotation ; I use @ObjectFactory instead.
Here is my test class :
import org.mockito.MockitoAnnotations;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.testng.PowerMockObjectFactory;
import org.testng.Assert;
import org.testng.IObjectFactory;
import org.testng.annotations.ObjectFactory;
import org.testng.annotations.Test;
@PrepareForTest(Static.class)
public class FakeForTestTest {
@ObjectFactory
public IObjectFactory setObjectFactory() {
return new PowerMockObjectFactory();
}
@Test
public void shouldBeValid() {
PowerMockito.mockStatic(Static.class);
MockitoAnnotations.initMocks(this);
Object testObject = new Double(50);
PowerMockito.when(Static.isValid(testObject)).thenReturn(true);
FakeForTest fft = new FakeForTest();
Boolean reel = fft.isValid(testObject);
Assert.assertTrue(reel, "Error");
}
}
Original comment by nfr...@gmail.com
on 23 Sep 2013 at 5:04
Need help for this . using java 1.7
Original comment by hamish.t...@gmail.com
on 27 Sep 2013 at 1:27
When using PowerMock with TestNG always extend your test from
org.powermock.modules.testng.PowerMockTestCase. By doing this you don't have to
bother about providing custom object factory, so you will not have
@ObjectFactory in your test at all. For me this solved the problem.
Original comment by AZagorne...@gmail.com
on 27 Sep 2013 at 6:26
Any workarounds for JUnit? I don't have TestNG nor any of the Powermock TestNG
libraries on the classpath.
I've also noticed this issue comes up with @BeforeClass mock initialization.
Original comment by robert....@gmail.com
on 9 Oct 2013 at 5:48
Same issue here with Junit.
Workaround is to add "org.mockito.*" in @PowerMockIgnore
Original comment by arnaud.l...@gmail.com
on 28 Oct 2013 at 3:52
Looks like this same issue was fixed in gwtMockito, perhaps that can help here
as well?
https://github.com/google/gwtmockito/issues/14
Original comment by hashbro...@gmail.com
on 1 Nov 2013 at 4:09
Based on the fix mentioned by in #11, I created a patch for
JUnit4TestSuiteChunkerImpl that seems to fix the problem. I ran it on a project
internally w/ ~700 tests that used to fail due to this bug, and they now
succeed.
I also attempted to figure out how to add a test case to powermock for this
issue, but it turned out to be easier to find the location for the fix than it
was to find out where I would put a test for it. :)
Patch file is attached.
Original comment by robert....@redfin.com
on 13 Nov 2013 at 6:20
Attachments:
Sorry, I should have been more clear: I created a patch for the issue when
running through JUnit. I don't have much/any experience w/ TestNG.
Original comment by robert....@redfin.com
on 13 Nov 2013 at 6:22
I have a similar issue.
My platform is Testng-6.8.7 and Powermock-1.5.2, and Mockito-1.9.5
And if I extends PowerMockTestCase, then the issue is not happening. Only when
I use the following.
@ObjectFactory
public IObjectFactory getObjectFactory() {
return new org.powermock.modules.testng.PowerMockObjectFactory();
}
The following is the exceptions error.
java.lang.ExceptionInInitializerError
at org.mockito.internal.exceptions.stacktrace.ConditionalStackTraceFilter.<init>(ConditionalStackTraceFilter.java:17)
at org.mockito.exceptions.base.MockitoException.filterStackTrace(MockitoException.java:30)
at org.mockito.exceptions.base.MockitoException.<init>(MockitoException.java:19)
at org.mockito.exceptions.misusing.MockitoConfigurationException.<init>(MockitoConfigurationException.java:18)
at org.mockito.internal.configuration.ClassPathLoader.loadImplementations(ClassPathLoader.java:145)
at org.mockito.internal.configuration.ClassPathLoader.findPluginImplementation(ClassPathLoader.java:110)
at org.mockito.internal.configuration.ClassPathLoader.findPlatformMockMaker(ClassPathLoader.java:106)
at org.mockito.internal.configuration.ClassPathLoader.<clinit>(ClassPathLoader.java:59)
at org.mockito.internal.util.MockUtil.<clinit>(MockUtil.java:21)
at org.mockito.internal.configuration.injection.scanner.MockScanner.<init>(MockScanner.java:22)
at org.mockito.internal.configuration.InjectingAnnotationEngine.injectMocks(InjectingAnnotationEngine.java:96)
at org.powermock.api.mockito.internal.configuration.PowerMockitoInjectingAnnotationEngine.process(PowerMockitoInjectingAnnotationEngine.java:35)
at org.powermock.api.extension.listener.AnnotationEnabler.injectSpiesAndInjectToSetters(AnnotationEnabler.java:57)
at org.powermock.api.extension.listener.AnnotationEnabler.beforeTestMethod(AnnotationEnabler.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.powermock.reflect.internal.WhiteboxImpl.performMethodInvocation(WhiteboxImpl.java:2014)
at org.powermock.reflect.internal.WhiteboxImpl.invokeMethod(WhiteboxImpl.java:744)
at org.powermock.reflect.Whitebox.invokeMethod(Whitebox.java:415)
at org.powermock.modules.testng.internal.PowerMockTestNGMethodHandler.injectMocksUsingAnnotationEnabler(PowerMockTestNGMethodHandler.java:75)
at org.powermock.modules.testng.internal.PowerMockTestNGMethodHandler.invoke(PowerMockTestNGMethodHandler.java:47)
at com.ibaset.solumina.sfcore.application.impl.LoginImplTest_$$_jvstdd8_0.getFoundationVersion_NoDash_LongSameShortEmpty(LoginImplTest_$$_jvstdd8_0.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Caused by: java.lang.NullPointerException
at org.mockito.internal.exceptions.stacktrace.StackTraceFilter.<clinit>(StackTraceFilter.java:21)
... 48 more
Original comment by Jaepyoun...@gmail.com
on 9 Jan 2014 at 9:16
Following 2 workarounds helped me get over this:
1. Do not use private static instance field:
private static final MockMe ME = new MockMe();
2. Make TestNG test method 'final'. Not sure how this helps, but it did help
me.
Original comment by khid...@gmail.com
on 24 Sep 2014 at 6:58
Original issue reported on code.google.com by
jon.cho...@actifio.com
on 4 Dec 2012 at 7:16