How to mock and verify method with argument T

85 views Asked by At

I have a method:

public V doSomething(T t, Class<V> classV){}

how can I invoke this method with the mockObject and verify it?

I'm trying like this:

when(mockObject.doSomething(any(MyConcreteT.class), AnotherConcrete.class).
                thenReturn(obj);    
verify(mockObject).doSomething(any(MyConcreteT.class), AnotherConcrete.class);

but receive an error

InvalidUseOfMatchersException: Invalid use of argument matchers!

appreciate any(help)

1

There are 1 answers

2
Puce On

AFAIK, Mockito requires all parameters to be non-matchers or all parameters to be matchers. It doesn't allow to mix them. (A detailed error message should tell you this, though.)

Try:

when(mySpy.doSomething(any(MyConcreteT.class), eq(AnotherConcrete.class)).
                thenReturn(obj);    
verify(mySpy).doSomething(any(MyConcreteT.class), eq(AnotherConcrete.class));