I'm trying write unit tests for the class which has a
restTemplate.getForObject( Url, Response.class);
I've mocked the RestTemplate in the test class still when I run test case, request hit's server and I get error
restTemplate.getForObject(configDiyUrl, BaseResponse.class);
error:
I/O error on GET request for "http://localhost:8080/WMService/api/v1/BulkDataSync": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
I've mocked the RestTemplate like this,
@Mock
RestTemplate restTemplate
then I've written the when/then mocking like this,
when(restTemplate.getForObject(anyString(), eq(Response.class))).thenReturn(br);
still when I run test case I get above mentioned error.
As per my understanding it should not hit the server when it is mocked.
I'm looking for some help about mocking RestTemplate so that it won't hit server.
I've gone throgh this example still I'm getting error as it hit's server.