Java.Lang.IllegalStateException when using powermock to mock a final class

535 views
Skip to first unread message

InfoDog

unread,
Aug 19, 2009, 5:42:17 PM8/19/09
to PowerMock
Hello:

I tried to use powermock to mock a final class. I face a two-prong
issue:

a) I'm using the following two classes from powermock library -- i)
org.powermock.core.classloader.annotations.PrepareForTest; and (ii)
org.powermock.modules.junit4.PowerMockRunner;

I get the following exception when I call createMock method

java.lang.IllegalStateException: Unknown callback type class
org.powermock.api.easymock.internal.signedsupport.SignedSupportingClassProxyFactory
$1
at net.sf.cglib.proxy.CallbackInfo.determineType(CallbackInfo.java:
87)
at net.sf.cglib.proxy.CallbackInfo.determineTypes(CallbackInfo.java:
25)
at net.sf.cglib.proxy.Enhancer.setCallbackTypes(Enhancer.java:273)
at net.sf.cglib.proxy.Enhancer.setCallbackType(Enhancer.java:257)
.............................

b) If I switch using the import
org.powermock.modules.junit4.legacy.PowerMockRunner; then I get the
java.lang.NoClassDefFoundError: org/junit/internal/runners/
BeforeAndAfterRunner
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.getConstructor(Class.java:1657)
exception.

Any tips/pointers on resolving this would be appreciated.

Johan Haleby

unread,
Aug 20, 2009, 2:24:19 AM8/20/09
to powe...@googlegroups.com
Hi,

Are you using the correct dependencies (those available in powermock-1.2.5-with-dependencies.zip)? If you are could you please post the code that you're trying to test as well as your test case?

/Johan

InfoDog

unread,
Aug 20, 2009, 1:01:34 PM8/20/09
to PowerMock
Thanks for the reply. I do not get what do you mean by the correct
dependencies in powermock-1.2.5-with-dependenices.zip. I'm including
the full version of 1.2.5 jar file in the build path. Here's is a
simplified version of my test case:

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class)
@PrepareForTest(SampleFinalClass.class)
public class SampleTest {
private SampleFinalClass finalClass;

@Before
public void setUp() {
finalClass = PowerMock.createMock
(sampleFinalClass.class); // The exception get's thrown here
}
}




On Aug 20, 6:24 am, Johan Haleby <johan.hal...@gmail.com> wrote:
> Hi,
>
> Are you using the correct dependencies (those available in
> powermock-1.2.5-with-dependencies.zip<http://powermock.googlecode.com/files/powermock-1.2.5-with-dependenci...>)?
> If you are could you please post the code that you're trying to test as well
> as your test case?
>
> /Johan
>

Johan Haleby

unread,
Aug 21, 2009, 2:14:26 AM8/21/09
to powe...@googlegroups.com
Hi,

powermock-1.2.5-full.jar doesn't contain any third-party dependencies (which is needed for PowerMock to work). You need to manually download the PowerMock dependencies as well (or use those available in the powermock-1.2.5-with-dependencies.zip). I.e. you need the correct versions of EasyMock class extensions, EasyMock, Javaassist, cglib, junit and objenesis in the classpath in order to successfully execute a PowerMock test with the EasyMock extension API.

/Johan
Reply all
Reply to author
Forward
0 new messages