• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

PowerMockito + Junit + Ant

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Seema Kekre
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
I brought this back from the farm where they grow the tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic