0

Hi i am new to Junit & Mockito. I have code like this:

public class ABCCheckout implements Checkout
{
@Resource
public PrimeConfigService primeConfigService;
/* PrimeConfigService getter & setters  */
@Override
public String getBlackOutDays()
{
    return getPrimeConfigService().findPrimeConfigByUid(RDD_ISA).get(0).getValue();
}
}

I want to verify that this line is called:

return getPrimeConfigService().findPrimeConfigByUid(RDD_ISA).get(0).getValue();

& findPrimeConfigByUid(RDD_ISA) returns a ArrayList of type ProductModel

So how does i achieve it in my ABCCheckoutTest where i have code like this

@UnitTest
@RunWith(MockitoJUnitRunner.class)
public class ABCheckoutTest{
@InjectMocks
private ABCCheckout aBCCheckout;

@Before
    public void setUp()
    {//what should go here//}

    @Test
    public void testGetBlackOutDays()
    {//what should go here//}

}
  • Inject a mock `PrimeConfigService` into `ABCCheckout`, then you can [verify](https://stackoverflow.com/questions/3555472/mockito-verify-method-arguments) those methods of `PrimeConfigService` were invoked. For the builder pattern, the [order](https://stackoverflow.com/questions/21901368/mockito-verify-order-sequence-of-method-calls) of the method invocations probably doesn't matter. – Andrew S Jul 07 '17 at 14:08
  • Note that you shouldn't mock every possible class and method. All you need to mock here is the service PrimeConfigService's findPrimeConfigByUid method. And you should make it return a real list containing a real ProductModel. – JB Nizet Jul 07 '17 at 14:23

0 Answers0