« Return to Thread: First Test - Ignoring addListener()

Re: First Test - Ignoring addListener()

by Steve Freeman-2 :: Rate this Message:

Reply to Author | View in Thread

Welcome to the club...

This phrase:

context.checking(new Expectations() {{
   ignoring (any(IView.class)).method("addListener") ;
}}) ;

isn't right. You ignore the call on a particular view instance, not  
the class, so it should be:

context.checking(new Expectations() {{
   ignoring (viewMock).addListener(with(any(<ListenerType>.class)));
}};

You can then merge this with the other expectation:

context.checking(new Expectations() {{
   ignoring (viewMock).addListener(with(any(<ListenerType>.class)));

   oneOf (viewMock).creditCardAuthenticated(true);
}}) ;

S

On 9 Apr 2009, at 17:43, Greg Akins wrote:

> 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
> gakins@...
>

Steve Freeman
Winner of the Agile Alliance Gordon Pask award 2006

http://www.m3p.co.uk

M3P Limited.
Registered office. 2 Church Street, Burnham, Bucks, SL1 7HZ.
Company registered in England & Wales. Number 03689627



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 « Return to Thread: First Test - Ignoring addListener()