Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

PowerMockito + Junit + Ant

Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • 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(
[junit] Caused by: java.lang.IllegalArgumentException: Cannot subclass final class class
[junit] at org.mockito.cglib.proxy.Enhancer.generateClass(
[junit] at org.mockito.cglib.core.DefaultGeneratorStrategy.generate(
[junit] at org.mockito.cglib.core.AbstractClassGenerator.create(
[junit] at org.mockito.cglib.proxy.Enhancer.createHelper(
[junit] at org.mockito.cglib.proxy.Enhancer.createClass(
[junit] at org.mockito.internal.creation.jmock.ClassImposterizer.createProxyClass(
[junit] at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(
[junit] at org.powermock.api.mockito.internal.mockcreation.MockCreator.createMethodInvocationControl(
[junit] at org.powermock.api.mockito.internal.mockcreation.MockCreator.mock(
[junit] at org.powermock.api.mockito.PowerMockito.mock(
[junit] at

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 Kekre
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • 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
  • 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
    Bookmark Topic Watch Topic
  • New Topic