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

Difference between Mockito #Spy and #Mock(answer = Answers.CALLS_REAL_METHODS)
How to return different child classes using Mockito
Mockito verification is contradicting itself
How to write unit test cases for Endeca application
unable to mock TextMessage
Mockito error “The system cannot find the path specified”
not returning stubbed value in the mockito,its all empty
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

Categories

HOME
image
wso2
debugging
office365api
read-eval-print-loop
bookshelf.js
cvs
spring-cloud-stream
spring-jdbc
leon
microservices
rdf
survey
retrofit
angular-ui-bootstrap
blueprintjs
opengl-es-2.0
webrequest
facebook-messenger-bot
kibana-4
quicklook
vb.net-2010
windows-server-2012
zebra-printers
quickfix
ups
worldwind
tostring
opencover
chromium-embedded
telerik-reporting
intel-pin
web-api-testing
saas
quote
sql-server-2012-express
preg-match
junit5
create-table
fog
caret
lxd
picasso
file-format
serve
streamsets
objectlistview
bootstrapper
greenrobot-eventbus
user-controls
tasker
botbuilder
outlook-api
wso2carbon
filepicker
rails-routing
hendrix
drupal-6
forever
qtwebview
redundancy
blacklist
elements
thrust
transmitfile
qpid
markojs
natvis
prerequisites
tmuxinator
purge
method-parameters
system32
gui-test-framework
relocation
valueconverter
didselectrowatindexpath
robotics-studio
simba
google-email-migration
errai
qtkit
coredump
coercion
locationlistener
self-extracting
android-sdk-2.1
imac
paster
sortable-tables
gallio
.nettiers
avatar
msdev
commodore

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