Willam2004 / powermock

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

Powermock does not play well with java.time #537

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
have this in a unit test which is annotated by: @RunWith(PowerMockRunner.class):

        LocalDate.now().minusYears(3).atStartOfDay().toInstant(ZoneOffset.UTC);

and it will blow up with:

teException: Failed to transform class with name 
com.davidkarlsen.traktorscrobbler.FileHandlingRouteBuilderTest. Reason: [source 
error] toInstant(java.time.ZoneOffset) not found in java.time.LocalDateTime
    at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:266)
    at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:180)
    at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:68)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:344)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:145)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:40)
    at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:244)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:61)
    at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:32)
    at org.powermock.modules.junit4.PowerMockRunner.<init>(PowerMockRunner.java:34)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:36)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
Caused by: javassist.CannotCompileException: [source error] 
toInstant(java.time.ZoneOffset) not found in java.time.LocalDateTime
    at javassist.expr.MethodCall.replace(MethodCall.java:241)
    at org.powermock.core.transformers.impl.MainMockTransformer$PowerMockExpressionEditor.edit(MainMockTransformer.java:288)
    at javassist.expr.ExprEditor.loopBody(ExprEditor.java:192)
    at javassist.expr.ExprEditor.doit(ExprEditor.java:91)
    at javassist.CtClassType.instrument(CtClassType.java:1431)
    at org.powermock.core.transformers.impl.MainMockTransformer.transform(MainMockTransformer.java:74)
    at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:251)
    ... 25 more

Original issue reported on code.google.com by davidkar...@gmail.com on 28 Jan 2015 at 1:23

GoogleCodeExporter commented 9 years ago
I also tried it with javassist:
3.19.0-GA

Original comment by davidkar...@gmail.com on 28 Jan 2015 at 1:24

GoogleCodeExporter commented 9 years ago
I have the exact same trace (except for the test-class, obviously).

Using mockito-core 1.10.19, powermock-api-mockito 1.6.2, 
powermock-module-junit4 1.6.2, javassist 3.19.0-GA.

Offending line of code: 
final Date start1415 =
            Date.from(LocalDateTime.of(2014, Month.AUGUST, 1, 0, 0, 0)
                .atZone(ZoneId.systemDefault()).toInstant());

Original comment by buurman....@gmail.com on 28 Apr 2015 at 8:55

GoogleCodeExporter commented 9 years ago
It looks like a bug in javassist.
see https://github.com/jboss-javassist/javassist/issues/43
You can reproduce this error without any powermock code.

Original comment by andreas....@web.de on 23 May 2015 at 1:11