Lewis Dominguez пре 8 година
родитељ
комит
e2eb51963c

+ 14
- 0
pom.xml Прегледај датотеку

@@ -7,6 +7,20 @@
7 7
     <groupId>com.zipcoder</groupId>
8 8
     <artifactId>payment</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <dependencies>
11
+        <dependency>
12
+            <groupId>org.junit.jupiter</groupId>
13
+            <artifactId>junit-jupiter-api</artifactId>
14
+            <version>RELEASE</version>
15
+            <scope>test</scope>
16
+        </dependency>
17
+        <dependency>
18
+            <groupId>com.zipcoder</groupId>
19
+            <artifactId>payment</artifactId>
20
+            <version>1.0-SNAPSHOT</version>
21
+            <scope>test</scope>
22
+        </dependency>
23
+    </dependencies>
10 24
 
11 25
 
12 26
 </project>


BIN
src/main/.DS_Store Прегледај датотеку


BIN
src/main/java/.DS_Store Прегледај датотеку


BIN
src/main/java/com/.DS_Store Прегледај датотеку


BIN
src/main/java/com/zipcoder/.DS_Store Прегледај датотеку


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

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

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

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

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

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

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

@@ -1,6 +1,38 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
+import java.util.Arrays;
4
+import java.util.Comparator;
5
+
3 6
 public class PaymentPresenter {
4 7
 
8
+    public String toString(Payment[] payments) {
9
+
10
+        Arrays.sort(payments);
11
+        return forMultipleDescriptions(payments);
12
+
13
+
14
+    }
15
+
16
+    public String forMultipleDescriptions(Payment[] payments) {
17
+        StringBuilder sb = new StringBuilder();
18
+        for (Payment payment : payments) {
19
+            sb.append(payment.getShortDescription() + "\n");
20
+        }
21
+        return sb.toString();
22
+    }
5 23
 
24
+    public String toStringByPayerName(Payment[] payments) {
25
+        PaymentSortByPayer psbp = new PaymentSortByPayer();
26
+        Arrays.sort(payments, psbp);
27
+        return forMultipleDescriptions(payments);
28
+    }
29
+
30
+    public String toStringBySetId(Payment[] payments) {
31
+        Comparator<Payment> compareById = ((o1, o2) -> o1.getId().compareTo(o2.getId()));
32
+        Arrays.sort(payments, compareById);
33
+        return forMultipleDescriptions(payments);
34
+    }
6 35
 }
36
+
37
+
38
+

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

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

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

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

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

@@ -0,0 +1,95 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.jupiter.api.Test;
4
+
5
+import static org.junit.jupiter.api.Assertions.assertEquals;
6
+import static org.junit.jupiter.api.Assertions.assertTrue;
7
+
8
+public class CheckTest {
9
+
10
+
11
+    @Test
12
+    public void getIdTest() {
13
+        Check check = new Check();
14
+        check.setId(1234L);
15
+
16
+        long expected = 1234L;
17
+
18
+        long actual = check.getId();
19
+
20
+        assertEquals(expected, actual);
21
+    }
22
+
23
+    @Test
24
+    public void getPayerNameTest() {
25
+        Check check = new Check();
26
+        check.setPayerName("Luisa");
27
+
28
+        String expected = "Luisa";
29
+
30
+        String actual = check.getPayerName();
31
+
32
+        assertEquals(expected, actual);
33
+    }
34
+
35
+    @Test
36
+    public void getRoutingNumberTest() {
37
+        Check check = new Check();
38
+        check.setRoutingNumber("123456789");
39
+
40
+        String expected = "123456789";
41
+
42
+        String actual = check.getRoutingNumber();
43
+
44
+        assertEquals(expected, actual);
45
+    }
46
+
47
+    @Test
48
+    public void getAccountNumberTest() {
49
+        Check check = new Check();
50
+        check.setAccountNumber("987654321");
51
+
52
+        String expected = "987654321";
53
+
54
+        String actual = check.getAccountNumber();
55
+
56
+        assertEquals(expected, actual);
57
+    }
58
+
59
+    @Test
60
+    public void getShortDescriptionTest() {
61
+        Check check = new Check("Lewis Dominguez", "123456789", "987654321");
62
+
63
+        String expected = "Check Lewis Dominguez ***4321";
64
+
65
+        String actual = check.getShortDescription();
66
+
67
+        assertEquals(expected, actual);
68
+    }
69
+
70
+    @Test
71
+    public void getLastFourTest() {
72
+        Check check = new Check();
73
+
74
+        String expected = "4321";
75
+
76
+        check.setAccountNumber("987654321");
77
+
78
+        assertEquals(expected, check.getLastFour());
79
+
80
+    }
81
+
82
+    @Test
83
+    public void compareToTest() {
84
+
85
+        Paypal paypal = new Paypal("Lewis Dominguez", "awesomeemail@awesomeemail.com");
86
+        Check check = new Check("Lewis Dominguez", "123456789", "987654321");
87
+
88
+
89
+        assertTrue(paypal.compareTo(check) > 0);
90
+    }
91
+
92
+
93
+
94
+
95
+}

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

