rjsmall90 vor 8 Jahren
Ursprung
Commit
a8ab2736b8

+ 68
- 0
src/main/java/com/zipcoder/payment/Check.java Datei anzeigen

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

+ 106
- 0
src/main/java/com/zipcoder/payment/CheckTest.java Datei anzeigen

@@ -0,0 +1,106 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Test;
4
+
5
+import static org.junit.Assert.*;
6
+
7
+public class CheckTest {
8
+    Check check = new Check();
9
+    Paypal pay = new Paypal();
10
+    CreditCard card = new CreditCard();
11
+
12
+    @Test
13
+    public void getId() {
14
+        long expectedId = 3765;
15
+        check.setId(expectedId);
16
+
17
+        long actualId = check.getId();
18
+
19
+        assertEquals(expectedId, actualId);
20
+    }
21
+
22
+    @Test
23
+    public void getPayerName() {
24
+        String expectedPayerName = "Tammy Jammy";
25
+        check.setPayerName(expectedPayerName);
26
+
27
+        String actualPayerName = check.getPayerName();
28
+
29
+        assertEquals(expectedPayerName, actualPayerName);
30
+
31
+    }
32
+
33
+    @Test
34
+    public void getShortDescription() {
35
+        String name = "Tammy Jammy";
36
+        String accountNumber = "4551";
37
+        check.setPayerName(name);
38
+        check.setAccountNumber(accountNumber);
39
+
40
+
41
+        String expectedDescription = "Check " + name +  " ***" + accountNumber;
42
+
43
+        System.out.println(check.getShortDescription());
44
+        String actualDescription = check.getShortDescription();
45
+
46
+        assertEquals(expectedDescription, actualDescription);
47
+    }
48
+
49
+    @Test
50
+    public void getRoutingNumber() {
51
+        String expectedRoutingNumber = "123456789";
52
+        check.setRoutingNumber(expectedRoutingNumber);
53
+
54
+        String actualRoutingNumber= check.getRoutingNumber();
55
+
56
+        assertEquals(expectedRoutingNumber, actualRoutingNumber);
57
+
58
+    }
59
+
60
+    @Test
61
+    public void getAccountNumber(){
62
+        Check check = new Check();
63
+
64
+        String expectedAccountNumber = "4551";
65
+        check.setAccountNumber(expectedAccountNumber);
66
+
67
+        String actualAccountNumber= check.getAccountNumber();
68
+
69
+        assertEquals(expectedAccountNumber, actualAccountNumber);
70
+
71
+    }
72
+    @Test
73
+    public void compareToPaypal() {
74
+        Check check = new Check();
75
+        Paypal pay = new Paypal();
76
+
77
+        int expected = -1;
78
+        int actual = (check.compareTo(pay));
79
+
80
+
81
+        assertEquals(expected, actual);
82
+    }
83
+
84
+    @Test
85
+    public void compareToCredit() {
86
+        Check check = new Check();
87
+        CreditCard card = new CreditCard();
88
+
89
+        int expected = 1;
90
+        int actual = (check.compareTo(card));
91
+
92
+
93
+        assertEquals(expected, actual);
94
+    }
95
+
96
+    @Test
97
+    public void compareToSelf() {
98
+        Check check = new Check();
99
+
100
+        int expected = 0;
101
+        int actual = (check.compareTo(check));
102
+
103
+
104
+        assertEquals(expected, actual);
105
+    }
106
+}

+ 70
- 0
src/main/java/com/zipcoder/payment/CreditCard.java Datei anzeigen

@@ -0,0 +1,70 @@
1
+package com.zipcoder.payment;
2
+
3
+
4
+public class CreditCard implements Payment {
5
+    private long id;
6
+    private String payerName;
7
+    private String number;
8
+    private Integer expiredMonth = 0;
9
+    private Integer expiredYear = 0;
10
+
11
+    public CreditCard () {}
12
+
13
+    public CreditCard(long id, String payerName, String number, Integer expiredMonth, Integer expiredYear){
14
+
15
+    }
16
+
17
+
18
+        public long getId() {
19
+            return id;
20
+        }
21
+        public void setId(long id){
22
+            this.id = id;
23
+        }
24
+
25
+        public String getPayerName(){
26
+            return payerName;
27
+        }
28
+        public void setPayerName(String payerName){
29
+            this.payerName = payerName;
30
+        }
31
+
32
+    @Override
33
+        public String getShortDescription() {
34
+
35
+            return "CC " + getPayerName() + " " + getNumber() + " " + getExpiredMonth() +"/"+ getExpiredYear();
36
+        }
37
+
38
+
39
+    public Integer getExpiredMonth() {
40
+        return expiredMonth;
41
+    }
42
+    public void setExpiredMonth(Integer expiredMonth){
43
+            this.expiredMonth = expiredMonth;
44
+    }
45
+
46
+    public Integer getExpiredYear() {
47
+        return expiredYear;
48
+    }
49
+
50
+    public void setExpiredYear(Integer expiredYear) {
51
+        this.expiredYear = expiredYear;
52
+    }
53
+
54
+    public String getNumber() {
55
+        return number;
56
+    }
57
+    public void setNumber(String number){
58
+            this.number = number;
59
+    }
60
+
61
+    @Override
62
+    public int compareTo(Payment o) {
63
+
64
+
65
+        if (this.getShortDescription().compareToIgnoreCase(o.getShortDescription()) > 0) return 1;
66
+            else if (this.getShortDescription().compareToIgnoreCase(o.getShortDescription()) < 0) return -1;
67
+                else return 0;
68
+    }
69
+
70
+}

