From: Immanuel, Gidado-Y. <av...@cd...> - 2002-11-08 08:25:48
|
(Appologies if this should go to the user list, but that list has been dormant for a little while, so I'm headed straight to the source) This has taken me about an 1 1/2 to figure out (thank goodness for the code). In my test case I have: 1. handler.log(val); 2. mock.setExpectedLogMessage(val); 3. mock.verify(); where the handler knows about the mock. What happens is that line 1 eventually calls mock.log() which then calls mock.logMessage.setActual(). setActual looks to see if it should verify...finds no expectations...so skips it. Line 2 sets the expected value which eventually calls ExpectationValue.setExpected() which calls AbstractExpectation.setHasExpectations() which does the not so obvious: AbstractExpectation.clearActual() So Line 2 ends up clearing whatever is set in Line 1. The only usage pattern that works is to setExpected() before setActual(): 1. mock.setExpectedLogMessage(val); 2. handler.log(val); 3. mock.verify(); This was not clear anywhere in the articles or javadoc. Perhaps you could add this to the FAQ page. I assume there is a very good reason why clearActual() is necessary in setHasExpectations()...I'm very new to all this, so if you don't mind educating me a little, I would love to know. Thanks, Gidado |