Hi Szczepan,
I would expect the following test to pass. What are your thoughts?
Cheers, felix
public class MockitoVarargTest {
interface VarargMethod{
Object run(String... args);
}
@Test
public void testVarargStubbing(){
Object returnValue = new Object();
VarargMethod mock = Mockito.mock(VarargMethod.class);
when(mock.run((String[]) anyObject())).thenReturn(returnValue);
assertEquals(returnValue, mock.run("a", "b"));
}
}
Comment #1
Posted on Mar 27, 2009 by Massive MonkeyI'll look at it
Comment #2
Posted on Apr 5, 2009 by Grumpy PandaI think we discussed this issue with patric back at gu, but unfortunately I can't remember, what came out of that...
Comment #3
Posted on Apr 8, 2009 by Massive MonkeyIt makes sense the anyObject() should match any number of elements in the varArg array.
It's fixed in trunk. Thanks Felix for reporting!
Comment #4
Posted on Apr 8, 2009 by Massive Monkey(No comment was entered for this change.)
Comment #5
Posted on Jun 9, 2009 by Massive Monkey(No comment was entered for this change.)
Comment #6
Posted on Jun 11, 2009 by Massive MonkeyReopened as the fix for this bug introduced regression. This is how you reproduce it:
//when
table.newRow("qux", "foo", "bar", "baz");
table.newRow("abc", "def");
//then
verify(table).newRow(anyString(), eq("foo"), anyString(), anyString());
verify(table).newRow(anyString(), anyString());
Comment #7
Posted on Jun 17, 2009 by Massive MonkeyReverted the fix for this issue as it makes other part of verification broken for some corner cases.
Fix for this issue will go to further milestone.
Comment #8
Posted on Jun 17, 2009 by Massive Monkey(No comment was entered for this change.)
Comment #9
Posted on Sep 22, 2009 by Massive MonkeyI officially don't have time for this feature :)
If anyone is keen on this feature, please submit a patch.
Comment #10
Posted on Nov 9, 2009 by Massive MonkeyThis cannot be implemented as it would change the behavior of other parts of the framework. Namely, it affects counting of actual invocations vs verified invocations.
Instead, I introduced new matcher: anyVararg()
Comment #11
Posted on Nov 10, 2009 by Quick MonkeyThat's great! Any release plans yet?
Comment #12
Posted on Nov 10, 2009 by Massive MonkeyI'm working on it - should be couple of days :)
Comment #13
Posted on Nov 11, 2009 by Massive Monkey(No comment was entered for this change.)
Comment #14
Posted on Nov 11, 2009 by Massive Monkey(No comment was entered for this change.)
Status: Fixed
Labels:
Type-Enhancement
Priority-Low
Milestone-Release1.8.1