| Author |
PowerMockito + Junit + Ant
|
Seema Kekre
Ranch Hand
Joined: Dec 02, 2010
Posts: 35
|
|
I am new to Powermockito. I have a Junit4 setup with Ant1.7.1. I am mocking a final class using mockito 1.8.5
When I run this test using Eclipse, it runs fine. When I run the test using my ant build I get the following error. From this error it looks like it can find Powermockito and mockito in its classpath and there is just one mockito jar in the lib (claspath).
[junit] java.lang.ExceptionInInitializerError
[junit] at java.lang.Class.forName0(Native Method)
[junit] at java.lang.Class.forName(Class.java:169)
[junit] Caused by: java.lang.IllegalArgumentException: Cannot subclass final class class com.company.FinalDB
[junit] at org.mockito.cglib.proxy.Enhancer.generateClass(Enhancer.java:447)
[junit] at org.mockito.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
[junit] at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:217)
[junit] at org.mockito.cglib.proxy.Enhancer.createHelper(Enhancer.java:378)
[junit] at org.mockito.cglib.proxy.Enhancer.createClass(Enhancer.java:318)
[junit] at org.mockito.internal.creation.jmock.ClassImposterizer.createProxyClass(ClassImposterizer.java:93)
[junit] at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:50)
[junit] at org.powermock.api.mockito.internal.mockcreation.MockCreator.createMethodInvocationControl(MockCreator.java:100)
[junit] at org.powermock.api.mockito.internal.mockcreation.MockCreator.mock(MockCreator.java:58)
[junit] at org.powermock.api.mockito.PowerMockito.mock(PowerMockito.java:138)
[junit] at com.hp.platform.store.archiver.SomeClassTest.getMockSomeClass(SomeClassTest.java:78)
My eclipse and Ant are pointing to the same junit. I dont think this is a Junit issue, but a mockito issue but I cannot figure out how to start figuring out the issue.
Why does it work with Eclipse and not with Ant? How can I figure out the order in which the Classloaders are loaded?
Thanks in advance.
Seema.
|
OCPJP 6
|
 |
Seema Kekre
Ranch Hand
Joined: Dec 02, 2010
Posts: 35
|
|
Was able to figure it out. For some reason, using mock for final classes in static causes a java.lang.ExceptionInInitializerError. When I changed this to a class method it still throws this Exception but my tests pass. Will post on Powermockito forum to understand this better.
|
 |
Shanky Sohar
Ranch Hand
Joined: Mar 17, 2010
Posts: 1046
|
|
|
using mockito we cannt mock the final classes but if you are using powermockito then it can be done..Just put the powermockit jar in the classpath and remove mockito jar
|
SCJP6.0,My blog Ranchers from Delhi
|
 |
 |
|
|
subject: PowerMockito + Junit + Ant
|
|
|