Seth пре 7 година
родитељ
комит
784219a69d

+ 4
- 0
src/main/java/com/zipcoder/payment/Check.java Прегледај датотеку

@@ -53,4 +53,8 @@ public class Check implements Payment {
53 53
     public String getShortDescription() {
54 54
         return "Check " + payerName + " ***" + getLastFourDigits(accountNumber);
55 55
     }
56
+
57
+    public int compareTo(Payment payment2) {
58
+        return this.getShortDescription().compareTo(payment2.getShortDescription());
59
+    }
56 60
 }

+ 4
- 0
src/main/java/com/zipcoder/payment/CreditCard.java Прегледај датотеку

@@ -43,4 +43,8 @@ public class CreditCard implements Payment {
43 43
     public String getShortDescription() {
44 44
         return "CC " + payerName + " " + getLastFourDigits(number) + " " + expiredMonth + "/" + expiredYear;
45 45
     }
46
+
47
+    public int compareTo(Payment payment2) {
48
+        return this.getShortDescription().compareTo(payment2.getShortDescription());
49
+    }
46 50
 }

+ 9
- 1
src/main/java/com/zipcoder/payment/PayPal.java Прегледај датотеку

@@ -1,6 +1,6 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
-public class PayPal {
3
+public class PayPal implements Payment{
4 4
     long id;
5 5
     String payerName;
6 6
     String email;
@@ -34,4 +34,12 @@ public class PayPal {
34 34
     public void setEmail(String email) {
35 35
         this.email = email;
36 36
     }
37
+
38
+    public String getShortDescription() {
39
+        return "PayPal " + payerName + " " +email;
40
+    }
41
+
42
+    public int compareTo(Payment payment2) {
43
+        return this.getShortDescription().compareTo(payment2.getShortDescription());
44
+    }
37 45
 }

+ 1
- 1
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
     public long getId();
6 6
 

+ 4
- 0
src/main/java/com/zipcoder/payment/PaymentSortByPayer.java Прегледај датотеку

@@ -0,0 +1,4 @@
1
+package com.zipcoder.payment;
2
+
3
+public class PaymentSortByPayer {
4
+}

+ 9
- 0
src/test/java/com/zipcoder/payment/CheckTest.java Прегледај датотеку

@@ -6,10 +6,12 @@ import org.junit.Test;
6 6
 
7 7
 public class CheckTest {
8 8
     Check testCheck;
9
+    CreditCard otherPayment;
9 10
 
10 11
     @Before
11 12
     public void initialize() {
12 13
         testCheck = new Check(100, "Karen Paige", "124567", "7654321");
14
+        otherPayment = new CreditCard(10, "John Hurt", "0043783590454335", 03,2020);
13 15
     }
14 16
 
15 17
     @Test
@@ -70,4 +72,11 @@ public class CheckTest {
70 72
 
71 73
         Assert.assertEquals(expected, actual);
72 74
     }
75
+
76
+    @Test
77
+    public void compareToTest() {
78
+        int actual = testCheck.compareTo(otherPayment);
79
+
80
+        Assert.assertTrue(actual > 0);
81
+    }
73 82
 }

+ 11
- 0
src/test/java/com/zipcoder/payment/CreditCardTest.java Прегледај датотеку

@@ -7,11 +7,14 @@ import org.junit.Test;
7 7
 
8 8
 public class CreditCardTest {
9 9
     CreditCard testCard;
10
+    PayPal otherPayment;
11
+    Check otherPayment2;
10 12
 
11 13
 
12 14
     @Before
13 15
     public void initialize() {
14 16
         testCard = new CreditCard(10, "John Hurt", "0043783590454335", 03,2020);
17
+        otherPayment =new PayPal(15,"Momo Hashimoto", "kawaii54@line.com");
15 18
 
16 19
     }
17 20
 
@@ -85,4 +88,12 @@ public class CreditCardTest {
85 88
 
86 89
         Assert.assertEquals(expected, actual);
87 90
     }
91
+
92
+    @Test
93
+    public void compareToTest() {
94
+        int actual = testCard.compareTo(otherPayment);
95
+
96
+        Assert.assertTrue(actual < 0);
97
+
98
+    }
88 99
 }

+ 18
- 0
src/test/java/com/zipcoder/payment/PayPalTest.java Прегледај датотеку

@@ -6,11 +6,13 @@ import org.junit.Test;
6 6
 
7 7
 public class PayPalTest {
8 8
     PayPal testPal;
9
+    Check otherPayment;
9 10
 
10 11
 
11 12
     @Before
12 13
     public void initialization() {
13 14
         testPal = new PayPal(15,"Momo Hashimoto", "kawaii54@line.com");
15
+        otherPayment = new Check(100, "Karen Paige", "124567", "7654321");
14 16
 
15 17
     }
16 18
     @Test
@@ -42,4 +44,20 @@ public class PayPalTest {
42 44
 
43 45
         Assert.assertEquals(expected, actual);
44 46
     }
47
+
48
+    @Test
49
+    public void getShortDescriptionTest() {
50
+        String expected = "PayPal Momo Hashimoto kawaii54@line.com";
51
+        String actual = testPal.getShortDescription();
52
+
53
+        Assert.assertEquals(expected, actual);
54
+    }
55
+
56
+    @Test
57
+    public void compareToTest() {
58
+        int actual = testPal.compareTo(otherPayment);
59
+
60
+
61
+        Assert.assertTrue(actual > 0);
62
+    }
45 63
 }