title: unit test Spring boot service class that has dependency on another service class
body: <p>I am writing up a spring boot rest service in which am trying to unit test a class annotated with @Service.
  This service class internally uses another service class.
  Here is the code :</p>
  
  <pre><code>@Service
  public class TieredClaimServiceImpl implements TieredClaimService {
  
  //this is the second service used within 
  // commented out setter injection and used constructor injection 
  // @Autowired
  private DiscountTierService discountTierService;
  
  @Autowired
  public TieredClaimServiceImpl(MerchRepository merchRepository,SalesRepository 
           salesRepository,DiscountTierService discountTierService) {
      this.merchRepository = merchRepository;
      this.salesRepository = salesRepository;
      this.discountTierService = discountTierService;
  }
  </code></pre>
  
  <p>Here is the method within the class that I would need to unit test :</p>
  
  <pre><code>@Override
  public List &lt;TieredClaimDto&gt;  calculateClaim(ClaimRequestDto claimRequestDto,String xAppCorelationId) throws SystemException {
  
      /** get the discount tier config data  - this is where we are using the other service **/
      List&lt;DiscountTierDto&gt; discountTierList = discountTierService.get();
  </code></pre>
  
  <p>I would like to mock the 'DiscountTierService' used within 'TieredClaimServiceImpl'</p>
  
  <p>In my unit test class I tried to mock the call being made to this service :</p>
  
  <pre><code>DiscountTierService discountTierService = mock(DiscountTierService.class);
  </code></pre>
  
  <p>OR      </p>
  
  <pre><code>DiscountTierService discountTierService = spy(new DiscountTierServiceImpl());
  </code></pre>
  
  <p>Neither of these worked .</p>
  
  <p>Though not directly related I had a question related to this entire solutioning <a href="https://stackoverflow.com/questions/59102896/spring-boot-which-slice-to-use-for-testing-service-component">here</a></p>