I have a class that when run will call a private sendEfvent() method
that sends data to an external process. I would like to override that
behavior in testing and just report what is set to avoid the
complications, etc of having to use external processes during unit
testing.
I don't think I can just use an assertTrue() because I also want to
know how many times this private method is called (i.e. is it sending
the correct number of copies out)?
Is there a way I can cause Junit to stop the JRE from calling the true
sendEvent() method and instead call something in my test class??
-Robert
Jim Korman - 29 Dec 2006 01:37 GMT
>I have a class that when run will call a private sendEfvent() method
>that sends data to an external process. I would like to override that
[quoted text clipped - 10 lines]
>
>-Robert
Consider using an Interface that exposes the send event behavior.
Then your sendEfvent() method calls this strategy's send method.
During testing you can set the strategy to a mock implementation that
counts data, or better yet, exposes the message so that you can then
unit test the message contents.
Jim