public class Card
{
public double roundMoney(double currencyValue , int digits) {
//some logic for rounding which includes heavy service calling
}
}
Now I want to mock the class and whenever the roundMoney methods is called with parameters I want it to return the product of the parameters
Card mycard = mock(Card.class);
when(mycard.roundMoney(anyDouble(), anyInt()).thenReturn( anyDouble() * anyInt() ));
How can I achieve this?
Use thenAnswer instead of thenReturn? The answer implementation has access to the parameter values being passed.
See: Making a mocked method return an argument that was passed to it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With