How to negate an ArgumentMatcher

487 views
Skip to first unread message

Eric J. Van der Velden

unread,
Oct 25, 2016, 8:01:59 AM10/25/16
to mockito
I create an ArgumentMatcher,

 private class IsListOf2Elements implements ArgumentMatcher<List<String>>{
 
@Override
 
public boolean matches(List<String> argument) {
 
return ((List<String>)argument).size()==2;
 
}
 
}

Then I try to use it,

 Mockito.doReturn(false).when(mock).addAll(Mockito.argThat(AdditionalMatchers.not(new IsListOf2Elements())));

But I get an error,

org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
No matchers found for additional matcher Not(?)
-> at my.test.own.Mockito_aTest.test4e(Mockito_aTest.java:136)



Brice Dutheil

unread,
Oct 25, 2016, 8:16:48 AM10/25/16
to mockito
Because the mockito `AdditionalMatchers.not` cannot be used like that, not to be mixed with the hamcrest one.
Using mockito that would be instead `addAll(AdditionalMatchers.not(Mockito.argThat(new IsListOfTwoElements())`.

-- Brice
Replied on a mobile device. May not compile.
_____________________________
From: Eric J. Van der Velden <ericjvan...@gmail.com>
Sent: Tuesday, October 25, 2016 14:02
Subject: [mockito] How to negate an ArgumentMatcher
To: mockito <moc...@googlegroups.com>
--
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 https://groups.google.com/group/mockito.
To view this discussion on the web visit https://groups.google.com/d/msgid/mockito/d50fe25f-7d41-4137-9599-727f8024f566%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Reply all
Reply to author
Forward
0 new messages