Khalil Malik Saboor 8 лет назад
Родитель
Сommit
c0cd7c0dd1

+ 11
- 2
src/main/java/com/zipcoder/payment/Check.java Просмотреть файл

8
 
8
 
9
 
9
 
10
 
10
 
11
-    public Check(long ID, String tia_mowry, String routingNumber, String accountNumber) {
11
+    public Check(long ID, String payerName, String routingNumber, String accountNumber) {
12
+
13
+        this.ID = ID;
14
+        this.payerName = payerName;
15
+        this.accountNumber = getlastfour(accountNumber);
16
+        this.routingNumber = routingNumber;
12
 
17
 
13
     }
18
     }
14
 
19
 
16
 
21
 
17
     }
22
     }
18
 
23
 
24
+    public String getlastfour(String accountNumber){
25
+        return accountNumber.replace(accountNumber.substring(0,accountNumber.length()-4), "");
26
+    }
27
+
19
     public Long getID() {
28
     public Long getID() {
20
         return ID;
29
         return ID;
21
     }
30
     }
25
     }
34
     }
26
 
35
 
27
     public String getShortDescription() {
36
     public String getShortDescription() {
28
-        return "Check " + payerName + " " + accountNumber;
37
+        return "Check " + payerName + " " + "***" + accountNumber;
29
     }
38
     }
30
 
39
 
31
     public String getRoutingNumber() {
40
     public String getRoutingNumber() {

+ 7
- 1
src/main/java/com/zipcoder/payment/PaymentPresenter.java Просмотреть файл

10
         for (Payment o: payments) {
10
         for (Payment o: payments) {
11
             o.getID();
11
             o.getID();
12
             o.getPayerName();
12
             o.getPayerName();
13
-
14
             sb.append(o.getShortDescription()+"\n");
13
             sb.append(o.getShortDescription()+"\n");
15
         }
14
         }
16
         return sb.toString();
15
         return sb.toString();
17
     }
16
     }
18
 
17
 
19
 
18
 
19
+    public String toStringByPayerName(Payment[] payments) {
20
+        return null;
21
+    }
22
+
23
+    public String toStringById(Payment[] payments) {
24
+        return null;
25
+    }
20
 }
26
 }

+ 30
- 0
src/test/java/com/zipcoder/payment/PaymentPresenterTest.java Просмотреть файл

30
         String actual = presenter.toString(payments);
30
         String actual = presenter.toString(payments);
31
         assertEquals(expected, actual);
31
         assertEquals(expected, actual);
32
     }
32
     }
33
+    @Test
34
+    public void toStringByPayerName(){
35
+        Payment[] payments = new Payment[2];
36
+        Payment paypal = new Paypal(4L, "Tamara Mowry", "tamara@mowry.com");
37
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
38
+
39
+        payments[0] = paypal;
40
+        payments[1] = check;
41
+
42
+        PaymentPresenter presenter = new PaymentPresenter();
43
+        String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
44
+
45
+        String actual = presenter.toStringByPayerName(payments);
46
+        assertEquals(expected, actual);
47
+    }
48
+    @Test
49
+    public void toStringByID(){
50
+        Payment[] payments = new Payment[2];
51
+        Payment paypal = new Paypal(120L, "Tamara Mowry", "tamara@mowry.com");
52
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
53
+
54
+        payments[0] = paypal;
55
+        payments[1] = check;
56
+
57
+        PaymentPresenter presenter = new PaymentPresenter();
58
+        String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
59
+
60
+        String actual = presenter.toStringById(payments);
61
+        assertEquals(expected, actual);
62
+    }
33
 }
63
 }