### Question:
InvoiceGenerator { public double getAmountWithTax() { return amount + taxCalculator.calculate(amount); } InvoiceGenerator(double amount, TaxCalculator taxCalculator); double getAmountWithTax();  }### Answer:
@Test public void testGenerateTax() { var productCost = 50.0; var tax = 10.0; TaxCalculator taxCalculatorMock = mock(TaxCalculator.class); doReturn(tax).when(taxCalculatorMock).calculate(productCost); target = new InvoiceGenerator(productCost, taxCalculatorMock); Assertions.assertEquals(target.getAmountWithTax(), productCost + tax); verify(taxCalculatorMock, times(1)).calculate(productCost); }