I have a SenderService class as shown below.
I am using the restTemplate object to call a url. How should I write a junit test for this by ONLY using Mockito ?
I have already tried creating a spy for my class but its not working
@Service public class SenderServiceImpl implements SenderService{ @Autowired private Logger logger; private RestTemplate restTemplate = new RestTemplate(); @Override public void sendNotification(SenderNotification notification) { try { HttpEntity sendRequestBody = new HttpEntity<> (notification,headers); response = restTemplate.postForEntity(url,sendRequestBody,String.class); } }
RestTemplateinstance to the constructor ofSenderServiceImplso that you can mock it, instead of creating it inside the class