+ 128
- 0
src/main/java/com/zipcoder/payment/CreditCardTest.java Datei anzeigen

@@ -0,0 +1,128 @@
1
+package com.zipcoder.payment;
2
+
3
+import com.sun.deploy.net.CrossDomainXML;
4
+import org.junit.Test;
5
+
6
+import static org.junit.Assert.*;
7
+
8
+public class CreditCardTest {
9
+    Paypal pay = new Paypal();
10
+    Check check = new Check();
11
+    CreditCard card = new CreditCard();
12
+
13
+    @org.junit.Test
14
+    public void setId() {
15
+        CreditCard credit = new CreditCard();
16
+
17
+        long expectedId = 2019;
18
+        credit.setId(expectedId);
19
+
20
+        long actualId = credit.getId();
21
+
22
+        assertEquals(expectedId, actualId);
23
+    }
24
+
25
+    @org.junit.Test
26
+    public void setPayerName() {
27
+        CreditCard credit = new CreditCard();
28
+
29
+
30
+        String expectedPayerName = "James Goslin";
31
+        credit.setPayerName(expectedPayerName);
32
+
33
+        String actualPayerName = credit.getPayerName();
34
+
35
+        assertEquals(expectedPayerName, actualPayerName);
36
+    }
37
+
38
+    @org.junit.Test
39
+    public void getShortDescription() {
40
+        CreditCard credit = new CreditCard();
41
+
42
+        String name = "Tammy Jammy";
43
+        String accountNumber = "4551";
44
+        Integer month = 10;
45
+        Integer year = 2019;
46
+
47
+        credit.setPayerName(name);
48
+        credit.setNumber(accountNumber);
49
+        credit.setExpiredMonth(month);
50
+        credit.setExpiredYear(year);
51
+
52
+
53
+        String expectedDescription = "CC " + name + " " + accountNumber
54
+                + " " + month + "/" + year;
55
+
56
+        System.out.println(credit.getShortDescription());
57
+        String actualDescription = credit.getShortDescription();
58
+
59
+        assertEquals(expectedDescription, actualDescription);
60
+    }
61
+
62
+    @org.junit.Test
63
+    public void getExpiredMonth() {
64
+        CreditCard credit = new CreditCard();
65
+
66
+        int expectedExpMonth = 10;
67
+        credit.setExpiredMonth(expectedExpMonth);
68
+
69
+        int actualExpMonth = credit.getExpiredMonth();
70
+
71
+        assertEquals(expectedExpMonth, actualExpMonth);
72
+
73
+    }
74
+
75
+    @org.junit.Test
76
+    public void getExpiredYear() {
77
+        CreditCard credit = new CreditCard();
78
+
79
+        int expectedExpYear = 2019;
80
+        credit.setExpiredYear(expectedExpYear);
81
+
82
+        int actualExpYear = credit.getExpiredYear();
83
+
84
+        assertEquals(expectedExpYear, actualExpYear);
85
+
86
+    }
87
+
88
+    @org.junit.Test
89
+    public void setNumber() {
90
+        CreditCard credit = new CreditCard();
91
+
92
+        String expectedNumber = "7890";
93
+        credit.setNumber(expectedNumber);
94
+
95
+        String actualNumber = credit.getNumber();
96
+
97
+        assertEquals(expectedNumber, actualNumber);
98
+
99
+    }
100
+
101
+    @Test
102
+    public void compareToSelf() {
103
+        int expected = 0;
104
+        int actual = card.compareTo(card);
105
+
106
+        assertEquals(expected, actual);
107
+
108
+    }
109
+
110
+    @Test
111
+    public void compareToCheck(){
112
+        int expected = -1;
113
+        int actual = card.compareTo(check);
114
+
115
+        System.out.println(card.compareTo(check));
116
+        assertEquals(expected, actual);
117
+
118
+    }
119
+
120
+    @Test
121
+    public void compareToPaypal(){
122
+        int expected = -1;
123
+        int actual = card.compareTo(pay);
124
+
125
+        assertEquals(expected, actual);
126
+
127
+    }
128
+}

+ 13
- 0
src/main/java/com/zipcoder/payment/Payment.java Datei anzeigen

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

+ 19
- 0
src/main/java/com/zipcoder/payment/PaymentPresenter.java Datei anzeigen

