Ben Blinebury 8 лет назад
Родитель
Сommit
a8686232a5

+ 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>junit</groupId>
13
+            <artifactId>junit</artifactId>
14
+            <version>RELEASE</version>
15
+            <scope>test</scope>
16
+        </dependency>
17
+        <dependency>
18
+            <groupId>junit</groupId>
19
+            <artifactId>junit</artifactId>
20
+            <version>RELEASE</version>
21
+            <scope>test</scope>
22
+        </dependency>
23
+    </dependencies>
10 24
 
11 25
 
12 26
 </project>

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

@@ -0,0 +1,60 @@
1
+package com.zipcoder.payment;
2
+
3
+public class Check implements Payment {
4
+    Long id = 0L;
5
+    String payerName;
6
+    String routingNumber;
7
+    String accountNumber;
8
+
9
+    public Check(long id, String payerName, String routingNumber, String accountNumber) {
10
+        this.id = id;
11
+        this.payerName = payerName;
12
+        this.routingNumber = routingNumber;
13
+        this.accountNumber = accountNumber;
14
+    }
15
+
16
+    public Check(){
17
+
18
+    }
19
+
20
+    public long getId() {
21
+        return id;
22
+    }
23
+
24
+    public void setId(Long id) {
25
+        this.id = id;
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 " + payerName + " ***4551";
54
+    }
55
+
56
+    public int compareTo(Payment p) {
57
+        return this.getShortDescription().compareTo(p.getShortDescription());
58
+    }
59
+
60
+}

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

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

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

@@ -0,0 +1,10 @@
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
+}

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

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

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

@@ -0,0 +1,15 @@
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 p1, Payment p2){
8
+
9
+        return p1.getPayerName().compareTo(p2.getPayerName());
10
+
11
+        }
12
+
13
+
14
+}
15
+

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

@@ -0,0 +1,84 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+
5
+import static org.junit.Assert.*;
6
+
7
+public class CheckTest {
8
+
9
+    @org.junit.Test
10
+    public void getId() {
11
+        Check ch = new Check();
12
+        ch.setId(1234L);
13
+        long expected = ch.getId();
14
+        long actual = 1234L;
15
+        Assert.assertEquals(expected, actual);
16
+    }
17
+
18
+    @org.junit.Test
19
+    public void setId() {
20
+        Check ch = new Check();
21
+        ch.setId(123L);
22
+        long expected = ch.getId();
23
+        long actual = 123L;
24
+        Assert.assertEquals(expected, actual);
25
+    }
26
+
27
+    @org.junit.Test
28
+    public void getPayerName() {
29
+        Check ch = new Check();
30
+        ch.setPayerName("Stormy");
31
+        String expected = ch.getPayerName();
32
+        String actual = "Stormy";
33
+        Assert.assertEquals(expected, actual);
34
+    }
35
+
36
+    @org.junit.Test
37
+    public void setPayerName() {
38
+        Check ch = new Check();
39
+        ch.setPayerName("Jewelz");
40
+        String expected = ch.getPayerName();
41
+        String actual = "Jewelz";
42
+        Assert.assertEquals(expected, actual);
43
+    }
44
+
45
+    @org.junit.Test
46
+    public void getRoutingNumber() {
47
+        Check ch = new Check();
48
+        ch.setRoutingNumber("123456789");
49
+        String expected = ch.getRoutingNumber();
50
+        String actual = "123456789";
51
+        Assert.assertEquals(expected, actual);
52
+    }
53
+
54
+    @org.junit.Test
55
+    public void setRoutingNumber() {
56
+        Check ch = new Check();
57
+        ch.setRoutingNumber("12345678");
58
+        String expected = ch.getRoutingNumber();
59
+        String actual = "12345678";
60
+        Assert.assertEquals(expected, actual);
61
+    }
62
+
63
+    @org.junit.Test
64
+    public void getAccountNumber() {
65
+        Check ch = new Check();
66
+        ch.setAccountNumber("33-123");
67
+        String expected = ch.getAccountNumber();
68
+        String actual = "33-123";
69
+        Assert.assertEquals(expected, actual);
70
+    }
71
+
72
+    @org.junit.Test
73
+    public void setAccountNumber() {
74
+        Check ch = new Check();
75
+        ch.setAccountNumber("33-124");
76
+        String expected = ch.getAccountNumber();
77
+        String actual = "33-124";
78
+        Assert.assertEquals(expected, actual);
79
+    }
80
+
81
+    @org.junit.Test
82
+    public void getShortDescription() {
83
+    }
84
+}

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

