wood burning stoves
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

Win a copy of Head First Android this week in the Android forum!
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(JavaReflectionImposteriser.java:31)
at org.jmock.Mockery.mock(Mockery.java:139)
at org.jmock.Mockery.mock(Mockery.java:120)
at com.test.domain.TestJMock.testJMockSetUp(TestJMock.java:18)
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(TestMethod.java:59)
at org.jmock.integration.junit4.JMock$1.invoke(JMock.java:37)
at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

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: 32319

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]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, 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.

subject: Help needed for setting JMock
It's not a secret anymore!