I have:
Map<String, String> vars = new HashMap<String, String>();
String r = restOperations.getForObject(url, String.class, vars);
In my test I try to mock RestOperations:
@Mock
RestOperations restOperations;
when(restOperations.getForObject(Matchers.anyString(), Matchers.eq(String.class), Matchers.notNull())).thenReturn("ok");
This never get triggered.
Does anyboy see why?
I believe the problem is with method overloading.
getForObjecthas two overloaded versions taking three arguments:You are actually mocking the second one while you want to mock the first one. To help the static method resolution cast the
notNull()matches explicitly:Or even better, use
anyMap():