瀏覽代碼

basically done

William Simkins 8 年之前
父節點
當前提交
5e60970a9f

+ 8
- 0
pom.xml 查看文件

@@ -7,6 +7,14 @@
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
+    </dependencies>
10 18
 
11 19
 
12 20
 </project>

+ 72
- 0
src/main/java/com/zipcoder/payment/Check.java 查看文件

@@ -0,0 +1,72 @@
1
+package com.zipcoder.payment;
2
+
3
+public class Check implements Payment{
4
+    private long id;
5
+    private String payerName;
6
+    private String shortDescription;
7
+    private String number;
8
+    private String routingNumber;
9
+    private String accountNumber;
10
+
11
+
12
+    public Check(long id, String payerName, String routingNumber, String accountNumber) {
13
+
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 getShortDescription() {
37
+        return "Check" + " " + getPayerName() + " " + "***" + getNumber();
38
+    }
39
+
40
+    public void setShortDescription(String shortDescription){
41
+        this.shortDescription = shortDescription;
42
+    }
43
+
44
+    public String getNumber(){
45
+        return number;
46
+    }
47
+
48
+    public void setNumber(String number){
49
+        this.number = number;
50
+    }
51
+
52
+    public String getRoutingNumber(){
53
+        return routingNumber;
54
+    }
55
+
56
+    public void setRoutingNumber(String routingNumber){
57
+        this.routingNumber = routingNumber;
58
+    }
59
+
60
+    public String getAccountNumber(){
61
+        return accountNumber;
62
+    }
63
+
64
+    public void setAccountNumber(String accountNumber){
65
+        this.accountNumber = accountNumber;
66
+    }
67
+
68
+    public int compareTo(Payment payment){
69
+        return this.getShortDescription().compareTo(payment.getShortDescription());
70
+    }
71
+
72
+}

+ 71
- 0
src/main/java/com/zipcoder/payment/CreditCard.java 查看文件

@@ -0,0 +1,71 @@
1
+package com.zipcoder.payment;
2
+
3
+public class CreditCard implements Payment {
4
+    private long id;
5
+    private String payerName;
6
+    private String shortDescription;
7
+    private String number;
8
+    private int expiredMonth;
9
+    private int expiredYear;
10
+
11
+    public CreditCard(long id, String payerName, String number, int expiredMonth, int expiredYear){
12
+
13
+    }
14
+
15
+    public CreditCard(){
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 getShortDescription() {
36
+        return "CC" + " " + getPayerName() + " " + getNumber() + " " + getExpiredMonth() + "/" + getExpiredYear();
37
+    }
38
+
39
+    public void setShortDescription(String shortDescription){
40
+        this.shortDescription = shortDescription;
41
+    }
42
+
43
+    public String getNumber(){
44
+        return number;
45
+    }
46
+
47
+    public void setNumber(String number){
48
+        this.number = number;
49
+    }
50
+
51
+    public int getExpiredMonth(){
52
+        return expiredMonth;
53
+    }
54
+
55
+    public void setExpiredMonth(int expiredMonth){
56
+        this.expiredMonth = expiredMonth;
57
+    }
58
+
59
+    public int getExpiredYear(){
60
+        return expiredYear;
61
+    }
62
+
63
+    public void setExpiredYear(int expiredYear){
64
+        this.expiredYear = expiredYear;
65
+    }
66
+
67
+    public int compareTo(Payment payment){
68
+        return this.getShortDescription().compareTo(payment.getShortDescription());
69
+    }
70
+}
71
+

+ 54
- 0
src/main/java/com/zipcoder/payment/PayPal.java 查看文件

@@ -0,0 +1,54 @@
1
+package com.zipcoder.payment;
2
+
3
+public class PayPal implements Payment {
4
+    private long id;
5
+    private String payerName;
6
+    private String shortDescription;
7
+    private String email;
8
+
9
+    public PayPal(long id, String payerName, String email){
10
+        this.id = id;
11
+        this.payerName = payerName;
12
+        this.email = email;
13
+    }
14
+
15
+    public PayPal(){
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 getShortDescription() {
36
+        return "PayPal" + " " + getPayerName() + " " + getEmail();
37
+    }
38
+
39
+    public void setShortDescription(String shortDescription){
40
+        this.shortDescription = shortDescription;
41
+    }
42
+
43
+    public String getEmail(){
44
+        return email;
45
+    }
46
+
47
+    public void setEmail(String email) {
48
+        this.email = email;
49
+    }
50
+
51
+    public int compareTo(Payment payment){
52
+        return this.getShortDescription().compareTo(payment.getShortDescription());
53
+    }
54
+}

+ 7
- 0
src/main/java/com/zipcoder/payment/Payment.java 查看文件

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

+ 23
- 0
src/main/java/com/zipcoder/payment/PaymentPresenter.java 查看文件

@@ -1,6 +1,29 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
+import java.util.Arrays;
4
+
5
+import static sun.rmi.registry.RegistryImpl.getID;
6
+
3 7
 public class PaymentPresenter {
8
+    public String toString(Payment[] payments) {
9
+        Arrays.sort(payments);
10
+        StringBuilder string = new StringBuilder();
11
+        for (Payment payment : payments) {
12
+            string.append(payment.getShortDescription() +"\n");
13
+        }
14
+        return string.toString();
15
+    }
16
+
17
+    public String toStringByPayerName(Payment[] payments) {
18
+        Arrays.sort(payments, new PaymentSortByPayer());
19
+        StringBuilder string = new StringBuilder();
20
+        for (Payment payment : payments) {
21
+            payment.getPayerName();
22
+            string.append(payment.getShortDescription() + "\n");
23
+        }
24
+        return string.toString();
25
+    }
26
+
4 27
 
5 28
 
6 29
 }

+ 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 payment1, Payment payment2){
8
+        return payment1.getPayerName().compareTo(payment2.getPayerName());
9
+    }
10
+}

+ 68
- 0
src/test/java/com/zipcoder/payment/CheckTest.java 查看文件

@@ -0,0 +1,68 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Test;
4
+
5
+import static org.junit.Assert.assertEquals;
6
+
7
+public class CheckTest {
8
+    Check check = new Check();
9
+
10
+    @Test
11
+    public void testGetId(){
12
+        long expected = 123456789;
13
+        check.setId(expected);
14
+        long actual = check.getId();
15
+        assertEquals(expected, actual);
16
+    }
17
+
18
+    @Test
19
+    public void testPayerName(){
20
+        String expected = "Tia Mowry";
21
+        check.setPayerName(expected);
22
+        String actual = check.getPayerName();
23
+        assertEquals(expected, actual);
24
+    }
25
+
26
+    @Test
27
+    public void testNumber(){
28
+        String expected = "4551";
29
+        check.setNumber(expected);
30
+        String actual = check.getNumber();
31
+        assertEquals(expected, actual);
32
+    }
33
+
34
+    @Test
35
+    public void testRoutingNumber(){
36
+        String expected = "987654321";
37
+        check.setRoutingNumber(expected);
38
+        String actual = check.getRoutingNumber();
39
+        assertEquals(expected, actual);
40
+    }
41
+
42
+    @Test
43
+    public void testAccountNumber(){
44
+        String expected = "123456789";
45
+        check.setAccountNumber(expected);
46
+        String actual = check.getAccountNumber();
47
+        assertEquals(expected, actual);
48
+    }
49
+
50
+    @Test
51
+    public void testShortDescription(){
52
+        String expected = "Check Tia Mowry ***4551";
53
+        String name = "Tia Mowry";
54
+        check.setPayerName(name);
55
+        String number = "4551";
56
+        check.setNumber(number);
57
+        String actual = check.getShortDescription();
58
+        assertEquals(expected, actual);
59
+    }
60
+
61
+    @Test
62
+    public void compareTo() {
63
+        Payment paypal = new PayPal(1, "Tia Mowry", "tia@mowry.com");
64
+        Payment check = new Check(1, "Tia Mowry", "00004551", "00004551");
65
+        Payment creditcard = new CreditCard(1, "Tia Mowry", "4551", 10, 2019);
66
+    }
67
+
68
+}

+ 73
- 0
src/test/java/com/zipcoder/payment/CreditCardTest.java 查看文件

@@ -0,0 +1,73 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Test;
4
+
5
+import static org.junit.Assert.assertEquals;
6
+
7
+public class CreditCardTest {
8
+    CreditCard cc = new CreditCard();
9
+
10
+    @Test
11
+    public void testGetId(){
12
+        long expected = 123456789;
13
+        cc.setId(expected);
14
+        long actual = cc.getId();
15
+        assertEquals(expected, actual);
16
+    }
17
+
18
+    @Test
19
+    public void testPayerName(){
20
+        String expected = "Tia Mowry";
21
+        cc.setPayerName(expected);
22
+        String actual = cc.getPayerName();
23
+        assertEquals(expected, actual);
24
+    }
25
+
26
+    @Test
27
+    public void testNumber(){
28
+        String expected = "4551";
29
+        cc.setNumber(expected);
30
+        String actual = cc.getNumber();
31
+        assertEquals(expected, actual);
32
+    }
33
+
34
+    @Test
35
+    public void testExpiredMonth(){
36
+        int expected = 10;
37
+        cc.setExpiredMonth(expected);
38
+        int actual = cc.getExpiredMonth();
39
+        assertEquals(expected, actual);
40
+
41
+    }
42
+
43
+    @Test
44
+    public void testExpiredYear(){
45
+        int expected = 2019;
46
+        cc.setExpiredYear(expected);
47
+        int actual = cc.getExpiredYear();
48
+        assertEquals(expected, actual);
49
+
50
+    }
51
+
52
+    @Test
53
+    public void testShortDescription(){
54
+        String expected = "CC Tia Mowry 4551 10/2019";
55
+        String name = "Tia Mowry";
56
+        cc.setPayerName(name);
57
+        String number = "4551";
58
+        cc.setNumber(number);
59
+        int expireMonth = 10;
60
+        cc.setExpiredMonth(expireMonth);
61
+        int expireYear = 2019;
62
+        cc.setExpiredYear(expireYear);
63
+        String actual = cc.getShortDescription();
64
+        assertEquals(expected, actual);
65
+    }
66
+
67
+    @Test
68
+    public void compareTo() {
69
+        Payment paypal = new PayPal(1, "Tia Mowry", "tia@mowry.com");
70
+        Payment check = new Check(1, "Tia Mowry", "00004551", "00004551");
71
+        Payment creditcard = new CreditCard(1, "Tia Mowry", "4551", 10, 2019);
72
+    }
73
+}

+ 51
- 0
src/test/java/com/zipcoder/payment/PayPalTest.java 查看文件

@@ -0,0 +1,51 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Test;
4
+
5
+import static org.junit.Assert.assertEquals;
6
+
7
+public class PayPalTest {
8
+    PayPal paypal = new PayPal();
9
+
10
+    @Test
11
+    public void testGetId(){
12
+        long expected = 123456789;
13
+        paypal.setId(expected);
14
+        long actual = paypal.getId();
15
+        assertEquals(expected, actual);
16
+    }
17
+
18
+    @Test
19
+    public void testPayerName(){
20
+        String expected = "Tia Mowry";
21
+        paypal.setPayerName(expected);
22
+        String actual = paypal.getPayerName();
23
+        assertEquals(expected, actual);
24
+    }
25
+
26
+    @Test
27
+    public void testEmail(){
28
+        String expected = "Tia@Mowry.com";
29
+        paypal.setEmail(expected);
30
+        String actual = paypal.getEmail();
31
+        assertEquals(expected, actual);
32
+    }
33
+
34
+    @Test
35
+    public void testShortDescription(){
36
+        String expected = "PayPal Tia Mowry tia@mowry.com";
37
+        String name = "Tia Mowry";
38
+        paypal.setPayerName(name);
39
+        String email = "tia@mowry.com";
40
+        paypal.setEmail(email);
41
+        String actual = paypal.getShortDescription();
42
+        assertEquals(expected, actual);
43
+    }
44
+
45
+    @Test
46
+    public void compareTo() {
47
+        Payment paypal = new PayPal(1, "Tia Mowry", "tia@mowry.com");
48
+        Payment check = new Check(1, "Tia Mowry", "00004551", "00004551");
49
+        Payment creditcard = new CreditCard(1, "Tia Mowry", "4551", 10, 2019);
50
+    }
51
+}

+ 51
- 0
src/test/java/com/zipcoder/payment/PaymentPresenterTest.java 查看文件

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

+ 16
- 0
src/test/java/com/zipcoder/payment/PaymentSortByPayerTest.java 查看文件

@@ -0,0 +1,16 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Test;
4
+
5
+import static org.junit.Assert.*;
6
+
7
+public class PaymentSortByPayerTest {
8
+
9
+    @Test
10
+    public void compare(){
11
+            Payment paypal = new PayPal(1, "Tia Mowry", "tia@mowry.com");
12
+            Payment check = new Check(1, "Tia Mowry", "00004551", "00004551");
13
+            Payment creditcard = new CreditCard(1, "Tia Mowry", "4551", 10, 2019);
14
+        }
15
+
16
+}