Nicholas Maidanos 8 лет назад
Родитель
Сommit
3c87bfe542

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

@@ -2,6 +2,6 @@ package com.zipcoder.payment;
2 2
 
3 3
 public class PaymentPresenter {
4 4
 
5
-
5
+    public
6 6
 
7 7
 }

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

@@ -0,0 +1,16 @@
1
+package com.zipcoder.payment;
2
+
3
+import java.util.Comparator;
4
+
5
+public class PaymentSortByPayer implements Comparator<Payment> {
6
+
7
+    public int compare(Payment o1, Payment o2) {
8
+        if(o1.getPayerName().compareTo(o2.getPayerName()) > 0){
9
+            return 1;
10
+        } else if(o1.getPayerName().compareTo(o2.getPayerName()) < 0){
11
+            return -1;
12
+        } else {
13
+            return 0;
14
+        }
15
+    }
16
+}

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

@@ -1,4 +1,23 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
-public class PaymentPresenterTest {
3
+import org.junit.Test;
4
+import static org.junit.jupiter.api.Assertions.*;
5
+
6
+class PaymentPresenterTest {
7
+
8
+    @Test
9
+    void emptyTestOne() {
10
+        //When
11
+        Payment[] payments = new Payment[0];
12
+        PaymentPresenter presenter = new PaymentPresenter();
13
+
14
+        //Expect
15
+        String expected = "";
16
+
17
+        //Actual
18
+        String actual = presenter.toString(payments);
19
+
20
+        assertEquals(expected, actual);
21
+    }
22
+
4 23
 }

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

@@ -0,0 +1,56 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.jupiter.api.Test;
4
+
5
+import static org.junit.jupiter.api.Assertions.*;
6
+
7
+class PaymentSortByPayerTest {
8
+
9
+    @Test
10
+    void compairTest1() {
11
+        //When
12
+        PaymentSortByPayer ps = new PaymentSortByPayer();
13
+        Payment cc = new CreditCard(12, 4111131,"Jimmy Maidanos", 4, 11);
14
+        Payment pp = new Paypal(23, "Nicholas Maidanos", "nmaidanos@gmail.com");
15
+
16
+        //Expect
17
+        int expect = -1;
18
+
19
+        //Actual
20
+        int actual = ps.compare(cc, pp);
21
+
22
+        assertEquals(expect, actual);
23
+    }
24
+
25
+    @Test
26
+    void compairTest2() {
27
+        //When
28
+        PaymentSortByPayer ps = new PaymentSortByPayer();
29
+        Payment cc = new CreditCard(12, 4111131,"Zimmy Maidanos", 4, 11);
30
+        Payment pp = new Paypal(23, "Nicholas Maidanos", "nmaidanos@gmail.com");
31
+
32
+        //Expect
33
+        int expect = 1;
34
+
35
+        //Actual
36
+        int actual = ps.compare(cc, pp);
37
+
38
+        assertEquals(expect, actual);
39
+    }
40
+
41
+    @Test
42
+    void compairTest3() {
43
+        //When
44
+        PaymentSortByPayer ps = new PaymentSortByPayer();
45
+        Payment cc = new CreditCard(12, 4111131,"Nicholas Maidanos", 4, 11);
46
+        Payment pp = new Paypal(23, "Nicholas Maidanos", "nmaidanos@gmail.com");
47
+
48
+        //Expect
49
+        int expect = 0;
50
+
51
+        //Actual
52
+        int actual = ps.compare(cc, pp);
53
+
54
+        assertEquals(expect, actual);
55
+    }
56
+}