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

Mocking Files.copy in spring boot unit test
JukitoRunner, bind mock of final class
java.lang.NoSuchMethodError: org.springframework.http.MediaType.getCharset()Ljava/nio/charset/Charset;
Mockito:how to match Class<T> [duplicate]
Mock Static Instance
Spring MVC test and PowerMock failing with Cannot load JDBC driver
How to stub a method of an class annotated with #InjectMocks?
Could not initialize plugin: interface org.mockito.plugins.MockMaker
How to mock a Hibernate query using mockito
Junit with Mockito
mockito NullPointerException
PowerMock: mocking multiple calls of same method with different parameters behave abnormally
Enable Mockito opt-in only for special classes
Mocking Interfaces with Kotlin and Mockito
what`s the scope of mockito verify?
Is it possible to use doReturn() and CALLS_REAL_METHODS with mockito-kotlin?

Categories

HOME
pdf
client
variables
atom-editor
oracle11g
read-eval-print-loop
xmpp
setup-deployment
react-redux
amortized-analysis
fsm
fingerprint
webrequest
slurm
kibana-4
dynamics-crm-online
caml
propel
contextmenu
numerical-methods
vlsi
fifo
kendo-datasource
nouislider
react-chartjs
data-manipulation
jspresso
jmonkeyengine
wixsharp
vxworks
main
disassembling
bitbucket-pipelines
multilingual
occlusion
theano.scan
greenrobot-eventbus
gzipstream
reportingservices-2005
google-closure
arena-simulation
slick-3.0
auto-update
outlook-2013
logparser
knockout-components
dtexec
memory-alignment
pdfclown
blacklist
query-performance
smart-table
pycaffe
medium.com
savon
mikroc
mathematica-frontend
qcustomplot
make-install
xpath-1.0
system.management
kendonumerictextbox
xna-4.0
cartesian-product
qdialog
wordml
ionic
cakephp-3.1
responsive-images
service-accounts
event-bubbling
operation
dundas
pretty-print
truevault
modalpopup
asp.net-web-api-odata
android-radiobutton
intentservice
jmapviewer
odata4j
dbconnection
dataservice
yui-compressor
sabredav
distutils
e4x
isnullorempty
online-compilation
regsvr32
bubble-chart
pendrive
code-cleanup
subscript
libc++
disclosure
mongomapper
sef
kdbg
microsoft-virtualization
yagni
caching-application-block

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