• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help: problem with EasyMock

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic