Can't figure out the correct way to use matchers to identify which overload of the exchange method I am targetting. The call I am making:
restTemplate.exchange(url, HttpMethod.PUT, httpEntity, Object.class)
I've tried using any(Class.class), and a couple other things but nothing is working. There are 2 methods with a similar signature that I am trying to distinguish between:
exchange(String url, HttpMethod method, @Nullable HttpEntity<?> requestEntity, Class<T> responseType)
and
exchange(String var1, HttpMethod var2, @Nullable HttpEntity<?> var3, ParameterizedTypeReference<T> var4)
Here are my current imports related to Mockito:
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*;
Has anyone been able to mock a call to this method that uses a Class as the 4th parameter instead of a ParameterizedTypeReference?
I am not sure whether I misunderstood your question or the issue mentioned by
@MarciejKowalski
, but when running the test from the issue or what I suppose is similar to your example againstmockito-core-2.23.4
/JDK 1.8.0_151
it works just fine.[I used JUnit 4 for your example instead of JUnit 5]
Most likely you are using the
when().then()
pattern.Try the
doReturn().when()
approach with your matchers.Just make sure you use matchers even for the params that you expect directly (use eq() for this).
Here is the issue and fix on project issue tracker.