Mexi 8 лет назад
Родитель
Сommit
83308fb9d9

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

@@ -56,7 +56,7 @@ public class Check implements Payment {
56 56
     public String getShortDescription() {
57 57
 
58 58
 
59
-        return "Check" + getPayerName() + " " + "***" + getAccountNumber().substring(accountNumber.length() - 4, accountNumber.length() - 1);
59
+        return "Check" + " "+ getPayerName() + " " + "***" + getAccountNumber().substring(accountNumber.length() - 4, accountNumber.length());
60 60
     }
61 61
 
62 62
     public int compareTo(Payment o) {

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

@@ -5,6 +5,14 @@ public class PayPal implements Payment {
5 5
     private String payerName;
6 6
     private String email;
7 7
 
8
+    public PayPal(){};
9
+
10
+    public PayPal(long id, String payerName, String email){
11
+        this.id = id;
12
+        this.payerName = payerName;
13
+        this.email = email;
14
+    }
15
+
8 16
     public Long getId() {
9 17
         return this.id;
10 18
     }
@@ -34,7 +42,7 @@ public class PayPal implements Payment {
34 42
 
35 43
     public String getShortDescription() {
36 44
 
37
-        return "PayPal" + getPayerName() + " " + getEmail();
45
+        return "PayPal" + " " + getPayerName() + " " + getEmail();
38 46
     }
39 47
 
40 48
     public int compareTo(Payment o) {

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

@@ -1,6 +1,30 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
+import java.util.Arrays;
4
+
3 5
 public class PaymentPresenter {
4 6
 
7
+    private  Payment payment;
8
+    private int n;
9
+    public String toString(Payment[] payments){
10
+        if(payments.length == 0) {
11
+
12
+            return "";
13
+        }
14
+        else {
15
+
16
+
17
+            Arrays.sort(payments, new PaymentSortByDescription());
18
+            StringBuilder sb = new StringBuilder();
19
+            for (Payment p : payments) {
20
+                System.out.println(p.getShortDescription());
21
+                sb.append(p.getShortDescription() + "\n");
22
+            }
23
+
24
+            return sb.toString();
25
+
26
+        }
27
+
28
+    }
5 29
 
6 30
 }

+ 12
- 0
src/main/java/com/zipcoder/payment/PaymentSortByDescription.java Просмотреть файл

@@ -0,0 +1,12 @@
1
+package com.zipcoder.payment;
2
+
3
+import java.util.Comparator;
4
+
5
+public class PaymentSortByDescription implements Comparator<Payment> {
6
+
7
+    public int compare(Payment o1, Payment o2) {
8
+        int n = o1.getShortDescription().compareTo(o2.getShortDescription());
9
+        return n;
10
+
11
+    }
12
+}

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

@@ -1,4 +1,35 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
3 6
 public class PaymentPresenterTest {
7
+
8
+    @Test
9
+    public void toStringNoPaymentTest(){
10
+        Payment[] payments = new Payment[0];
11
+        PaymentPresenter presenter = new PaymentPresenter();
12
+        String expected = "";
13
+
14
+        String actual = presenter.toString(payments);
15
+
16
+        Assert.assertEquals(expected, actual);
17
+    }
18
+
19
+    @Test
20
+    public void toStringHasPaymentTest() {
21
+        Payment[] payments = new Payment[2];
22
+        Payment paypal = new PayPal(4L, "Tia Mowry", "tia@mowry.com");
23
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
24
+
25
+        payments[0] = paypal;
26
+        payments[1] = check;
27
+
28
+        PaymentPresenter presenter = new PaymentPresenter();
29
+        String expected = "Check Tia Mowry ***4551\nPayPal Tia Mowry tia@mowry.com\n";
30
+
31
+        String actual = presenter.toString(payments);
32
+        Assert.assertEquals(expected, actual);
33
+
34
+    }
4 35
 }