@@ -1,6 +1,25 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
+import java.util.Arrays;
4
+
3 5
 public class PaymentPresenter {
4 6
 
5 7
 
8
+    public String toString(Payment[] payment) {
9
+
10
+        if (payment.length > 1)
11
+            return payment[0].getShortDescription() + "\n" + payment[1].getShortDescription() + "\n";
12
+        else return Arrays.toString(payment).replace("[]", "");
13
+
14
+        for (Payment o : payment){
15
+             o.getId(); o.getPayerName();
16
+        }
17
+    }
18
+
19
+
20
+
21
+
22
+
23
+
24
+
6 25
 }

+ 44
- 0
src/main/java/com/zipcoder/payment/PaymentPresenterTest.java Datei anzeigen

@@ -0,0 +1,44 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Test;
4
+
5
+import static junit.framework.TestCase.assertEquals;
6
+
7
+public class PaymentPresenterTest {
8
+
9
+    @Test
10
+    public void toStringNoPayments() {
11
+        Payment[] payments = new Payment[0];
12
+        PaymentPresenter presenter = new PaymentPresenter();
13
+        String expected = "";
14
+
15
+        String actual = presenter.toString(payments);
16
+
17
+        assertEquals(expected, actual);
18
+
19
+    }
20
+
21
+    @Test
22
+    public void toStringMultiplePayments() {
23
+        Payment[] payment = new Payment[2];
24
+        Paypal paypal = new Paypal(4L, "Tia Mowry", "tia@mowry.com");
25
+        Check check = new Check(81L, "Tia Mowry", "11432543", "134344551");
26
+
27
+
28
+        payment[0] = paypal;
29
+        payment[1] = check;
30
+
31
+        PaymentPresenter presenter = new PaymentPresenter();
32
+        String expected = "Check Tia Mowry ***4551\nPaypal Tia Mowry tia@mowry.com\n";
33
+
34
+        String actual = presenter.toString(payment);
35
+        assertEquals(expected, actual);
36
+    }
37
+
38
+//        paypal.setId(4L); paypal.setPayerName("Tia Mowry"); paypal.setEmail("tia@mowry.com");
39
+//        check.setId(81L); check.setPayerName("Tia Mowry"); check.setAccountNumber("11432543");
40
+//        check.setRoutingNumber("134344551");
41
+
42
+    }
43
+
44
+

+ 54
- 0
src/main/java/com/zipcoder/payment/Paypal.java Datei anzeigen

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

+ 96
- 0
src/main/java/com/zipcoder/payment/PaypalTest.java Datei anzeigen

@@ -0,0 +1,96 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Test;
4
+
5
+import static org.junit.Assert.*;
6
+
7
+public class PaypalTest {
8
+
9
+    @Test
10
+    public void getId() {
11
+        Paypal pay = new Paypal();
12
+
13
+        long expectedId = 6478;
14
+        pay.setId(expectedId);
15
+
16
+        long actualId = pay.getId();
17
+
18
+        assertEquals(expectedId, actualId);
19
+    }
20
+
21
+    @Test
22
+    public void getPayerName() {
23
+        Paypal pay = new Paypal();
24
+
25
+        String expectedName = "Andre Baugher";
26
+        pay.setPayerName(expectedName);
27
+
28
+        String actualName = pay.getPayerName();
29
+
30
+        assertEquals(expectedName, actualName);
31
+    }
32
+
33
+    @Test
34
+    public void getShortDescription() {
35
+        Paypal pay = new Paypal();
36
+
37
+        String name = "Andre Baugher";
38
+        String email = "scoopDAwoop82@woopty.com";
39
+
40
+        pay.setPayerName(name);
41
+        pay.setEmail(email);
42
+
43
+        String expectedDescription = "Paypal " + name + " " + email;
44
+        String actualDescription = pay.getShortDescription();
45
+
46
+        assertEquals(expectedDescription, actualDescription);
47
+    }
48
+
49
+    @Test
50
+    public void getEmail() {
51
+        Paypal pay = new Paypal();
52
+
53
+        String expectedMail = "scoopDAwoop82@woopty.com";
54
+        pay.setEmail(expectedMail);
55
+
56
+        String actualMail = pay.getEmail();
57
+
58
+        assertEquals(expectedMail, actualMail);
59
+    }
60
+
61
+    @Test
62
+    public void compareToCheck() {
63
+        Paypal pay = new Paypal();
64
+        Check check = new Check();
65
+
66
+        int expected = 1;
67
+        int actual = (pay.compareTo(check));
68
+
69
+
70
+        assertEquals(expected, actual);
71
+    }
72
+
73
+    @Test
74
+    public void compareToCredit() {
75
+        Paypal pay = new Paypal();
76
+        CreditCard card = new CreditCard();
77
+
78
+        int expected = 1;
79
+        int actual = (pay.compareTo(card));
80
+
81
+
82
+        assertEquals(expected, actual);
83
+    }
84
+
85
+    @Test
86
+    public void compareToSelf() {
87
+        Paypal pay = new Paypal();
88
+
89
+        int expected = 0;
90
+        int actual = (pay.compareTo(pay));
91
+
92
+
93
+        assertEquals(expected, actual);
94
+    }
95
+
96
+}

+ 0
- 4
src/test/java/com/zipcoder/payment/PaymentPresenterTest.java Datei anzeigen

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