shakila 8 лет назад
Родитель
Сommit
6699bc2803

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

@@ -44,4 +44,8 @@ public class Check implements Payment {
44 44
     public String getAccountNumber() {
45 45
     return accountNumber;
46 46
     }
47
+
48
+    public int compareTo(Payment o) {
49
+        return 0;
50
+    }
47 51
 }

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

@@ -6,6 +6,7 @@ public class CreditCard implements Payment{
6 6
     String number;
7 7
     int expiredMonth;
8 8
     int expiredYear;
9
+    int compare;
9 10
 
10 11
     public  CreditCard(){
11 12
         id = 12345;
@@ -13,6 +14,7 @@ public class CreditCard implements Payment{
13 14
         number = "4551";
14 15
         expiredMonth = 10;
15 16
         expiredYear = 2019;
17
+        int compare = 0;
16 18
     }
17 19
 
18 20
     public Long getId() {
@@ -54,4 +56,19 @@ public class CreditCard implements Payment{
54 56
     public int getExpiredYear() {
55 57
         return expiredYear;
56 58
     }
59
+
60
+    public int compareTo(Payment o) {
61
+        if (this.getShortDescription().compareTo(o.getShortDescription()) < 0){
62
+            compare = -1;
63
+        }
64
+        else if (this.getShortDescription().compareTo(o.getShortDescription()) > 0){
65
+            compare = 1;
66
+        }
67
+
68
+        else{
69
+            compare = 0;
70
+        }
71
+
72
+        return compare;
73
+    }
57 74
 }

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

@@ -20,7 +20,7 @@ public class PayPal implements Payment {
20 20
     }
21 21
 
22 22
     public String getShortDescription() {
23
-        return null;
23
+        return ("PayPal" + payerName + email);
24 24
     }
25 25
 
26 26
     public void setId(long id) {
@@ -35,4 +35,8 @@ public class PayPal implements Payment {
35 35
     public String getEmail() {
36 36
         return email;
37 37
     }
38
+
39
+    public int compareTo(Payment o) {
40
+        return 0;
41
+    }
38 42
 }

+ 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
     Long getId();
6 6
 

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

@@ -48,6 +48,37 @@ public class CheckTest {
48 48
 
49 49
     @Test
50 50
     public void getShortDescription() {
51
+        Check check = new Check();
52
+        String getShortDescription = ("Check" + check.getPayerName() + check.getAccountNumber());
53
+        String expectedGetShortDescription = ("Check" + check.getPayerName() + check.getAccountNumber());
54
+        String actualGetShortDescription = check.getShortDescription();
55
+        assertEquals(expectedGetShortDescription, actualGetShortDescription);
56
+    }
57
+
58
+
59
+    @Test
60
+    public void compareTo1() {
61
+        CreditCard creditCard = new CreditCard();
62
+        Check check = new Check();
63
+        int expectedCompareTo = 1;
64
+        int actualCompareTo = check.compareTo(creditCard);
65
+        assertEquals(expectedCompareTo, actualCompareTo);
66
+    }
51 67
 
68
+    @Test
69
+    public void compareTo2() {
70
+        Check check = new Check();
71
+        PayPal payPal = new PayPal();
72
+        int expectedCompareTo = -1;
73
+        int actualCompareTo = check.compareTo(payPal);
74
+        assertEquals(expectedCompareTo, actualCompareTo);
75
+    }
76
+
77
+    @Test
78
+    public void compareTo3() {
79
+        Check check = new Check();
80
+        int expectedCompareTo = 0;
81
+        int actualCompareTo = check.compareTo(check);
82
+        assertEquals(expectedCompareTo, actualCompareTo);
52 83
     }
53 84
 }

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

@@ -69,6 +69,36 @@ public class CreditCardTest {
69 69
 
70 70
     @org.junit.Test
71 71
     public void getShortDescription() {
72
+        CreditCard creditCard = new CreditCard();
73
+        String getShortDescription = ("CC" + creditCard.getPayerName() + creditCard.getNumber() + creditCard.getExpiredMonth() + "/" + creditCard.getExpiredYear());
74
+        String expectedGetShortDescription = ("CC" + creditCard.payerName + creditCard.getNumber() + creditCard.getExpiredMonth() + "/" + creditCard.getExpiredYear());
75
+        String actualGetShortDescription = creditCard.getShortDescription();
76
+        assertEquals(expectedGetShortDescription, actualGetShortDescription);
77
+    }
78
+
79
+    @Test
80
+    public void compareTo1() {
81
+        CreditCard creditCard = new CreditCard();
82
+        Check check = new Check();
83
+        int expectedCompareTo = -1;
84
+        int actualCompareTo = creditCard.compareTo(check);
85
+        assertEquals(expectedCompareTo, actualCompareTo);
86
+    }
87
+
88
+    @Test
89
+    public void compareTo2() {
90
+        CreditCard creditCard = new CreditCard();
91
+        PayPal payPal = new PayPal();
92
+        int expectedCompareTo = -1;
93
+        int actualCompareTo = creditCard.compareTo(payPal);
94
+        assertEquals(expectedCompareTo, actualCompareTo);
72 95
     }
73 96
 
97
+    @Test
98
+    public void compareTo3() {
99
+        CreditCard creditCard = new CreditCard();
100
+        int expectedCompareTo = 0;
101
+        int actualCompareTo = creditCard.compareTo(creditCard);
102
+        assertEquals(expectedCompareTo, actualCompareTo);
103
+    }
74 104
 }

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

@@ -38,5 +38,10 @@ public class PayPalTest {
38 38
 
39 39
     @Test
40 40
     public void getShortDescription() {
41
+        PayPal payPal = new PayPal();
42
+        String getShortDescription = ("PayPal" + payPal.payerName + payPal.email);
43
+         String expectedGetShortDescription = ("PayPal" + payPal.payerName + payPal.email);
44
+         String actualGetShortDescription = payPal.getShortDescription();
45
+        assertEquals(expectedGetShortDescription, actualGetShortDescription);
41 46
     }
42 47
 }