Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerMockito and Java 8 ZonedDateTime toInstant() not found

Wen I run my tests:

@RunWith(PowerMockRunner.class)
@PrepareForTest(MyStuff.class)
public class MyStuffTest { ..whatever

After I added ZonedDateTime class to that code it stared failing with the following error:

java.lang.IllegalStateException: Failed to transform class with name MyCode Reason: [source error] toInstant() not found in java.time.ZonedDateTime

Somewhere in my code I have:

long longTimeNoSee = ZonedDateTime.parse(getateTimeString()).toInstant().toEpochMilli();

I guess it is a bug in powermock. But maybe someone got some idea (?)

like image 943
ses Avatar asked Aug 12 '14 19:08

ses


2 Answers

It seems to be a bug in Powermock indeed. See

https://github.com/jayway/powermock/issues/557

You might want to add your examples and vote for this issue.

UPDATE: According to Powermock it seems to be an issue in javassist: https://github.com/jboss-javassist/javassist/issues/43

like image 180
Buurman Avatar answered Oct 10 '22 17:10

Buurman


Use powermockito version 1.6.6 or higher.

Also, make sure to use latest javassist version or at least 3.23.0-GA

like image 45
Ashwani Kumar Avatar answered Oct 10 '22 18:10

Ashwani Kumar