• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help needed for setting JMock  RSS feed

Pradeep Kumar
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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,
Jeanne Boyarsky
author & internet detective
Posts: 37181
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Eric Botorlian
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should help. It's an instruction on mocking concrete and abstract classes.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!