Skip to content

Instantly share code, notes, and snippets.

@javaeeeee
Created January 10, 2015 13:22
Show Gist options
  • Save javaeeeee/c82dc85b05225bd16d79 to your computer and use it in GitHub Desktop.
Save javaeeeee/c82dc85b05225bd16d79 to your computer and use it in GitHub Desktop.
A mockito test to make sure only desired interactions took place
@Test
public void testWithdrawCashNotEnoughMoneyOnAccount() throws BankServiceException {
//given
BigDecimal amount = new BigDecimal("1000");
BigDecimal balance = new BigDecimal("500");
Mockito.when(keypad.getAmount()).thenReturn(amount);
Mockito.when(bankService.getBalance()).thenReturn(balance);
Mockito.when(cashDispenser.isThereEnoughMoney(amount)).thenReturn(true);
//when
sut.withdrawCash();
//then
Mockito.verifyZeroInteractions(cashDispenser);
Mockito.verify(bankService, Mockito.times(0))
.debit(Mockito.any(BigDecimal.class));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment