Hi,
Can you provide code snippets of the class under test? If you are mocking addListener() call which should eventually trigger a call to creditCardAuthenticated method then I don't see how you can succeed your test. addListener() will be called and the mock will ignore the call ending your test there and will probably throw an exception because creditCardAuthenticated expectation wasn't met.
Maybe you need to change your perspective and create separate tests. One that tests your view to ensure addListener() does call run on the Presenter. Another test for your presenter to ensure run() calls creditCardAuthenticated() method.
Having small tests focusing on testing a single thing is better because it makes your tests less brittle to changes.
-Guillaume
________________________________
From: Greg Akins [mailto:
gakins@...]
Sent: Thu 4/9/2009 11:43 AM
To:
user@...
Subject: [jmock-user] First Test - Ignoring addListener()
Getting started with JMock.. sanity check. (Also, this might be a repeat. I tried to post through the gmane archive, but that didn't appear to work).
I am testing a PresenterFirst pattern.. and want to test with JMock. The Presenter calls the View's addListener method which calls the Presenters run() method, which in turn calls the view creditCardAuthenticated method. I don't care about the listener being called, only that the creditCardAuthenticated method is eventually called. Given all that, is this the right way to construct the test?
final IView viewMock = context.mock(IView.class);
context.checking(new Expectations() {{
ignoring (any(IView.class)).method("addListener") ;
}}) ;
context.checking( new Expectations()
{{
oneOf (viewMock).creditCardAuthenticated(true);
}});
CreditCardPresenter presenter = new CreditCardPresenter(viewMock) ;
Greg Akins
Director of Software Development
724.935.8281 x 210 (office)
724.935.8283 (fax)
724.454.7790 (cell)
http://www.towercare.com <
http://www.towercare.com/>
gakins@...
____________________________________________________________________________________________________
This electronic mail (including any attachments) may contain information that is privileged, confidential, and/or otherwise protected from disclosure to anyone other than its intended recipient(s). Any dissemination or use of this electronic email or its contents (including any attachments) by persons other than the intended recipient(s) is strictly prohibited. If you have received this message in error, please notify us immediately by reply email so that we may correct our internal records. Please then delete the original message (including any attachments) in its entirety. Thank you.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email