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

Help: problem with EasyMock

 
Daniel D. Guo
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I tried to learn a mocking framework for testing with JUnit. EasyMock seems to be a good one, but I keep having problems with it. I am attaching the code as follows:









Basically, verify in tearDown cannot catch that stream.close() not being called, while it is supposed to be because "stream.close()" is specified before replay(stream) in testGetContentOk. Any idea is greatly appreciated.

Thanks a lot!

Daniel
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33671
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel,
I've moved on to jMock, but aren't you supposed to call stream.close() from within an expect method like you do for the read methods?
 
Daniel D. Guo
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne,

Thanks for your post!

Actually, I was trying to create an error by not calling close.

May I ask why you switched to JMock?

Thanks,
Daniel
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 33671
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used EasyMock pre-Java 5. Some collegues used jMock which was more powerful, but I didn't want my project to be using 2 mock frameworks and people have to switch back and forth. I did use jMock on JavaRanch proejcts and liked it better. It was easier to control and more powerful.

When we migrated to Java 5, there was an opportunity to change to something different. (easyMock and jMock both changed a lot with Java 5.) I took that as an opportunity to switch to jMock. EasyMock is a lot better now, but I still like the matchers in jMock more.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic