Guest User

Untitled

a guest
Feb 21st, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. import static org.junit.Assert.*;
  2. import static org.hamcrest.CoreMatchers.is;
  3. import org.hamcrest.core.Is;
  4. import org.junit.After;
  5. import org.junit.Before;
  6. import org.junit.Rule;
  7. import org.junit.Test;
  8. import org.junit.rules.ExpectedException;
  9.  
  10. public class DebitTest {
  11.  
  12. private BankAccount bankAccount;
  13. private int amount = 1
  14.  
  15. @Before
  16. public void setUp() {
  17. System.out.println("Before: Something really cool");
  18. bankAccount = new BankAccount("Tiki", 10.0);
  19. }
  20.  
  21. @After
  22. public void tearDown() {
  23. System.out.println("After: Something really cool");
  24. }
  25.  
  26. @Test
  27. public void decreaseBalanceAmountTest() throws AccontFrozenException {
  28. int expectedBalance = bankAccount.getBalance() - amount
  29.  
  30. bankAccount.Debit(amount);
  31. assertThat(bankAccount.getBalance(), is(expectedBalance));
  32. }
  33.  
  34. @Rule
  35. public ExpectedException thrown = ExpectedException.none();
  36.  
  37. @Test
  38. public void IfAccountIsFrozenThrowsAccontFrozenExceptionTest() throws AccontFrozenException {
  39. bankAccount.FreezeAccount();
  40.  
  41. thrown.expect(AccontFrozenException.class);
  42. bankAccount.Debit(amount);
  43. }
  44.  
  45. @Test
  46. public void ifAmountIsGreaterThanBalanceThrowsTest() throws AccontFrozenException{
  47. amount = bankAccount.getBalance() + 1
  48.  
  49. thrown.expect(IllegalArgumentException.class);
  50. bankAccount.Debit(amount);
  51. }
  52.  
  53. @Test
  54. public void ifAmountIsLessThanBalanceThrowsTest() throws AccontFrozenException{
  55. amount = -1
  56.  
  57. thrown.expect(IllegalArgumentException.class);
  58. bankAccount.Debit(amount);
  59. }
  60.  
  61. }
Add Comment
Please, Sign In to add comment