@@ -0,0 +1,107 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.jupiter.api.Test;
4
+
5
+import static org.junit.jupiter.api.Assertions.assertEquals;
6
+import static org.junit.jupiter.api.Assertions.assertTrue;
7
+
8
+public class CreditCardTest {
9
+
10
+    @Test
11
+    public void getIdTest() {
12
+        CreditCard creditCard = new CreditCard();
13
+        creditCard.setId(1234L);
14
+
15
+        long expected = 1234L;
16
+
17
+        long actual = creditCard.getId();
18
+
19
+        assertEquals(expected, actual);
20
+    }
21
+
22
+    @Test
23
+    public void getPayerNameTest() {
24
+        CreditCard creditCard = new CreditCard();
25
+        creditCard.setPayerName("Luisa");
26
+
27
+        String expected = "Luisa";
28
+
29
+        String actual = creditCard.getPayerName();
30
+
31
+        assertEquals(expected, actual);
32
+    }
33
+
34
+
35
+    @Test
36
+    public void getNumberTest() {
37
+        CreditCard creditCard = new CreditCard();
38
+        creditCard.setNumber("123456789");
39
+
40
+        String expected = "123456789";
41
+
42
+        String actual = creditCard.getNumber();
43
+
44
+        assertEquals(expected, actual);
45
+    }
46
+
47
+    @Test
48
+    public void getExpiredMonth() {
49
+        CreditCard creditCard = new CreditCard();
50
+        creditCard.setExpiredMonth(1);
51
+
52
+        int expected = 1;
53
+
54
+        int actual = creditCard.getExpiredMonth();
55
+
56
+        assertEquals(expected, actual);
57
+    }
58
+
59
+    @Test
60
+    public void getExpiredYear() {
61
+        CreditCard creditCard = new CreditCard();
62
+        creditCard.setExpiredYear(2030);
63
+
64
+        int expected = 2030;
65
+
66
+        int actual = creditCard.getExpiredYear();
67
+
68
+        assertEquals(expected, actual);
69
+    }
70
+
71
+    @Test
72
+    public void getShortDescriptionTest() {
73
+        CreditCard creditCard = new CreditCard("Lewis Dominguez", "123456789", 1, 2030);
74
+
75
+
76
+        String expected = "CC Lewis Dominguez 6789 1/2030";
77
+
78
+        String actual = creditCard.getShortDescription();
79
+
80
+        assertEquals(expected, actual);
81
+    }
82
+
83
+    @Test
84
+    public void getLastFourTest() {
85
+        CreditCard creditCard = new CreditCard();
86
+
87
+        String expected = "6789";
88
+
89
+        creditCard.setNumber("123456789");
90
+
91
+        assertEquals(expected, creditCard.getLastFour());
92
+    }
93
+
94
+    @Test
95
+    public void compareToTest() {
96
+        CreditCard credit = new CreditCard("Lewis Dominguez", "123456789", 1, 2030);
97
+        Paypal paypal = new Paypal("Lewis Dominguez", "awesomeemail@awesomeemail.com");
98
+
99
+        assertTrue(credit.compareTo(paypal) < 0);
100
+
101
+
102
+
103
+    }
104
+
105
+
106
+
107
+}

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

