I have a function signature I'd like to mock of an External Service.
public <T> void save(T item, AnotherClass anotherClassObject);
Given this function signature, and class name IGenericService how could one mock it with PowerMock?
Or Mockito?
For this generic, I'm using: Class Theodore for the T in T item. For example, I tried using:
doNothing().when(iGenericServiceMock.save(any(Theodore.class),
any(AnotherClass.class));
IntelliJ cranks this:
save(T, AnotherClass) cannot be applied to
(org.Hamcrest.Matcher<Theodore>, org.Hamcrest.Matcher<AnotherClass>)
And it cites the following reason:
reason: No instance(s) of type variable T exist
so that Matcher<T> conforms to AnotherClass
First, the issue ought to solve if the generics argument is handled properly. What are some things one could do in such situations?
UPDATE: As ETO shared:
doNothing().when(mockedObject).methodToMock(argMatcher);
shares the same fate.