How stub instanseof in Mockito in java?
I have method that accept argument of Object type. But inside of method checked if is e.g. List type. Is possible in mockito to stub it? E.g.
public void checkValue(Object arg) {
if (arg instanceof List) {
....
So in mockito:
开发者_如何学JAVAObject myObject=mock(Object.class);
After I need write something like:
when (myObject instanceof List).thenReturn List
How it can be done? Thanks.
Sure, you can mock how ever you want. Ex:
Object o = mock(List.class);
There is an advice that states
Do not mock types you don't own
So your test should accept an instance of a real list object new ArrayList()
instead of a mock.
Should you only mock types you own?
精彩评论