In fact, the signature of the @Mock
method does not match the signature of the mocked method, as the exception message says.
To see why, notice there is only one real implementation of the RestTemplate#getForObject(String, Class, Object[])
method. Then, consider what would happen for the following call:
Integer i = restTemplate.getForObject("...", Integer.class);
Naturally, this call should not redirect to a @Mock
method having a return type of String
.
So, the correct mock method should be:
new MockUp<RestTemplate>() {
@Mock
<T> T getForObject(String url, Class<T> responseType, Object... urlVariables) {
return (T) "{(\"error\": \"missing data id\", \"data_id\":2001)}";
}
};