Advertisement
spiny94

Untitled

Sep 13th, 2015
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. package it.polito.po.test;
  2. import junit.framework.TestCase;
  3.  
  4.  
  5. import BankServices.Account;
  6. import BankServices.Bank;
  7. import BankServices.InvalidCode;
  8. import BankServices.InvalidValue;
  9.  
  10.  
  11. public class TestR2_Operations extends TestCase {
  12. Bank b1;
  13.  
  14. public void setUp() throws Exception {
  15. b1 = new Bank("Uncle-$crooge");
  16. assertNotNull(b1);
  17. }
  18.  
  19. public void test_initialValue() {
  20. int c1 = b1.createAccount("John", 5, 500.5);
  21. Account a1 = null;
  22. try{
  23. a1 = b1.getAccount(c1);
  24. }
  25. catch(InvalidCode ic) {
  26. fail("code 1 is valid");
  27. }
  28. String[] s = a1.toString().split("\\s*,\\s*");
  29. assertEquals("500.5", s[3]);
  30. }
  31.  
  32. public void test_depositedValue() {
  33. int c1 = b1.createAccount("John", 5, 500.5);
  34. Account a1 = null;
  35. try{
  36. b1.deposit(c1, 7, 360.);
  37. a1 = b1.getAccount(c1);
  38. }
  39. catch(InvalidCode ic) {
  40. fail("code 1 is valid");
  41. }
  42. String[] s = a1.toString().split("\\s*,\\s*");
  43. assertEquals("860.5", s[3]); <------------------ERRORE
  44. }
  45.  
  46. public void test_withdrawedValue() {
  47. int c1 = b1.createAccount("John", 5, 500.5);
  48. Account a1 = null;
  49. try{
  50. b1.withdraw(c1, 7, 360.);
  51. a1 = b1.getAccount(c1);
  52. }
  53. catch(InvalidCode ic) {
  54. fail("code 1 is valid");
  55. }
  56. catch(InvalidValue iv) {
  57. fail("value 360. is valid");
  58. }
  59. String[] s = a1.toString().split("\\s*,\\s*");
  60. assertEquals("140.5", s[3]);
  61. }
  62.  
  63. public void test_transferredValue() {
  64. int c1 = b1.createAccount("John", 5, 500.5);
  65. int c2 = b1.createAccount("John", 20, 800.);
  66. Account a1 = null, a2 = null;
  67. try{
  68. b1.transfer(c1, c2, 8, 400);
  69. a1 = b1.getAccount(c1);
  70. a2 = b1.getAccount(c2);
  71. }
  72. catch(InvalidCode ic) {
  73. fail("codes 1 and 2 are valid");
  74. }
  75. catch(InvalidValue iv) {
  76. fail("value 400. is valid");
  77. }
  78. String[] s1 = a1.toString().split("\\s*,\\s*");
  79. assertEquals("100.5", s1[3]);
  80. String[] s2 = a2.toString().split("\\s*,\\s*");
  81. assertEquals("1200.0", s2[3]);
  82. }
  83.  
  84. public void test_deletedAcount() {
  85. int c1 = b1.createAccount("John", 5, 500.5);
  86. Account a1 = null;
  87. try{
  88. a1 = b1.deleteAccount(c1,50);
  89. }
  90. catch(InvalidCode ic) {
  91. fail("code 1 is valid");
  92. }
  93. String[] s1 = a1.toString().split("\\s*,\\s*");
  94. assertEquals("0.0", s1[3]); <---------------------ERRORE
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement