mardi 24 mars 2015

How can I set Mockito `when` method when instantiating mock objects in Spring?

The method described in this answer best suits me for instantiating my mock objects.



<bean id="dao" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="com.package.Dao" />
</bean>


However, I also need to set the Mockito when method(s).


Can I do that in the XML, or is the only way to to it like:



when( objectToBestTested.getMockedObject()
.someMethod(anyInt())
).thenReturn("helloWorld");


within my test case?


The reason I ask, is because I don't otherwise need a getter for MockedObject, and I'd only be adding a getter so I can test ObjectToBeTested.


Aucun commentaire:

Enregistrer un commentaire