mockito


InvalidUseOfMatchersException when mocking datasource


#Test
public void getRelationInteractionDataTest() throws Exception {
InteractionData iData = new InteractionData();
when(mockJdbcTemplate.getDataSource()).thenReturn(dataSource);
relationshipCheckDaoImpl.getRelationInteractionData(Mockito.anyString(), Mockito.anyString());
}
Exception:failed with = org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
0 matchers expected, 3 recorded:
relationshipCheckDaoImpl.getRelationInteractionData(Mockito.anyString(), Mockito.anyString());
While it may sound alluring to test a method with 'any' parameter, no, this isn't what matchers are for. Use actual values instead:
relationshipCheckDaoImpl.getRelationInteractionData("a", "b");
The reason is: You can use matchers when preparing a mock method...
Mockito.when( a.doB( Mockito.anyString() ) ).thenReturn("XYZ";
...or when verifying that something was called...
Mockito.verify( a ).doB( Mockito.anyString() );
...but not when calling the method itself, since what should the matchers match there? This will only confuse Mockito's internal system.

Related Links

Stubbing a method with three arguments using mockito
How to mock an array of interfaces using powermock or mockito
How to write mockIto test case for interface object creation and declaration
java.lang.AbstractMethodError: abstract method when running espresso on Kotlin with Mockito
ClassNotFoundException with Mockito 2 in OSGI
What is the point of a spied instance
Mockito NullPointerException DataSourceTransactionManager.getTransaction()
How powermockito intercept new instance?
What's the different of <reified T> with <reified T: Any> in Kotlin?
Parameter specified as non-null is null when using Mokito anyObject() on Kotlin function
java.lang.reflect.InvocationTargetException when using Kotlin-Mokito library
How to execute original method in Mockito after Answer on Spy object
How to use MockMvcResultMatchers.jsonpath to do test?
Mockito - calling a stubbed method from non-stubbed one
How do I use Mockito to test that a Java 8 Stream had the expected values?
Stubbing of mockito mock object on spock-based test

Categories

HOME
single-sign-on
alfresco
rsyslog
programming-languages
spring-cloud-stream
retrofit
networkx
vault
wheelnav.js
rascal
modx-revolution
modelica
leiningen
designer
clearcase-ucm
pugjs
one-hot-encoding
jndi
emgucv
apache-commons-io
publish
jspm
media-queries
ecto
galsim
subset-sum
xmlreader
streamreader
azure-ml
user-controls
core-plot
user-accounts
termination
komodoedit
pebble-watch
powercli
veracode
fancybox-2
zendesk-app
cudafy.net
dynamics-sl
query-performance
word-vba-mac
visual-c++-2008
slicknav
fody
merge-conflict-resolution
xml-attribute
plottable.js
persist
nessus
oauth2client
pyke
iad
intellij-14
cyclomatic-complexity
metaclass
wireshark-dissector
browser-bugs
method-parameters
apache-commons-fileupload
sonarqube5.1.2
inmobi
camanjs
javafx-webengine
mesa
eol
jubula
openlaszlo
ril
buster.js
eventual-consistency
jquery-mobile-dialog
eventlistener
flashvars
anonymous-methods
libstdc++
bluepill
postgresql-performance
spring-portlet-mvc
work-stealing
mercurial-server
doh
zpt
infobox
yetanotherforum
mongomapper
dbal
yagni
premature-optimization
multiple-languages

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App