@@ -1,4 +1,78 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
+import org.junit.jupiter.api.Test;
4
+
5
+import static org.junit.jupiter.api.Assertions.assertEquals;
6
+
3 7
 public class PaymentPresenterTest {
8
+
9
+
10
+    @Test
11
+    public void toStringTest() {
12
+        Payment[] payments = new Payment[0];
13
+        PaymentPresenter pp = new PaymentPresenter();
14
+        String expected = "";
15
+
16
+        String actual = pp.toString(payments);
17
+
18
+        assertEquals(expected, actual);
19
+
20
+
21
+    }
22
+
23
+
24
+    @Test
25
+    public void toStringMultipleTest() {
26
+        Payment[] payments = new Payment[2];
27
+        Payment paypal = new Paypal("Tia Mowry", "tia@mowry.com");
28
+        Payment check = new Check("Lewis Dominguez", "11432543", "134344551");
29
+
30
+        payments[0] = paypal;
31
+        payments[1] = check;
32
+
33
+        PaymentPresenter presenter = new PaymentPresenter();
34
+        String expected = "Check Lewis Dominguez ***4551\nPaypal Tia Mowry tia@mowry.com\n";
35
+
36
+        String actual = presenter.toString(payments);
37
+        assertEquals(expected, actual);
38
+    }
39
+
40
+    @Test
41
+    public void toStringPaymentByPayer() {
42
+        Payment[] payments = new Payment[2];
43
+        Payment paypal = new Paypal("Tia Mowry", "tia@mowry.com");
44
+        Payment check = new Check("Lewis Dominguez", "11432543", "134344551");
45
+
46
+        payments[0] = paypal;
47
+        payments[1] = check;
48
+
49
+        PaymentPresenter presenter = new PaymentPresenter();
50
+        String expected = "Check Lewis Dominguez ***4551\nPaypal Tia Mowry tia@mowry.com\n";
51
+
52
+        String actual = presenter.toStringByPayerName(payments);
53
+        assertEquals(expected, actual);
54
+    }
55
+
56
+    @Test
57
+    public void toStringBySetIdTest() {
58
+        Payment[] payments = new Payment[2];
59
+        Paypal paypal = new Paypal("Tia Mowry", "tia@mowry.com");
60
+        Check check = new Check("Lewis Dominguez", "11432543", "134344551");
61
+        paypal.setId(2L);
62
+        check.setId(1L);
63
+
64
+        payments[0] = paypal;
65
+        payments[1] = check;
66
+
67
+        PaymentPresenter presenter = new PaymentPresenter();
68
+        String expected = "Check Lewis Dominguez ***4551\nPaypal Tia Mowry tia@mowry.com\n";
69
+
70
+        String actual = presenter.toStringBySetId(payments);
71
+        assertEquals(expected, actual);
72
+
73
+    }
74
+
75
+
76
+
4 77
 }
78
+

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

@@ -0,0 +1,16 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.jupiter.api.Test;
4
+
5
+import static org.junit.jupiter.api.Assertions.assertTrue;
6
+
7
+public class PaymentSortByPayerTest {
8
+    @Test
9
+    public void compareTest() {
10
+        Paypal.PaymentSortByPayer psbp = new Paypal.PaymentSortByPayer();
11
+        Paypal paypal = new Paypal("Lewis Dominguez", "awesomeemail@awesomeemail.com");
12
+        Check check = new Check("Lewis Dominguez", "987654321", "123456789");
13
+
14
+        assertTrue(psbp.compare(paypal, check) == 0);
15
+    }
16
+}

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

@@ -0,0 +1,67 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.jupiter.api.Test;
4
+
5
+import static org.junit.jupiter.api.Assertions.assertEquals;
6
+import static org.junit.jupiter.api.Assertions.assertTrue;
7
+
8
+public class PaypalTest {
9
+
10
+    @Test
11
+    public void getIdTest() {
12
+        Paypal paypal = new Paypal();
13
+        paypal.setId(1234L);
14
+
15
+        long expected = 1234L;
16
+
17
+        long actual = paypal.getId();
18
+
19
+        assertEquals(expected, actual);
20
+    }
21
+
22
+    @Test
23
+    public void getPayerNameTest() {
24
+        Paypal paypal = new Paypal();
25
+        paypal.setPayerName("Luisa");
26
+
27
+        String expected = "Luisa";
28
+
29
+        String actual = paypal.getPayerName();
30
+
31
+        assertEquals(expected, actual);
32
+    }
33
+
34
+    @Test
35
+    public void getEmailTest() {
36
+        Paypal paypal = new Paypal();
37
+        paypal.setEmail("bestemail@bestemail.com");
38
+
39
+        String expected = "bestemail@bestemail.com";
40
+
41
+        String actual = paypal.getEmail();
42
+
43
+        assertEquals(expected, actual);
44
+    }
45
+
46
+    @Test
47
+    public void getShortDescritionTest() {
48
+        Paypal paypal = new Paypal("Lewis Dominguez", "awesomeemail@awesomeemail.com");
49
+
50
+        String expected = "Paypal Lewis Dominguez awesomeemail@awesomeemail.com";
51
+
52
+        String actual = paypal.getShortDescription();
53
+
54
+        assertEquals(expected, actual);
55
+    }
56
+
57
+    @Test
58
+    public void compareTo() {
59
+        Paypal paypal = new Paypal("Lewis Dominguez", "awesomeemail@awesomeemail.com");
60
+        Check check = new Check("Lewis Dominguez", "987654321", "123456789");
61
+
62
+        assertTrue(paypal.compareTo(check) > 0);
63
+    }
64
+
65
+
66
+
67
+}