Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. import junit.framework.TestCase;
  2. import org.junit.*;
  3. import static org.junit.Assert.*;
  4.  
  5. import put.io.tdd.dusigrosz.BankAccount;
  6. import put.io.tdd.dusigrosz.IllegalDepositValueException;
  7. import put.io.tdd.dusigrosz.IllegalInterestRate;
  8. import put.io.tdd.dusigrosz.IllegalTransferException;
  9. import put.io.tdd.dusigrosz.IllegalWithdrawValueException;
  10. import put.io.tdd.dusigrosz.InsufficientFundsException;
  11. import put.io.tdd.dusigrosz.InterestCapitalizationType;
  12. import put.io.tdd.dusigrosz.NegativeTransferException;
  13.  
  14. public class BankAccountTest {
  15. private BankAccount account;
  16. @Before
  17. public void setUp() throws Exception {
  18. account = new BankAccount();
  19. }
  20.  
  21. @Test(expected=IllegalInterestRate.class)
  22. public void testInterest2(){
  23. account.setInterestRate(-1);
  24. }
  25.  
  26. @Test
  27. public void testInterest4(){
  28. account.deposit(1000);
  29. account.setInterestRate(360);
  30. account.setCapitalizationType(InterestCapitalizationType.Dzien);
  31. double balance = account.getBalanceAfterDays(1);
  32. assertEquals(balance, 1010.0, 0.00001);
  33. }
  34.  
  35. @Test
  36. public void testInterest3(){
  37. account.deposit(1000);
  38. account.setInterestRate(2.4);
  39. account.setCapitalizationType(InterestCapitalizationType.Miesiac);
  40. double balance = account.getBalanceAfterDays(360);
  41. assertEquals(balance, 1024.27, 0.00001);
  42. }
  43.  
  44. @Test
  45. public void testInterest(){
  46. account.deposit(1000);
  47. account.setInterestRate(1.2);
  48. account.setCapitalizationType(InterestCapitalizationType.Miesiac);
  49. double balance = account.getBalanceAfterDays(30);
  50. assertEquals(balance, 1001, 0.00001);
  51. }
  52.  
  53. @Test(expected=IllegalTransferException.class)
  54. public void testTransfer3() throws IllegalDepositValueException, IllegalTransferException, NegativeTransferException{
  55. account.deposit(1500);
  56. BankAccount acc2 = new BankAccount();
  57.  
  58. account.transfer(acc2, 2000);
  59. }
  60.  
  61. @Test(expected=NegativeTransferException.class)
  62. public void testTransfer2() throws IllegalDepositValueException, IllegalTransferException, NegativeTransferException{
  63. account.deposit(1500);
  64. BankAccount acc2 = new BankAccount();
  65.  
  66. account.transfer(acc2, -500);
  67. }
  68.  
  69. @Test
  70. public void testTransfer() throws IllegalDepositValueException, IllegalTransferException, NegativeTransferException{
  71. account.deposit(1500);
  72.  
  73. BankAccount acc2 = new BankAccount();
  74. double balance = acc2.getBalance();
  75. assertEquals(balance, 0.0, 0.000001);
  76. balance = account.getBalance();
  77. assertEquals(balance, 1500.0, 0.000001);
  78.  
  79. account.transfer(acc2, 1000);
  80.  
  81. balance = acc2.getBalance();
  82. assertEquals(balance, 1000.0, 0.000001);
  83. balance = account.getBalance();
  84. assertEquals(balance, 500.0, 0.000001);
  85. }
  86.  
  87. @Test
  88. public void testDeposit() throws IllegalDepositValueException {
  89. account.deposit(5000);
  90. double balance = account.getBalance();
  91. assertEquals(balance, 5000.0, 0.000001);
  92. }
  93.  
  94. @Test
  95. public void testDepositAndWithdraw() throws IllegalWithdrawValueException, InsufficientFundsException, IllegalDepositValueException {
  96. double balance = account.getBalance();
  97. assertEquals(balance, 0.0, 0.000001);
  98.  
  99. account.deposit(1000);
  100. account.withdraw(500);
  101.  
  102. balance = account.getBalance();
  103. assertEquals(balance, 500.0, 0.000001);
  104. }
  105.  
  106. @Test(expected=InsufficientFundsException.class)
  107. public void testDepositAndWithdraw2() throws IllegalDepositValueException, IllegalWithdrawValueException, InsufficientFundsException {
  108. double balance = account.getBalance();
  109. assertEquals(balance, 0.0, 0.000001);
  110.  
  111. account.deposit(1000);
  112. account.withdraw(2000);
  113. }
  114.  
  115. @Test
  116. public void testDeposit2() throws IllegalDepositValueException {
  117. double balance = account.getBalance();
  118. assertEquals(balance, 0.0, 0.000001);
  119.  
  120. account.deposit(1000);
  121. balance = account.getBalance();
  122. assertEquals(balance, 1000.0, 0.000001);
  123.  
  124. account.deposit(200);
  125. balance = account.getBalance();
  126. assertEquals(balance, 1200.0, 0.000001);
  127.  
  128. account.deposit(300);
  129. balance = account.getBalance();
  130. assertEquals(balance, 1500.0, 0.000001);
  131. }
  132.  
  133. @Test(expected=IllegalDepositValueException.class)
  134. public void testNegativeDeposit() throws IllegalDepositValueException {
  135. account.deposit(-100);
  136. }
  137.  
  138. @Test(expected=IllegalWithdrawValueException.class)
  139. public void testDepositAndNegativeWithdraw() throws IllegalDepositValueException, IllegalWithdrawValueException, InsufficientFundsException {
  140. double balance = account.getBalance();
  141. assertEquals(balance, 0.0, 0.000001);
  142.  
  143. account.deposit(1000);
  144. account.withdraw(-100);
  145. }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement