The snippet looks good. Did you verified the import of the matchers matched org.mockito.Matchers.*
?
Cheers,
— Brice
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at http://groups.google.com/group/mockito.
For more options, visit https://groups.google.com/d/optout.
The snippet looks good. Did you verified the import of the matchers matched
org.mockito.Matchers.*
?Cheers,
— Brice
On 2014-07-22 16:20, Brice Dutheil wrote:
> Probably not. If you run the code snippet I cannot reproduce this behavior.
> So there's something in the code you' re trying to mack verify that reaches
> the current limitation of mockito.
> Is your method final ? Is the parent of Bar not public, and does
> the `doSomething` method declared in that parent?
Eduardo, you can also generate a small project which reproduces that
problem.
Marcin
> On Tue, Jul 22, 2014 at 3:13 PM, Eduardo Martins <
> eduardo...@luizalabs.com> wrote:
>
>> Hi Brice, thanks for the answer. I already imported:
>>
>> import static org.mockito.Matchers.*;
>> import static org.mockito.Mockito.mock;
>> import static org.mockito.Mockito.verify;
>>
>> So, is it a bug?
>>
>>
>> On Tuesday, July 22, 2014 5:17:25 AM UTC-3, Brice wrote:
>>
>>> The snippet looks good. Did you verified the import of the matchers
>>> matched org.mockito.Matchers.* ?
>>>
>>> Cheers,
>>>
>>> — Brice
>>>
>>> On Mon, Jul 21, 2014 at 11:48 PM, Eduardo Martins
>>> [eduardo...@luizalabs.com]
>>> <http://mailto:%5Beduardo.mar...@luizalabs.com%5D(mailto:eduardo...@luizalabs.com)>
Marcin, i created a project with the problem:
There’s the error in the snippet in the github project (not in the snippet of the first mail ;))
Bar bar = Mockito.mock(Bar.class);
Foo foo = new Foo(bar);
foo.doMagic(anyString());
Mockito.verify(bar).doSomething(isA(Dummy.class), anyString());
the following line is incorrect :
foo.doMagic(anyString());
You cannot use a matcher there. A mockito matcher need to be used either when you stub or when you verify.
Instead you should use a concrete value when invoking the object under test. The following snippet is green :
Bar bar = Mockito.mock(Bar.class);
Foo foo = new Foo(bar);
foo.doMagic("whatever");
Mockito.verify(bar).doSomething(isA(Dummy.class), anyString());
HTH
Cheers,
— Brice
--
foo.doMagic(anyString());
There’s the error in the snippet in the github project (not in the snippet of the first mail ;))
Bar bar = Mockito.mock(Bar.class); Foo foo = new Foo(bar); foo.doMagic(anyString()); Mockito.verify(bar).doSomething(isA(Dummy.class), anyString());
the following line is incorrect :
foo.doMagic(anyString());
You cannot use a matcher there. A mockito matcher need to be used either when you stub or when you verify.
Instead you should use a concrete value when invoking the object under test. The following snippet is green :Bar bar = Mockito.mock(Bar.class); Foo foo = new Foo(bar); foo.doMagic("whatever"); Mockito.verify(bar).doSomething(isA(Dummy.class), anyString());
HTH
Cheers,
— Brice
@Test public void testFoo() { Form form = new Form(); form.param("name", "eduardo"); form.param("id", "123");
Response response = target("/service/dummy").request().post(Entity.form(form));
ArgumentCaptor<Dummy> captor = ArgumentCaptor.forClass(Dummy.class); Mockito.verify(bar).doSomething(captor.capture(), "service");
Assert.assertEquals(HttpStatus.OK_200.getStatusCode(), response.getStatus()); Assert.assertEquals("eduardo", captor.getValue().getName()); }
@Test public void testFoo() { Form form = new Form(); form.param("name", "eduardo"); form.param("id", "123");
Response response = target("/service/dummy").request().post(Entity.form(form));
ArgumentCaptor<Dummy> captor = ArgumentCaptor.forClass(Dummy.class); Mockito.verify(bar).doSomething(captor.capture(), anyString());
Assert.assertEquals(HttpStatus.OK_200.getStatusCode(), response.getStatus()); Assert.assertEquals("eduardo", captor.getValue().getName()); }