atom feed5 messages in org.codehaus.jmock.userRe: [jmock-user] Mocking a method tha...
FromSent OnAttachments
Richard MartinNov 22, 2007 3:51 am 
Steve FreemanNov 22, 2007 6:34 am 
Dale KingNov 22, 2007 9:15 am 
Nat PryceNov 22, 2007 1:29 pm 
Dale KingNov 22, 2007 3:29 pm 
Subject:Re: [jmock-user] Mocking a method that expects a generic collection
From:Steve Freeman (
Date:Nov 22, 2007 6:34:21 am

If you use a matcher for one parameter you have to use them for all, that's what the error message is trying to tell you. Perhaps we ought to reword it.

allowing(dao).update(with(equal(1)), with(is(List.class)));

Also, I tend to turn off the generics checking in code like this. I just find it easier to read than adding a cast.


On 22 Nov 2007, at 11:51, Richard Martin wrote:


I seem to be really struggling trying to mock this method call, its an update call that takes an int as the key and a list of value objects to be updates. I just want the mock to accept the call of move on but I just can't seem to get it to work, at the moment I dont care whats in the list that is sent to the method.

The method signature is public void update(int key, List<ValueObjectVo> updates)

and my expectations is something like

final Dao dao = context.mock(Dao.class);

this.context.checking (new Expectations() { { allowing(dao).update(1, (List<CampaignChannelMapVo>)with (is(List.class))); } });

That doesn't work due to "not all parameters were given explicit constraints: either all parameters must be specified by explicit constraints or all must be specified by literal values to match"

I've tried lots of different things now and I think im just being stupid as I can't find any real reference to this in the mailing list so it must be possible.

Any one point me in the right direction?

Cheers Bob

Steve Freeman Winner of the Agile Alliance Gordon Pask award 2006

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