Mockito 1.9.0: Getting "Invalid use of argument matchers" error when using argument matchers with eq around raw values

12,217 views
Skip to first unread message

Omair-Inam Abdul-Matin

unread,
Apr 11, 2012, 12:59:21 PM4/11/12
to moc...@googlegroups.com
I'm testing Here's a test that fails:

public void verifyAgentCallbackInvokedWithCorrectArgumentsWhenTriggeringConfigCollectionForMaster() throws DlinkCollectionException {
        svc.triggerConfigCollection(device);

        verify(mockPnAuditService).log((secUser), (device.getUniqueId()), (AuditableService.CollectionConfiguration), (AuditableActionType.collectDeviceConfiguration),
                anyString(),
                anyString());
}


Here's the modified test:
    public void verifyAgentCallbackInvokedWithCorrectArgumentsWhenTriggeringConfigCollectionForMaster() throws DlinkCollectionException {
        String ip = "192.3.3.5";
        String port = "9999";
        String masterUnitID = "1343";
        TopologyObject device = mockDlinkMaster(ip, port, masterUnitID);
        svc.triggerConfigCollection(device);

        verify(mockPnAuditService).log(eq(secUser), eq(device.getUniqueId()), eq(AuditableService.CollectionConfiguration), eq(AuditableActionType.collectDeviceConfiguration),
                anyString(),
                anyString());
    }
which still fails:


Does anyone know why this does not work?  What do I need to change to make this work? I'd like to be able to check all arguments, except the last two which can be any string...

Eric Lefevre-Ardant

unread,
Apr 11, 2012, 1:09:20 PM4/11/12
to moc...@googlegroups.com
Your code looks good at first glance.
Could you maybe try to simplify your code to pinpoint the problem in a more obvious manner?


--
You received this message because you are subscribed to the Google Groups "mockito" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mockito/-/N1P1O6Z0Al8J.
To post to this group, send email to moc...@googlegroups.com.
To unsubscribe from this group, send email to mockito+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mockito?hl=en.

Omair-Inam Abdul-Matin

unread,
Apr 11, 2012, 1:09:45 PM4/11/12
to moc...@googlegroups.com
I did a bit of analysis and found that I can make eq work.. for all non-String arguments:
... The code below passes:

 verify(mockPnAuditService).log(eq(secUser), anyString(), eq(AuditableService.CollectionConfiguration), eq(AuditableActionType.collectDeviceConfiguration),
                anyString(), anyString());

However this fails:
verify(mockPnAuditService).log(eq(secUser), eq(remote.getUniqueId()), eq(AuditableService.CollectionConfiguration), eq(AuditableActionType.collectDeviceConfiguration),
                anyString(), anyString());

with:
So the question is... is it possible to verify a method call being made in which one of the string arguments is anyString() .. but at least one argument needs to be an exact value?


Eric Lefevre-Ardant

unread,
Apr 11, 2012, 1:13:11 PM4/11/12
to moc...@googlegroups.com
Is "remote.getUniqueId()" a mocked value or some other thing managed by Mockito?
That wouldn't seem to be a very clean test, but you could get around the problem by simply extracting it into a local variable before the call to verify.

--
You received this message because you are subscribed to the Google Groups "mockito" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mockito/-/muvNLrWw5AQJ.
Reply all
Reply to author
Forward
0 new messages