Trinh Tong 7 лет назад
Родитель
Сommit
fbfb28bb9e

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

@@ -1,14 +1,21 @@
1 1
 package com.zipcoder.payment;
2 2
 
3 3
 public class Check implements Payment {
4
-    private long id;
4
+    private Long id;
5 5
 
6 6
     private String payerName;
7 7
     private String routingNumber;
8 8
     private String accountNumber;
9 9
 
10
+    public Check(Long id, String payerName, String routingNumber, String accountNumber) {
11
+        this.id = id;
12
+        this.payerName = payerName;
13
+        this.routingNumber = routingNumber;
14
+        this.accountNumber = accountNumber;
15
+    }
16
+
10 17
     public Check() {
11
-        id = 0;
18
+        id = 0L;
12 19
         payerName = null;
13 20
         routingNumber = null;
14 21
         accountNumber = null;
@@ -16,7 +23,12 @@ public class Check implements Payment {
16 23
     }
17 24
 
18 25
     @Override
19
-    public long getId() {
26
+    public int compareTo(Payment o) {
27
+        return getShortDescription().compareTo(o.getShortDescription());
28
+    }
29
+
30
+    @Override
31
+    public Long getId() {
20 32
         return this.id;
21 33
     }
22 34
 
@@ -25,7 +37,7 @@ public class Check implements Payment {
25 37
     }
26 38
 
27 39
     public String getRoutingNumber() {
28
-        return routingNumber;
40
+        return this.routingNumber;
29 41
     }
30 42
 
31 43
     public void setRoutingNumber(String routingNumber) {
@@ -33,7 +45,7 @@ public class Check implements Payment {
33 45
     }
34 46
 
35 47
     public String getAccountNumber() {
36
-        return accountNumber;
48
+        return this.accountNumber;
37 49
     }
38 50
 
39 51
     public void setAccountNumber(String accountNumber) {
@@ -47,10 +59,11 @@ public class Check implements Payment {
47 59
 
48 60
     @Override
49 61
     public String getShortDescription() {
50
-        return null;
62
+
63
+        return "Check " + this.getPayerName() + " ****" + this.getAccountNumber().substring(this.getAccountNumber().length() - 4);
51 64
     }
52 65
 
53
-    public void setId(long l) {
66
+    public void setId(Long l) {
54 67
         this.id = l;
55 68
     }
56 69
 }

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

@@ -1,7 +1,7 @@
1 1
 package com.zipcoder.payment;
2 2
 
3 3
 public class CreditCard implements Payment {
4
-    private long id;
4
+    private Long id;
5 5
 
6 6
     private String payerName;
7 7
     private String number;
@@ -9,8 +9,16 @@ public class CreditCard implements Payment {
9 9
     private int expiredMonth;
10 10
     private int expiredyear;
11 11
 
12
+    public CreditCard(Long id, String payerName, String number, int expiredMonth, int expiredyear) {
13
+        this.id = id;
14
+        this.payerName = payerName;
15
+        this.number = number;
16
+        this.expiredMonth = expiredMonth;
17
+        this.expiredyear = expiredyear;
18
+    }
19
+
12 20
     public CreditCard() {
13
-        id = 0;
21
+        id = 0L;
14 22
         this.number = null;
15 23
         this.payerName = null;
16 24
         expiredMonth = 0;
@@ -18,6 +26,7 @@ public class CreditCard implements Payment {
18 26
     }
19 27
 
20 28
 
29
+
21 30
     public void setPayerName(String payerName) {
22 31
         this.payerName = payerName;
23 32
     }
@@ -46,11 +55,11 @@ public class CreditCard implements Payment {
46 55
         this.expiredyear = expiredyear;
47 56
     }
48 57
 
49
-    public long getId() {
58
+    public Long getId() {
50 59
         return id;
51 60
     }
52 61
 
53
-    public void setId(long id) {
62
+    public void setId(Long id) {
54 63
         this.id = id;
55 64
     }
56 65
 
@@ -65,6 +74,11 @@ public class CreditCard implements Payment {
65 74
         int numLength = getNumber().length();
66 75
         String last4 = getNumber().substring(numLength - 4);
67 76
 
68
-        return "CC [" + this.getPayerName() + "] [" + last4 + "] [" + getExpiredMonth() + "]/[" + getExpiredyear() + "]";
77
+        return "CC " + this.getPayerName() + " " + last4 + " " + getExpiredMonth() + "/" + getExpiredyear();
78
+    }
79
+
80
+    @Override
81
+    public int compareTo(Payment o) {
82
+        return this.getShortDescription().compareTo(o.getShortDescription());
69 83
     }
70 84
 }

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

@@ -0,0 +1,58 @@
1
+package com.zipcoder.payment;
2
+
3
+public class PayPal implements Payment {
4
+    private Long id;
5
+
6
+    String payerName;
7
+    String email;
8
+
9
+    public PayPal(Long id, String name, String email) {
10
+        this.id = id;
11
+        this.payerName = name;
12
+        this.email = email;
13
+    }
14
+
15
+    public PayPal() {
16
+        this.id = 0L;
17
+        this.payerName = "Default";
18
+        this.email = "Defailt@gmail.com";
19
+    }
20
+
21
+    public void setPayerName(String payerName) {
22
+        this.payerName = payerName;
23
+    }
24
+
25
+    public String getEmail() {
26
+        return this.email;
27
+    }
28
+
29
+    public void setEmail(String email) {
30
+        this.email = email;
31
+    }
32
+
33
+    @Override
34
+    public Long getId() {
35
+        return this.id;
36
+    }
37
+
38
+    @Override
39
+    public String getPayerName() {
40
+        return this.payerName;
41
+    }
42
+
43
+    @Override
44
+    public String getShortDescription() {
45
+
46
+        //Paypal Tia Mowry tia@mowry.com
47
+        return "PayPal " + getPayerName() + " " + getEmail();
48
+    }
49
+
50
+    public void setId(Long l) {
51
+        this.id = l;
52
+    }
53
+
54
+    @Override
55
+    public int compareTo(Payment o) {
56
+        return this.getShortDescription().compareTo(o.getShortDescription());
57
+    }
58
+}

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

@@ -1,8 +1,8 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
-public interface Payment {
3
+public interface Payment extends Comparable<Payment> {
4 4
 
5
-    long getId();
5
+    Long getId();
6 6
     String getPayerName();
7 7
     String getShortDescription();
8 8
     

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

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

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

@@ -6,21 +6,57 @@ import org.junit.Test;
6 6
 
7 7
 public class CheckTest {
8 8
     private Check testCheck;
9
+    private CreditCard cc;
9 10
 
10 11
     @Before
11 12
     public void setUp() {
12 13
         testCheck = new Check();
14
+
13 15
         testCheck.setId(12345678910L);
14 16
         testCheck.setPayerName("Biggie");
15 17
         testCheck.setRoutingNumber("623852453");
16 18
         testCheck.setAccountNumber("1234567");
19
+
20
+        cc = new CreditCard();
21
+        cc.setPayerName("Apple");
22
+        cc.setNumber("4567 8910 9090 9000");
17 23
     }
18 24
 
19 25
     @Test
20 26
     public void testId() {
21
-        long expectedId = 12345678910L;
27
+        Long expectedId = 12345678910L;
22 28
         testCheck.setId(12345678910L);
23 29
         Assert.assertEquals(expectedId, testCheck.getId());
24 30
     }
25 31
 
32
+    @Test
33
+    public void testPayerName() {
34
+        String expectedName = "Biggie";
35
+        Assert.assertEquals(expectedName, testCheck.getPayerName());
36
+
37
+    }
38
+
39
+    @Test
40
+    public void testAccountingNum() {
41
+        String expectedActNum = "1234567";
42
+        Assert.assertEquals(expectedActNum, testCheck.getAccountNumber());
43
+    }
44
+
45
+    @Test
46
+    public void testRoutingNum() {
47
+        String expectedRout = "623852453";
48
+        Assert.assertEquals(expectedRout, testCheck.getRoutingNumber());
49
+    }
50
+
51
+    @Test
52
+    public void testShortDesc() {
53
+        String expectedDesc = "Check Biggie ****4567";
54
+        Assert.assertEquals(expectedDesc, testCheck.getShortDescription());
55
+    }
56
+
57
+    @Test
58
+    public void testCompareTo() {
59
+        int expectedComp = 37;
60
+        Assert.assertEquals(expectedComp, testCheck.compareTo(cc));
61
+    }
26 62
 }

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

@@ -6,6 +6,7 @@ import org.junit.Test;
6 6
 
7 7
 public class CreditcardTest {
8 8
     CreditCard cc;
9
+    Check testCheck;
9 10
 
10 11
     @Before
11 12
     public void setUp() {
@@ -15,11 +16,18 @@ public class CreditcardTest {
15 16
         cc.setExpiredMonth(12);
16 17
         cc.setExpiredyear(2020);
17 18
         cc.setNumber("4539 1889 1071 9389");
19
+
20
+        testCheck = new Check();
21
+
22
+        testCheck.setId(12345678910L);
23
+        testCheck.setPayerName("Biggie");
24
+        testCheck.setRoutingNumber("623852453");
25
+        testCheck.setAccountNumber("1234567");
18 26
     }
19 27
 
20 28
     @Test
21 29
     public void testLongId() {
22
-        long expectedId =  1234567894321L;
30
+        Long expectedId =  1234567894321L;
23 31
         cc.setId(1234567894321L);
24 32
         Assert.assertEquals(expectedId, cc.getId());
25 33
     }
@@ -50,9 +58,13 @@ public class CreditcardTest {
50 58
 
51 59
     @Test
52 60
     public void testShortDesc() {
53
-        String expectedCC = "CC [Jared] [9389] [12]/[2020]";
61
+        String expectedCC = "CC Jared 9389 12/2020";
54 62
         Assert.assertEquals(expectedCC, cc.getShortDescription());
55 63
     }
56 64
 
57
-
65
+    @Test
66
+    public void testCompare() {
67
+        int exp = -37;
68
+        Assert.assertEquals(exp, cc.compareTo(testCheck));
69
+    }
58 70
 }

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

@@ -0,0 +1,54 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
7
+public class PayPalTest {
8
+    PayPal pp;
9
+    CreditCard cc;
10
+    @Before
11
+    public void setUp() {
12
+        pp = new PayPal();
13
+        pp.setId(98765432100L);
14
+        pp.setPayerName("TeeTay Tong");
15
+        pp.setEmail("TeeTay@gmail.com");
16
+
17
+        cc = new CreditCard();
18
+
19
+        cc.setPayerName("Jared");
20
+        cc.setExpiredMonth(12);
21
+        cc.setExpiredyear(2020);
22
+        cc.setNumber("4539 1889 1071 9389");
23
+    }
24
+
25
+    @Test
26
+    public void testId() {
27
+        Long expectedID = 98765432100L;
28
+        Assert.assertEquals(expectedID, pp.getId());
29
+    }
30
+
31
+    @Test
32
+    public void testPayerName() {
33
+        String expectedName = "TeeTay Tong";
34
+        Assert.assertEquals(expectedName, pp.getPayerName());
35
+    }
36
+
37
+    @Test
38
+    public void testEmail() {
39
+        String expectedEmail = "TeeTay@gmail.com";
40
+        Assert.assertEquals(expectedEmail, pp.getEmail());
41
+    }
42
+
43
+    @Test
44
+    public void testDesc() {
45
+        String expDesc = "PayPal TeeTay Tong TeeTay@gmail.com";
46
+        Assert.assertEquals(expDesc, pp.getShortDescription());
47
+    }
48
+
49
+    @Test
50
+    public void testCompare() {
51
+        int exp = 13;
52
+        Assert.assertEquals(exp, pp.compareTo(cc));
53
+    }
54
+}

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

@@ -0,0 +1,26 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
7
+import static org.junit.Assert.*;
8
+
9
+public class PaymentSortByPayerTest {
10
+    PaymentSortByPayer ppSort;
11
+    PayPal pp;
12
+    Check ch;
13
+
14
+    @Before
15
+    public void setUp() {
16
+        ppSort = new PaymentSortByPayer();
17
+        pp = new PayPal(678694850L, "Tullo Tilly", "tSquared@gmail.com");
18
+        ch = new Check(123149324L, "Biggie Yougin", "011103093", "123456789");
19
+    }
20
+
21
+    @Test
22
+    public void testCompare() {
23
+        int expected = 13;
24
+        Assert.assertEquals(expected, ppSort.compare(pp, ch));
25
+    }
26
+}