On Apr 9, 2009, at 12:03 PM, Jeudy, Guillaume wrote:
> 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.
That's exactly what happens. I had, as another post on this thread
mentions, seen examples with JMock 1.2 that captured the results of
the addListener call and created a proxy to the method which could be
executed (at least I think that's how it works).
>
> 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.
Splitting it up like that makes sense. But what I think I need to
test here is that if the presenter gives a view a listener and the
listener is invoked that it executes the method as expected. Also,
run() is private, because it's only called through the listener.. if I
can get a proxy to the listener then I don't have to make run() public.
This all might be way to complicated, but my motivation is to use
PresenterFirst to separate logic from UI and I can't think of another
good way to test that.
>
> 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_emailGreg Akins
Director of Software Development
724.935.8281 x 210 (office)
724.935.8283 (fax)
724.454.7790 (cell)
http://www.towercare.comgakins@...
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email