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

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

@@ -1,9 +1,10 @@
1
-package com.zipcoder.payment;
1
+package com.zipcoder;
2 2
 
3
-import com.zipcoder.paymentSort.ById;
4
-import com.zipcoder.paymentSort.ByPayer;
5
-import com.zipcoder.paymentSort.PaymentOrder;
6
-import com.zipcoder.paymentSort.ByShortDescription;
3
+import com.zipcoder.payment.Payment;
4
+import com.zipcoder.payment.Comparators.Id;
5
+import com.zipcoder.payment.Comparators.Payer;
6
+import com.zipcoder.payment.Comparators.PaymentOrder;
7
+import com.zipcoder.payment.Comparators.ShortDescription;
7 8
 
8 9
 import java.util.Comparator;
9 10
 
@@ -22,7 +23,6 @@ public class PaymentPresenter {
22 23
 
23 24
         for(int i = 0; i < payments.length; i++){
24 25
             sb.append(payments[i].getShortDescription());
25
-            sb.append("\n");
26 26
         }
27 27
 
28 28
         return sb.toString();
@@ -35,13 +35,13 @@ public class PaymentPresenter {
35 35
     public void orderBy(Payment[] payments){
36 36
         switch(this.order){
37 37
             case SHORTDESCRIPTION:
38
-                this.bubbleSort(payments, new ByShortDescription());
38
+                this.bubbleSort(payments, new ShortDescription());
39 39
                 break;
40 40
             case PAYERNAME:
41
-                this.bubbleSort(payments, new ByPayer());
41
+                this.bubbleSort(payments, new Payer());
42 42
                 break;
43 43
             case ID:
44
-                this.bubbleSort(payments, new ById());
44
+                this.bubbleSort(payments, new Id());
45 45
                 break;
46 46
             default:
47 47
                 break;

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

@@ -63,6 +63,14 @@ public class Check implements Payment {
63 63
     }
64 64
 
65 65
     public int compareTo(Payment o) {
66
-        return 0;
66
+        int result = this.getShortDescription().compareTo(o.getShortDescription());
67
+        if(result > 0){
68
+            return 1;
69
+        } else if(result < 0){
70
+            return -1;
71
+        } else {
72
+            return 0;
73
+        }
67 74
     }
75
+
68 76
 }

src/main/java/com/zipcoder/paymentSort/ById.java → src/main/java/com/zipcoder/payment/Comparators/Id.java Просмотреть файл

@@ -1,10 +1,10 @@
1
-package com.zipcoder.paymentSort;
1
+package com.zipcoder.payment.Comparators;
2 2
 
3 3
 import com.zipcoder.payment.Payment;
4 4
 
5 5
 import java.util.Comparator;
6 6
 
7
-public class ById implements Comparator<Payment> {
7
+public class Id implements Comparator<Payment> {
8 8
 
9 9
     public int compare(Payment o1, Payment o2) {
10 10
         String id1 = Long.toString(o1.getId());

src/main/java/com/zipcoder/paymentSort/ByPayer.java → src/main/java/com/zipcoder/payment/Comparators/Payer.java Просмотреть файл

@@ -1,10 +1,10 @@
1
-package com.zipcoder.paymentSort;
1
+package com.zipcoder.payment.Comparators;
2 2
 
3 3
 import com.zipcoder.payment.Payment;
4 4
 
5 5
 import java.util.Comparator;
6 6
 
7
-public class ByPayer implements Comparator<Payment> {
7
+public class Payer implements Comparator<Payment> {
8 8
 
9 9
     public int compare(Payment o1, Payment o2) {
10 10
         if(o1.getPayerName().compareTo(o2.getPayerName()) > 0){

src/main/java/com/zipcoder/paymentSort/PaymentOrder.java → src/main/java/com/zipcoder/payment/Comparators/PaymentOrder.java Просмотреть файл

@@ -1,4 +1,4 @@
1
-package com.zipcoder.paymentSort;
1
+package com.zipcoder.payment.Comparators;
2 2
 
3 3
 public enum PaymentOrder {
4 4
     ID, PAYERNAME, SHORTDESCRIPTION

src/main/java/com/zipcoder/paymentSort/ByShortDescription.java → src/main/java/com/zipcoder/payment/Comparators/ShortDescription.java Просмотреть файл

@@ -1,10 +1,10 @@
1
-package com.zipcoder.paymentSort;
1
+package com.zipcoder.payment.Comparators;
2 2
 
3 3
 import com.zipcoder.payment.Payment;
4 4
 
5 5
 import java.util.Comparator;
6 6
 
7
-public class ByShortDescription implements Comparator<Payment> {
7
+public class ShortDescription implements Comparator<Payment> {
8 8
 
9 9
     public int compare(Payment o1, Payment o2) {
10 10
         String str1 = o1.getShortDescription();

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

@@ -44,6 +44,16 @@ public class Paypal implements Payment {
44 44
     }
45 45
 
46 46
     public int compareTo(Payment o) {
47
-        return 0;
47
+
48
+        int result = this.getShortDescription().compareTo(o.getShortDescription());
49
+
50
+        if(result > 0){
51
+            return 1;
52
+        } else if(result < 0){
53
+            return -1;
54
+        } else {
55
+            return 0;
56
+        }
57
+
48 58
     }
49 59
 }

+ 13
- 10
src/test/java/com/zipcoder/payment/PaymentOrderByPayerTest.java Просмотреть файл

@@ -1,16 +1,19 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
-import com.zipcoder.paymentSort.ByPayer;
4
-import org.junit.jupiter.api.Test;
3
+import com.zipcoder.payment.Comparators.Payer;
5 4
 
6
-import static org.junit.jupiter.api.Assertions.*;
5
+import static org.junit.Assert.*;
7 6
 
8
-class PaymentOrderByPayerTest {
7
+import org.junit.Test;
8
+
9
+import java.util.Comparator;
10
+
11
+public class PaymentOrderByPayerTest {
9 12
 
10 13
     @Test
11
-    void compairTest1() {
14
+    public void compairTest1() {
12 15
         //When
13
-        ByPayer ps = new ByPayer();
16
+        Comparator ps = new Payer();
14 17
         Payment cc = new CreditCard(12, 4111131,"Jimmy Maidanos", 4, 11);
15 18
         Payment pp = new Paypal(23, "Nicholas Maidanos", "nmaidanos@gmail.com");
16 19
 
@@ -24,9 +27,9 @@ class PaymentOrderByPayerTest {
24 27
     }
25 28
 
26 29
     @Test
27
-    void compairTest2() {
30
+    public void compairTest2() {
28 31
         //When
29
-        ByPayer ps = new ByPayer();
32
+        Comparator ps = new Payer();
30 33
         Payment cc = new CreditCard(12, 4111131,"Zimmy Maidanos", 4, 11);
31 34
         Payment pp = new Paypal(23, "Nicholas Maidanos", "nmaidanos@gmail.com");
32 35
 
@@ -40,9 +43,9 @@ class PaymentOrderByPayerTest {
40 43
     }
41 44
 
42 45
     @Test
43
-    void compairTest3() {
46
+    public void compairTest3() {
44 47
         //When
45
-        ByPayer ps = new ByPayer();
48
+        Comparator ps = new Payer();
46 49
         Payment cc = new CreditCard(12, 4111131,"Nicholas Maidanos", 4, 11);
47 50
         Payment pp = new Paypal(23, "Nicholas Maidanos", "nmaidanos@gmail.com");
48 51
 

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

@@ -1,9 +1,9 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
-import com.zipcoder.paymentSort.PaymentOrder;
4
-import org.junit.Test;
5
-
3
+import com.zipcoder.PaymentPresenter;
4
+import com.zipcoder.payment.Comparators.PaymentOrder;
6 5
 import static org.junit.Assert.*;
6
+import org.junit.Test;
7 7
 
8 8
 public class PaymentPresenterTest {
9 9
 
@@ -37,7 +37,7 @@ public class PaymentPresenterTest {
37 37
         payments[1] = cc;
38 38
         payments[2] = ck;
39 39
         //Expect
40
-        String expected = "CC Nicholas Maidanos 1131 4/11\nCheck Nicholas Maidanos ****3234\nPayPal Nicholas Maidanos nmaidanos@gmail.com\n";
40
+        String expected = "CC Nicholas Maidanos 1131 4/11\nCheck Nicholas Maidanos ****3234\nPaypal Nicholas Maidanos nmaidanos@gmail.com\n";
41 41
 
42 42
         //Actual
43 43
         String actual = paymentPresenter.toString(payments);
@@ -60,7 +60,7 @@ public class PaymentPresenterTest {
60 60
         payments[1] = cc;
61 61
         payments[2] = ck;
62 62
         //Expect
63
-        String expected = "Check Nicholas Maidanos ****3234\nPayPal Nicholas Maidanos nmaidanos@gmail.com\nCC Nicholas Maidanos 1131 4/11\n";
63
+        String expected = "Check Nicholas Maidanos ****3234\nPaypal Nicholas Maidanos nmaidanos@gmail.com\nCC Nicholas Maidanos 1131 4/11\n";
64 64
 
65 65
         //Actual
66 66
         String actual = paymentPresenter.toString(payments);
@@ -82,7 +82,7 @@ public class PaymentPresenterTest {
82 82
         payments[1] = ck;
83 83
         payments[2] = pp;
84 84
         //Expect
85
-        String expected = "PayPal Billy Maidanos nmaidanos@gmail.com\nCC Jimmy Maidanos 1131 4/11\nCheck Nicholas Maidanos ****3234\n";
85
+        String expected = "Paypal Billy Maidanos nmaidanos@gmail.com\nCC Jimmy Maidanos 1131 4/11\nCheck Nicholas Maidanos ****3234\n";
86 86
 
87 87
         //Actual
88 88
         String actual = paymentPresenter.toString(payments);