This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Testing and the fly likes Mocking File/OutputStream help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Mocking File/OutputStream help" Watch "Mocking File/OutputStream help" New topic
Author

Mocking File/OutputStream help

Lyane Foly
Greenhorn

Joined: Jun 02, 2011
Posts: 1
Hi there,
I am testing a function that create a fileOutputStream in the body of the function.
This the simple example I wrote just to show my problem.

Here is my class:

Using EasyMock I test this way



I am getting an assertionError because 2 differents FileOutputStream are getting created. This make sense to me, but I am not sure how to sole this issue.
Any help would be appreciated. Aslo I cannot pass the fileoutputstream to the getFileName() function because that interface is already defined and I can changed it...

Error is here:



Thanks
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30356
    
150

Lyane,
Welcome to CodeRanch!

Have you looked into argument matchers? They let you redefine equality in any way you want.


[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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Mocking File/OutputStream help