aspose file tools
The moose likes Testing and the fly likes About Mockito exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » Testing
Reply Bookmark "About Mockito exceptions" Watch "About Mockito exceptions" New topic
Author

About Mockito exceptions

robert isidorson
Greenhorn

Joined: Sep 03, 2007
Posts: 19
When i verify a method in a mock i still have to care about catching the exception even though it's a mock!

try {
verify(session, times(5)).init();
} catch(IOException e) {
;
}

how can i avoid that?
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26184
    
  66

Robert,
You can have your test method say "throws Exception" and let JUnit deal with it. I actually recommend that; especially over silently ignoring the exception as you are doing. For Exception, it is possible for the mock to throw it and then you don't know your setup is wrong.


[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: About Mockito exceptions
 
Similar Threads
Free exam from SUN??
Do you recomment using Mock Objects
HFSJ is obsolete as per spec
Passed scea (part 1) with 89 %
Urgent! Give the Answers pl.