File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Testing and the fly likes Help needed for setting JMock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Help needed for setting JMock" Watch "Help needed for setting JMock" New topic

Help needed for setting JMock

Pradeep Kumar
Ranch Hand

Joined: Sep 08, 2006
Posts: 108

I am new to test with Jmock. When i run the test case i get this exception stack trace. I am using the following library dependencies.

1. hamcrest-core-1.1.jar
2. hamcrest-library-1.1.jar
3. jmock-2.5.1.jar
4. jmock-junit4-2.5.1.jar
5. junit-4.4.jar

The Test class is wrote is below.

The class to be tested is a simple java class.

And finally when i run in eclipse the stack trace is as follows

java.lang.IllegalArgumentException: com.local.domain.DependentClass1 is not an interface
at java.lang.reflect.Proxy.getProxyClass(Unknown Source)
at java.lang.reflect.Proxy.newProxyInstance(Unknown Source)
at org.jmock.lib.JavaReflectionImposteriser.imposterise(
at org.jmock.Mockery.mock(
at org.jmock.Mockery.mock(
at com.test.domain.TestJMock.testJMockSetUp(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.internal.runners.TestMethod.invoke(
at org.jmock.integration.junit4.JMock$1.invoke(
at org.junit.internal.runners.MethodRoadie.runTestMethod(
at org.junit.internal.runners.MethodRoadie$
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(
at org.junit.internal.runners.MethodRoadie.runTest(
at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(
at org.junit.internal.runners.JUnit4ClassRunner$
at org.junit.internal.runners.ClassRoadie.runUnprotected(
at org.junit.internal.runners.ClassRoadie.runProtected(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(

Kindly let me know where i went wrong.

Thanks and Regards,

Thanks and Regards, Pradeep Kumar
SCJP 1.6, SCWCD 5.0
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33106

The error message is a big clue. It's telling you that you are trying to mock a regular class and not an interface. Try creating an interface for the class.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Eric Botorlian

Joined: Sep 05, 2009
Posts: 2
I'm facing the same issue. I would consider it a bug or configuration issue as it's my impression that JMock can mock both concrete classes and interfaces.

Post here if you find a solution, Pradeep!

Eric Botorlian

Joined: Sep 05, 2009
Posts: 2
This should help. It's an instruction on mocking concrete and abstract classes.
I agree. Here's the link:
subject: Help needed for setting JMock
It's not a secret anymore!