Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. public void testWithdraw() {
  2.  
  3. //Create account with the following information
  4. Account myBankAccount = new Account(100.0, "SEK", 250.0);
  5. assertEquals("The value of the account shall be 100", 100.0, myBankAccount.getBalance(), 0);
  6.  
  7. //Amount to withdraw and check that it isn't a negative value
  8. double amountToWithdraw = 50.0;
  9. assertTrue(amountToWithdraw > 0);
  10.  
  11.  
  12. //Make sure that the amount we want to withdraw isn't higher than the amount allowed
  13. double maxWithdrawAmount = myBankAccount.getBalance() + myBankAccount.getMaxOverdrawn();
  14. assertTrue((maxWithdrawAmount - amountToWithdraw) > 0);
  15.  
  16. //Proceed with the withdrawel and make sure it is correct
  17. myBankAccount.withdraw(amountToWithdraw);
  18. assertEquals("The value of the account shall be 50", 50.0, myBankAccount.getBalance(), 0);
  19.  
  20.  
  21. }
  22.  
  23. @Test
  24. public void testDeposit() {
  25.  
  26. //Create account with the following information
  27. Account myBankAccount = new Account(100.0, "SEK", 250.0);
  28. assertEquals("The value of the account shall be 100", 100.0, myBankAccount.getBalance(), 0);
  29.  
  30. //Amount to deposit and in what currency that is
  31. double amountToDeposit = 100.0;
  32. String depCurrCode = "SEK";
  33.  
  34. //Checks that the currency is the same
  35. assertEquals(depCurrCode,myBankAccount.getCurrency());
  36.  
  37.  
  38. //This assert performs a check where it makes sure that the value that is inputet is not of
  39. //negative value, since you can only deposit positive amount of money.
  40. assertTrue( amountToDeposit > 0);
  41.  
  42. //Perform the deposit and check that it is correct
  43. myBankAccount.deposit(amountToDeposit);
  44. assertEquals("The value of the account shall be 200", 200.0, myBankAccount.getBalance(), 0);
  45.  
  46. }
  47.  
  48. @Test
  49. public void testConvertToCurrency() {
  50. Account myBankAccount = new Account(100.0, "SEK", 250.0);
  51. assertEquals("The value of the account shall be 100", 100.0, myBankAccount.getBalance(), 0);
  52.  
  53. //Make The conversition to US dollars
  54. String convertToString = "USD";
  55. double currRate = 1.2;
  56.  
  57. //Make sure that the currency we want to convert to isn't the currency already applied on the account.
  58. assertEquals(convertToString, myBankAccount.getCurrency());
  59.  
  60. myBankAccount.convertToCurrency(convertToString, currRate);
  61.  
  62. //Make sure the conversition went ok
  63. assertEquals(120.0, myBankAccount.getBalance(), 0);
  64. assertEquals(convertToString, myBankAccount.getCurrency());
  65.  
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement