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

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

@@ -62,8 +62,12 @@ public class Check implements Payment {
62 62
     public void setId(long id) {
63 63
         this.id = id;
64 64
     }
65
+
65 66
     public String getAccountNumber(){
66 67
         return this.accountNumber;
67 68
     }
68 69
 
70
+    public int compareTo(Payment o) {
71
+        return 0;
72
+    }
69 73
 }

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

@@ -81,5 +81,17 @@ public class CreditCard implements Payment {
81 81
         return Integer.parseInt(lastFourString);
82 82
     }
83 83
 
84
+    public int compareTo(Payment o) {
84 85
 
86
+        int result = this.getShortDescription().compareTo(o.getShortDescription());
87
+
88
+        if(result > 0){
89
+            return 1;
90
+        } else if(result < 0){
91
+            return -1;
92
+        } else {
93
+            return 0;
94
+        }
95
+
96
+    }
85 97
 }

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

@@ -1,6 +1,6 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
-public interface Payment {
3
+public interface Payment extends Comparable<Payment> {
4 4
 
5 5
     long getId();
6 6
 
@@ -8,5 +8,4 @@ public interface Payment {
8 8
 
9 9
     String getShortDescription();
10 10
 
11
-
12 11
 }

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

@@ -47,5 +47,7 @@ public class Paypal implements Payment {
47 47
         return sb.toString();
48 48
     }
49 49
 
50
-
50
+    public int compareTo(Payment o) {
51
+        return 0;
52
+    }
51 53
 }

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

@@ -141,4 +141,8 @@ class CheckTest {
141 141
         String actual = ck.getShortDescription();
142 142
         assertEquals(expected, actual);
143 143
     }
144
+
145
+    @Test
146
+    void compareTo() {
147
+    }
144 148
 }

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

@@ -154,4 +154,19 @@ public class CreditCardTest {
154 154
 
155 155
     }
156 156
 
157
+    @Test
158
+    public void compareToTest() {
159
+        //Given
160
+        Payment cc = new CreditCard(12, 4111131,"Nicholas Maidanos", 4, 11);
161
+        Payment pp = new Paypal(23, "Nicholas Maidanos", "nmaidanos@gmail.com");
162
+
163
+        //Expect
164
+        int expected = -1;
165
+
166
+        //Actual
167
+        int actual = cc.compareTo(pp);
168
+
169
+        assertEquals(expected, actual);
170
+
171
+    }
157 172
 }

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

@@ -104,4 +104,8 @@ class PaypalTest {
104 104
 
105 105
         assertEquals(expect,actual);
106 106
     }
107
+
108
+    @Test
109
+    void compareTo() {
110
+    }
107 111
 }