aspose file tools*
The moose likes Testing and the fly likes jmock allowing call Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "jmock allowing call" Watch "jmock allowing call" New topic
Author

jmock allowing call

Kavita Shivani
Ranch Hand

Joined: Aug 14, 2009
Posts: 45
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

Joined: May 26, 2003
Posts: 31054
    
232

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.


[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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jmock allowing call