@@ -0,0 +1,112 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+import javax.print.DocFlavor;
7
+
8
+import static org.junit.Assert.*;
9
+
10
+public class CreditCardTest {
11
+
12
+    @Test
13
+    public void getId() {
14
+        CreditCard cc = new CreditCard();
15
+        cc.setId(4551L);
16
+        long expected = cc.getId();
17
+        long actual = 4551L;
18
+        Assert.assertEquals(expected, actual);
19
+    }
20
+
21
+    @Test
22
+    public void setId() {
23
+        CreditCard cc = new CreditCard();
24
+        cc.setId(315L);
25
+        long expected = cc.getId();
26
+        long actual = 315L;
27
+        Assert.assertEquals(expected, actual);
28
+
29
+    }
30
+
31
+    @Test
32
+    public void getPayerName() {
33
+        CreditCard cc = new CreditCard();
34
+        cc.setPayerName("Cinnamon");
35
+        String expected = cc.getPayerName();
36
+        String actual = "Cinnamon";
37
+        Assert.assertEquals(expected, actual);
38
+    }
39
+
40
+    @Test
41
+    public void setPayerName() {
42
+        CreditCard cc = new CreditCard();
43
+        cc.setPayerName("Mercedez");
44
+        String expected = cc.getPayerName();
45
+        String actual = "Mercedez";
46
+        Assert.assertEquals(expected, actual);
47
+    }
48
+
49
+    @Test
50
+    public void getNumber() {
51
+        CreditCard cc = new CreditCard();
52
+        cc.setNumber("856-358-1032");
53
+        String expected = cc.getNumber();
54
+        String actual = "856-358-1032";
55
+        Assert.assertEquals(expected, actual);
56
+    }
57
+
58
+    @Test
59
+    public void setNumber() {
60
+        CreditCard cc = new CreditCard();
61
+        cc.setNumber("215-964-2484");
62
+        String expected = cc.getNumber();
63
+        String actual = "215-964-2484";
64
+        Assert.assertEquals(expected, actual);
65
+    }
66
+
67
+    @Test
68
+    public void getExpiredMonth() {
69
+        CreditCard cc = new CreditCard();
70
+        cc.setExpiredMonth(12);
71
+        int expected = cc.getExpiredMonth();
72
+        int actual = 12;
73
+        Assert.assertEquals(expected, actual);
74
+    }
75
+
76
+    @Test
77
+    public void setExpiredMonth() {
78
+        CreditCard cc = new CreditCard();
79
+        cc.setExpiredMonth(11);
80
+        int expected = cc.getExpiredMonth();
81
+        int actual = 11;
82
+        Assert.assertEquals(expected, actual);
83
+    }
84
+
85
+    @Test
86
+    public void getExpiredYear() {
87
+        CreditCard cc = new CreditCard();
88
+        cc.setExpiredYear(2018);
89
+        int expected = cc.getExpiredYear();
90
+        int actual = 2018;
91
+        Assert.assertEquals(expected, actual);
92
+    }
93
+
94
+    @Test
95
+    public void setExpiredYear() {
96
+        CreditCard cc = new CreditCard();
97
+        cc.setExpiredYear(2020);
98
+        int expected = cc.getExpiredYear();
99
+        int actual = 2020;
100
+        Assert.assertEquals(expected, actual);
101
+    }
102
+
103
+    @Test
104
+    public void getShortDescription() {
105
+
106
+    }
107
+
108
+    @Test
109
+    public void setShortDescription() {
110
+
111
+    }
112
+}

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

@@ -0,0 +1,49 @@
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(long id, String payerName, String email){
9
+        this.id = id;
10
+        this.payerName = payerName;
11
+        this.email = email;
12
+    }
13
+
14
+    public PayPal() {
15
+
16
+    }
17
+
18
+    public long getId() {
19
+        return id;
20
+    }
21
+
22
+    public void setId(long id) {
23
+        this.id = id;
24
+    }
25
+
26
+    public String getPayerName() {
27
+        return payerName;
28
+    }
29
+
30
+    public void setPayerName(String payerName) {
31
+        this.payerName = payerName;
32
+    }
33
+
34
+    public String getEmail() {
35
+        return email;
36
+    }
37
+
38
+    public void setEmail(String email) {
39
+        this.email = email;
40
+    }
41
+
42
+    public String getShortDescription() {
43
+        return "PayPal " + payerName + " " + email;
44
+    }
45
+
46
+    public int compareTo(Payment p) {
47
+        return this.getShortDescription().compareTo(p.getShortDescription());
48
+    }
49
+}

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

