This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30138
    
150

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
 
Similar Threads
Record Locking in multi-user
Anyone done SCJP 1.4 Beta , please comment~ :)
Inheritance / Komposition of multiple abstract classes
help with itteration through a multi dimensional array?
jMock and return value