Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import static org.junit.Assert.*;
- import static org.hamcrest.CoreMatchers.is;
- import org.hamcrest.core.Is;
- import org.junit.After;
- import org.junit.Before;
- import org.junit.Rule;
- import org.junit.Test;
- import org.junit.rules.ExpectedException;
- public class DebitTest {
- private BankAccount bankAccount;
- private int amount = 1
- @Before
- public void setUp() {
- System.out.println("Before: Something really cool");
- bankAccount = new BankAccount("Tiki", 10.0);
- }
- @After
- public void tearDown() {
- System.out.println("After: Something really cool");
- }
- @Test
- public void decreaseBalanceAmountTest() throws AccontFrozenException {
- int expectedBalance = bankAccount.getBalance() - amount
- bankAccount.Debit(amount);
- assertThat(bankAccount.getBalance(), is(expectedBalance));
- }
- @Rule
- public ExpectedException thrown = ExpectedException.none();
- @Test
- public void IfAccountIsFrozenThrowsAccontFrozenExceptionTest() throws AccontFrozenException {
- bankAccount.FreezeAccount();
- thrown.expect(AccontFrozenException.class);
- bankAccount.Debit(amount);
- }
- @Test
- public void ifAmountIsGreaterThanBalanceThrowsTest() throws AccontFrozenException{
- amount = bankAccount.getBalance() + 1
- thrown.expect(IllegalArgumentException.class);
- bankAccount.Debit(amount);
- }
- @Test
- public void ifAmountIsLessThanBalanceThrowsTest() throws AccontFrozenException{
- amount = -1
- thrown.expect(IllegalArgumentException.class);
- bankAccount.Debit(amount);
- }
- }
Add Comment
Please, Sign In to add comment