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

java.lang.NullPointerException at org.powermock.api.mockito.internal.expectation.PowerMockitoStubberImpl.addAnswersForStubbing
The method when(T) in the type Stubber is not applicable for the arguments (void)
Mock static method that calls to external service
JUnit for a method with while loop
The method when(BasePersistenceImpl<capture#2-of ?,Long>) is undefined for the type BusinessServiceImplTest [duplicate]
junit.framework.AssertionFailedError: Exception occured : java.lang.ClassCastException:
org.powermock.reflect.exceptions.TooManyMethodsFoundException
How to match a class with type parameters using mock?
PowerMock and Mockito not working for TestNG
How to write junits for anonymous inner class?
Mockito - Testing method that calls private methods
Mockito: Mock class<T> object
How to mock hibernate getSessionFactory?
Is there an equivalent to anyInt(), anyString(), etc. for checking a parameter is of a particular (non-generic) type?
When can I write Mockito.anyInt()?
How to add java mock objects to hashset?

Categories

HOME
maven
arduino-uno
hive
deployment
listview
keycloak
activiti
server
google-api-php-client
json.net
appx
session
relayjs
electron
mvvmcross
convolution
swagger-ui
maude-system
vault
tomcat6
kentor-authservices
qt-creator
apache-cayenne
spring-tool-suite
worldwind
clojurescript
jqwidget
firefox-webextensions
visual-composer
scichart
emulator
facebook-instant-articles
bootstrap-tour
smb
numerical-methods
sparse-matrix
social-media
gitignore
libssl
procdump
nameservers
noraui
caret
dosbox
sql-server-agent
texmaker
heightmap
s
cubic-spline
long-polling
filepicker
python-webbrowser
sage-one
veracode
rdfs
mplayer
brightcove
sqlbulkcopy
epson
flutterwave
sqldf
dwscript
database-optimization
multi-level
storekit
master-slave
ptrace
system.management
historian
natvis
cartesian-product
retina
computer-algebra-systems
varargs
android-listview
appfabric-cache
sonarqube5.1.2
notify
winddk
asp.net-web-api-odata
gulp-less
terminfo
navigationservice
mysql-error-1062
quartz-graphics
xamlparseexception
gil
quickdialog
propertyeditor
pysimplesoap
tridion-worldserver
postgresql-performance
boost-filesystem
data-loss
heartbeat
sql-server-profiler
coda-slider
mtj
pascal-fc
gacutil

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