wujun / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 0 forks source link

PowerMock for mockito with maven not working on Linux #412

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. On linux annotate you test class with @RunWith(PowerMockRunner.class) and 
@PrepareForTest(UtilClass.class)
2. run maven command 'mvn clean test -e'
3. Using maven 3.0.4 and java 1.6 update 37

What is the expected output? 
That tests are are running without interruption and exception thrown

What do you see instead?
when opening test report in target/test-report/TEST-* I see the folowing error:

Failed to transform class with name 
com.application.cart.components.HybridCartItemTest. Reason: java.lang.Class
Stacktrace

java.lang.IllegalStateException: Failed to transform class with name 
com.application.cart.components.HybridCartItemTest. Reason: java.lang.Class
    at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:207)
    at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:145)
    at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:67)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:247)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:133)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:39)
    at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:217)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:59)
    at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:32)
    at org.powermock.modules.junit4.PowerMockRunner.<init>(PowerMockRunner.java:31)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
    at org.junit.runner.Computer.getRunner(Computer.java:38)
    at org.apache.maven.surefire.junitcore.ConfigurableParallelComputer.getRunner(ConfigurableParallelComputer.java:142)
    at org.junit.runner.Computer$1.runnerForClass(Computer.java:29)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
    at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:93)
    at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:84)
    at org.junit.runners.Suite.<init>(Suite.java:79)
    at org.junit.runner.Computer.getSuite(Computer.java:26)
    at org.apache.maven.surefire.junitcore.ConfigurableParallelComputer.getSuite(ConfigurableParallelComputer.java:134)
    at org.junit.runner.Request.classes(Request.java:69)
    at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:54)
    at org.apache.maven.surefire.junitcore.JUnitCoreProvider.invoke(JUnitCoreProvider.java:139)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:113)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: javassist.NotFoundException: java.lang.Class
    at javassist.ClassPool.get(ClassPool.java:439)
    at javassist.bytecode.Descriptor.toCtClass(Descriptor.java:591)
    at javassist.bytecode.Descriptor.getReturnType(Descriptor.java:488)
    at javassist.CtBehavior.getReturnType0(CtBehavior.java:293)
    at javassist.CtMethod.getReturnType(CtMethod.java:216)
    at org.powermock.core.transformers.impl.MainMockTransformer.modifyMethod(MainMockTransformer.java:173)
    at org.powermock.core.transformers.impl.MainMockTransformer.allowMockingOfStaticAndFinalAndNativeMethods(MainMockTransformer.java:143)
    at org.powermock.core.transformers.impl.MainMockTransformer.transform(MainMockTransformer.java:66)
    at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:203)
    ... 40 more

What version of the product are you using? On what operating system?

PowerMock: 1.4.12
Mockito: 1.9.0
junit: 4.8.2
Apache Maven 3.0.4 (r1232337; 2012-01-17 00:44:56-0800)
Maven home: /usr/local/apache-maven/apache-maven-3.0.4
Java version: 1.6.0_37, vendor: Sun Microsystems Inc.
Java home: /usr/java/jdk1.6.0_37/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-100.26.2.el5", arch: "amd64", family: "unix"

Please provide any additional information below.

I have tried the following to resolve the issue without luck:

1) Switched extending a baseMocking class to using 
@MockPolicy(BaseMocking.class) BaseMocking defined by me
2) Added maven-surefire-plugin configuration:  
<useSystemClassLoader>true</useSystemClassLoader>
3) Tried different forkModes: none, perthread, etc.
4) Updated to latest version of javassist, we are using a slightly older version
5) Updated to the latest version of Junit4 4.10
6) Bootstrapped test using JUnit Rule and a agent 
(http://code.google.com/p/powermock/wiki/PowerMockAgent)

Please if you could provide me my organization (Apple) some information about 
how to get this to work I would be grateful.

Sincerely
Bilal Clarance

Original issue reported on code.google.com by bclara...@gmail.com on 25 Nov 2012 at 6:08

GoogleCodeExporter commented 9 years ago
It sounds really strange that Javassist says it can't find java.lang.Class.. It 
could be a javassist issue but I doubt it. You can try the latest version of 
PowerMock and see if you run into the same issues. Make sure you use the latest 
Javassist version (3.17.1-GA).

Original comment by johan.ha...@gmail.com on 5 Dec 2012 at 9:01