File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jmock allowing call

 
Kavita Shivani
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I am trying to mock an object. In that I have a method which returns Boolean value. I construct this mock object several times. So I had to use allowing on the certain methods. I want the return value to be true as and when I pass the object id, in my case acronym. For all the remaining acronyms that are there in the test data it has to return false. But I don't know the usage of allowing will return .Following is the code.





What I want to see happen is,




But its not working, it gives unexpected value exception because its neither true nor false for other issues and years.

I have like 5 more test data for different years and issue code, and I am not concerned about those. I simply want them to return false so they are ignored.
My main functionality returns false so I believe the functionality itself is working good. But I am not able to mock it right.

thanks,
Kavitha.


 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33699
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to use the with() Hamcrest matcher syntax.


This is equivalent to what you have and lets you return true.


This lets you express the opposite so you can say that you want to return false for the negative case.

Note that it might be equal() or equalTo() depending on your version of jMock/Hamcrest.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic