Created
January 10, 2015 13:18
-
-
Save javaeeeee/ad9a8e71a82fb8342933 to your computer and use it in GitHub Desktop.
A test of a withdraw method of an ATM using Mockito and test doubles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(MockitoJUnitRunner.class) | |
public class ATMTest { | |
private ATM sut; | |
@Mock | |
private BankService bankService; | |
@Mock | |
private CashDispenser cashDispenser; | |
@Mock | |
private DepositSlot depositSlot; | |
@Mock | |
private Keypad keypad; | |
@Mock | |
private Screen screen; | |
@Before | |
public void setUp() { | |
sut = new ATM(bankService, cashDispenser, depositSlot, keypad, screen); | |
} | |
@Test | |
public void testWithdrawCashSuccess() throws BankServiceException { | |
//given | |
BigDecimal amount = new BigDecimal("1000"); | |
BigDecimal balance = new BigDecimal("5000"); | |
Mockito.when(keypad.getAmount()).thenReturn(amount); | |
Mockito.when(bankService.getBalance()).thenReturn(balance); | |
Mockito.when(cashDispenser.isThereEnoughMoney(amount)).thenReturn(true); | |
//when | |
sut.withdrawCash(); | |
//then | |
Mockito.verify(bankService, Mockito.times(1)).debit(amount); | |
Mockito.verify(cashDispenser).dispenseCash(amount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment