I have a service method with restTemplate. As part of unit test, I am trying to mock it but some how failing.
Service Method:
@Autowired
private RestTemplate getRestTemplate;
return getRestTemplate.getForObject(restDiagnosisGetUrl, SfdcCustomerResponseType.class);
Test Method:
private CaresToSfdcResponseConverter caresToSfdcResponseConverter;
@Before
public void setUp() throws Exception {
caresToSfdcResponseConverter = new CaresToSfdcResponseConverter();
}
@Test
public void testConvert(){
RestTemplate mock = Mockito.mock(RestTemplate.class);
Mockito.when(mock.getForObject(Matchers.anyString(), Matchers.eq(SfdcCustomerResponseType.class))).thenReturn(sfdcCustomerResponseType);
}
sfdcRequest = caresToSfdcResponseConverter.convert(responseForSfdcAndHybris);
It is giving NullPointerException. Looks like it is failing to mock rest template and it is breaking there as rest template is null. Any help would appreciated.Thanks