@@ -0,0 +1,69 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+import static org.junit.Assert.*;
7
+
8
+public class PayPalTest {
9
+
10
+    @Test
11
+    public void getId() {
12
+        PayPal pp = new PayPal();
13
+        pp.setId(12345L);
14
+        long expected = pp.getId();
15
+        long actual = 12345L;
16
+        Assert.assertEquals(expected, actual);
17
+    }
18
+
19
+    @Test
20
+    public void setId() {
21
+        PayPal pp = new PayPal();
22
+        pp.setId(2345L);
23
+        long expected = pp.getId();
24
+        long actual = 2345L;
25
+        Assert.assertEquals(expected, actual);
26
+    }
27
+
28
+    @Test
29
+    public void getPayerName() {
30
+        PayPal pp = new PayPal();
31
+        pp.setPayerName("Hot Chocolate");
32
+        String expected = pp.getPayerName();
33
+        String actual = "Hot Chocolate";
34
+        Assert.assertEquals(expected, actual);
35
+    }
36
+
37
+    @Test
38
+    public void setPayerName() {
39
+        PayPal pp = new PayPal();
40
+        pp.setPayerName("Diamond Kream");
41
+        String expected = pp.getPayerName();
42
+        String actual = "Diamond Kream";
43
+        Assert.assertEquals(expected, actual);
44
+    }
45
+
46
+    @Test
47
+    public void getEmail() {
48
+        PayPal pp = new PayPal();
49
+        pp.setEmail("2cool4school@clownfart.butt");
50
+        String expected = pp.getEmail();
51
+        String actual = "2cool4school@clownfart.butt";
52
+        Assert.assertEquals(expected, actual);
53
+    }
54
+
55
+    @Test
56
+    public void setEmail() {
57
+        PayPal pp = new PayPal();
58
+        pp.setEmail("akirafan367@geocities.com");
59
+        String expected = pp.getEmail();
60
+        String actual = "akirafan367@geocities.com";
61
+        Assert.assertEquals(expected, actual);
62
+    }
63
+
64
+    @Test
65
+    public void compareTo() {
66
+    Payment pp = new PayPal(1, "Tia Mowry", "tia@mowry.com");
67
+    Payment ch = new Check(1, "Tia Mowry", "00004551", "00004551");
68
+    }
69
+}

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

@@ -1,4 +1,62 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
+import com.zipcoder.payment.Check;
4
+import com.zipcoder.payment.PayPal;
5
+import com.zipcoder.payment.Payment;
6
+import com.zipcoder.payment.PaymentPresenter;
7
+import org.junit.Assert;
8
+import org.junit.Test;
9
+
3 10
 public class PaymentPresenterTest {
4
-}
11
+
12
+            @Test
13
+            public void toStringTest() {
14
+                Payment[] payments = new Payment[0];
15
+                PaymentPresenter presenter = new PaymentPresenter();
16
+                String expected = "";
17
+
18
+                String actual = presenter.toString(payments);
19
+
20
+                Assert.assertEquals(expected, actual);
21
+            }
22
+
23
+            @Test
24
+            public void toStringTest2() {
25
+                Payment paypal = new PayPal(4L, "Tia Mowry", "tia@mowry.com");
26
+                Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
27
+                Payment[] payments = new Payment[]{paypal, check};
28
+
29
+                PaymentPresenter presenter = new PaymentPresenter();
30
+                String expected = "Check Tia Mowry ***4551\nPayPal Tia Mowry tia@mowry.com\n";
31
+
32
+                String actual = presenter.toString(payments);
33
+                Assert.assertEquals(expected, actual);
34
+            }
35
+
36
+            @Test
37
+            public void toStringByPayerNameTest() {
38
+                Payment paypal = new PayPal(4L, "Tamara Mowry", "tamara@mowry.com");
39
+                Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
40
+                Payment[] payments = new Payment[]{check, paypal};
41
+
42
+                PaymentPresenter presenter = new PaymentPresenter();
43
+                String expected = "PayPal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
44
+
45
+                String actual = presenter.toStringByPayerName(payments);
46
+                Assert.assertEquals(expected, actual);
47
+            }
48
+
49
+            @Test
50
+            public void toStringByIdTest() {
51
+                Payment paypal = new PayPal(120L, "Tamara Mowry", "tamara@mowry.com");
52
+                Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
53
+                Payment[] payments = new Payment[]{paypal, check};
54
+
55
+
56
+                PaymentPresenter presenter = new PaymentPresenter();
57
+                String expected = "Check Tia Mowry ***4551\nPayPal Tamara Mowry tamara@mowry.com\n";
58
+                String actual = presenter.toStringById(payments);
59
+                Assert.assertEquals(expected, actual);
60
+
61
+                    }
62
+}