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

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

1
 package com.zipcoder.payment;
1
 package com.zipcoder.payment;
2
 
2
 
3
 public class Check implements Payment {
3
 public class Check implements Payment {
4
-    private long id;
4
+    private Long id;
5
 
5
 
6
     private String payerName;
6
     private String payerName;
7
     private String routingNumber;
7
     private String routingNumber;
8
     private String accountNumber;
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
     public Check() {
17
     public Check() {
11
-        id = 0;
18
+        id = 0L;
12
         payerName = null;
19
         payerName = null;
13
         routingNumber = null;
20
         routingNumber = null;
14
         accountNumber = null;
21
         accountNumber = null;
16
     }
23
     }
17
 
24
 
18
     @Override
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
         return this.id;
32
         return this.id;
21
     }
33
     }
22
 
34
 
25
     }
37
     }
26
 
38
 
27
     public String getRoutingNumber() {
39
     public String getRoutingNumber() {
28
-        return routingNumber;
40
+        return this.routingNumber;
29
     }
41
     }
30
 
42
 
31
     public void setRoutingNumber(String routingNumber) {
43
     public void setRoutingNumber(String routingNumber) {
33
     }
45
     }
34
 
46
 
35
     public String getAccountNumber() {
47
     public String getAccountNumber() {
36
-        return accountNumber;
48
+        return this.accountNumber;
37
     }
49
     }
38
 
50
 
39
     public void setAccountNumber(String accountNumber) {
51
     public void setAccountNumber(String accountNumber) {
47
 
59
 
48
     @Override
60
     @Override
49
     public String getShortDescription() {
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
         this.id = l;
67
         this.id = l;
55
     }
68
     }
56
 }
69
 }

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

1
 package com.zipcoder.payment;
1
 package com.zipcoder.payment;
2
 
2
 
3
 public class CreditCard implements Payment {
3
 public class CreditCard implements Payment {
4
-    private long id;
4
+    private Long id;
5
 
5
 
6
     private String payerName;
6
     private String payerName;
7
     private String number;
7
     private String number;
9
     private int expiredMonth;
9
     private int expiredMonth;
10
     private int expiredyear;
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
     public CreditCard() {
20
     public CreditCard() {
13
-        id = 0;
21
+        id = 0L;
14
         this.number = null;
22
         this.number = null;
15
         this.payerName = null;
23
         this.payerName = null;
16
         expiredMonth = 0;
24
         expiredMonth = 0;
18
     }
26
     }
19
 
27
 
20
 
28
 
29
+
21
     public void setPayerName(String payerName) {
30
     public void setPayerName(String payerName) {
22
         this.payerName = payerName;
31
         this.payerName = payerName;
23
     }
32
     }
46
         this.expiredyear = expiredyear;
55
         this.expiredyear = expiredyear;
47
     }
56
     }
48
 
57
 
49
-    public long getId() {
58
+    public Long getId() {
50
         return id;
59
         return id;
51
     }
60
     }
52
 
61
 
53
-    public void setId(long id) {
62
+    public void setId(Long id) {
54
         this.id = id;
63
         this.id = id;
55
     }
64
     }
56
 
65
 
65
         int numLength = getNumber().length();
74
         int numLength = getNumber().length();
66
         String last4 = getNumber().substring(numLength - 4);
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 Просмотреть файл

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
 package com.zipcoder.payment;
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
     String getPayerName();
6
     String getPayerName();
7
     String getShortDescription();
7
     String getShortDescription();
8
     
8
     

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

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
 
6
 
7
 public class CheckTest {
7
 public class CheckTest {
8
     private Check testCheck;
8
     private Check testCheck;
9
+    private CreditCard cc;
9
 
10
 
10
     @Before
11
     @Before
11
     public void setUp() {
12
     public void setUp() {
12
         testCheck = new Check();
13
         testCheck = new Check();
14
+
13
         testCheck.setId(12345678910L);
15
         testCheck.setId(12345678910L);
14
         testCheck.setPayerName("Biggie");
16
         testCheck.setPayerName("Biggie");
15
         testCheck.setRoutingNumber("623852453");
17
         testCheck.setRoutingNumber("623852453");
16
         testCheck.setAccountNumber("1234567");
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
     @Test
25
     @Test
20
     public void testId() {
26
     public void testId() {
21
-        long expectedId = 12345678910L;
27
+        Long expectedId = 12345678910L;
22
         testCheck.setId(12345678910L);
28
         testCheck.setId(12345678910L);
23
         Assert.assertEquals(expectedId, testCheck.getId());
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
 
7
 public class CreditcardTest {
7
 public class CreditcardTest {
8
     CreditCard cc;
8
     CreditCard cc;
9
+    Check testCheck;
9
 
10
 
10
     @Before
11
     @Before
11
     public void setUp() {
12
     public void setUp() {
15
         cc.setExpiredMonth(12);
16
         cc.setExpiredMonth(12);
16
         cc.setExpiredyear(2020);
17
         cc.setExpiredyear(2020);
17
         cc.setNumber("4539 1889 1071 9389");
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
     @Test
28
     @Test
21
     public void testLongId() {
29
     public void testLongId() {
22
-        long expectedId =  1234567894321L;
30
+        Long expectedId =  1234567894321L;
23
         cc.setId(1234567894321L);
31
         cc.setId(1234567894321L);
24
         Assert.assertEquals(expectedId, cc.getId());
32
         Assert.assertEquals(expectedId, cc.getId());
25
     }
33
     }
50
 
58
 
51
     @Test
59
     @Test
52
     public void testShortDesc() {
60
     public void testShortDesc() {
53
-        String expectedCC = "CC [Jared] [9389] [12]/[2020]";
61
+        String expectedCC = "CC Jared 9389 12/2020";
54
         Assert.assertEquals(expectedCC, cc.getShortDescription());
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 Просмотреть файл

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 Просмотреть файл

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
+}