Browse Source

lab with min

Jamez-s 8 years ago
parent
commit
d4e628ed52

BIN
.DS_Store View File


BIN
src/.DS_Store View File


BIN
src/main/.DS_Store View File


BIN
src/main/java/.DS_Store View File


BIN
src/main/java/com/.DS_Store View File


BIN
src/main/java/com/zipcoder/.DS_Store View File


+ 57
- 0
src/main/java/com/zipcoder/payment/Check.java View File

@@ -0,0 +1,57 @@
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(Long id, String payerName, String routingNumber, String accountNumber) {
11
+
12
+        this.id = id;
13
+        this.payerName = payerName;
14
+        this.routingNumber = routingNumber;
15
+        this.accountNumber = accountNumber;
16
+    }
17
+
18
+    public String getRoutingNumber() {
19
+        return routingNumber;
20
+    }
21
+
22
+    public void setRoutingNumber(String routingNumber) {
23
+        this.routingNumber = routingNumber;
24
+    }
25
+
26
+    public String getAccountNumber() {
27
+        return accountNumber;
28
+    }
29
+
30
+    public void setAccountNumber(String accountNumber) {
31
+        this.accountNumber = accountNumber;
32
+    }
33
+
34
+    public Long getId() {
35
+        return id;
36
+    }
37
+
38
+    public void setId(Long id) {
39
+        this.id = id;
40
+    }
41
+
42
+    public String getPayerName() {
43
+        return payerName;
44
+    }
45
+
46
+    public void setPayerName(String payerName) {
47
+        this.payerName = payerName;
48
+    }
49
+
50
+    public String getShortDescription() {
51
+        return "Check " + payerName + " ***" + accountNumber.substring(accountNumber.length() - 4, accountNumber.length());
52
+    }
53
+
54
+    public int compareTo(Payment o) {
55
+        return this.id.compareTo(o.getId());
56
+    }
57
+}

+ 75
- 0
src/main/java/com/zipcoder/payment/CreditCard.java View File

@@ -0,0 +1,75 @@
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
+
14
+    public CreditCard(Long id, String payerName, String number, int expiredMonth, int expiredYear) {
15
+        this.id = id;
16
+        this.payerName = payerName;
17
+        this.number = number;
18
+        this.expiredMonth = expiredMonth;
19
+        this.expiredYear = expiredYear;
20
+    }
21
+
22
+    public int getExpiredYear() {
23
+        return expiredYear;
24
+    }
25
+
26
+    public void setExpiredYear(int expiredYear) {
27
+        this.expiredYear = expiredYear;
28
+    }
29
+
30
+    public String getNumber() {
31
+        return number;
32
+    }
33
+
34
+    public void setNumber(String number) {
35
+        this.number = number;
36
+    }
37
+
38
+    public int getExpiredMonth() {
39
+        return expiredMonth;
40
+    }
41
+
42
+    public void setExpiredMonth(int expiredMonth) {
43
+        this.expiredMonth = expiredMonth;
44
+    }
45
+
46
+    public Long getId() {
47
+        return id;
48
+    }
49
+
50
+    public void setId(Long id) {
51
+        this.id = id;
52
+    }
53
+
54
+    public String getPayerName() {
55
+        return payerName;
56
+    }
57
+
58
+    public void setPayerName(String payerName) {
59
+        this.payerName = payerName;
60
+    }
61
+
62
+    public String getShortDescription() {
63
+        String lastFourDigitsOfNumber = number.substring(number.length() - 4, number.length());
64
+        String expiredMonthStringValue = String.valueOf(expiredMonth);
65
+        if (expiredMonth < 10) {
66
+            expiredMonthStringValue = "0" + expiredMonthStringValue;
67
+        }
68
+        return "CC " + payerName + " " + lastFourDigitsOfNumber + " " + expiredMonthStringValue + "/" + expiredYear;
69
+    }
70
+
71
+    public int compareTo(Payment o) {
72
+        return this.id.compareTo(o.getId());
73
+    }
74
+
75
+}

+ 11
- 0
src/main/java/com/zipcoder/payment/Payment.java View File

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

+ 28
- 0
src/main/java/com/zipcoder/payment/PaymentPresenter.java View File

@@ -1,6 +1,34 @@
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[] payments) {
9
+
10
+        Arrays.sort(payments, new PaymentSortByShortDescription());
11
+
12
+        return createString(payments);
13
+    }
14
+
15
+    public String toStringByPayerName(Payment[] payments) {
16
+        Arrays.sort(payments, new PaymentSortByPayer());
17
+
18
+        return createString(payments);
19
+    }
20
+
21
+    public String toStringById(Payment[] payments) {
22
+        Arrays.sort(payments);
23
+
24
+        return createString(payments);
25
+    }
26
+
27
+    private String createString(Payment[] payments) {
28
+        String retVal = "";
29
+        for (Payment payment : payments) {
30
+            retVal += payment.getShortDescription() + "\n";
31
+        }
32
+        return retVal;
33
+    }
6 34
 }

+ 10
- 0
src/main/java/com/zipcoder/payment/PaymentSortByPayer.java View File

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

+ 9
- 0
src/main/java/com/zipcoder/payment/PaymentSortByShortDescription.java View File

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

+ 35
- 0
src/main/java/com/zipcoder/payment/Paypal.java View File

@@ -0,0 +1,35 @@
1
+package com.zipcoder.payment;
2
+
3
+public class Paypal implements Payment {
4
+
5
+    private Long id;
6
+    private String payerName;
7
+    private String email;
8
+
9
+    public Paypal(Long id, String payerName, String email) {
10
+
11
+        this.id = id;
12
+        this.payerName = payerName;
13
+        this.email = email;
14
+    }
15
+
16
+    public Long getId() {
17
+        return id;
18
+    }
19
+
20
+    public void setId(Long id) {
21
+        this.id = id;
22
+    }
23
+
24
+    public String getPayerName() {
25
+        return payerName;
26
+    }
27
+
28
+    public String getShortDescription() {
29
+        return "Paypal " + payerName + " " + email;
30
+    }
31
+
32
+    public int compareTo(Payment o) {
33
+        return this.id.compareTo(o.getId());
34
+    }
35
+}

BIN
src/test/.DS_Store View File


+ 20
- 0
src/test/java/com/zipcoder/payment/CheckTest.java View File

@@ -0,0 +1,20 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class CheckTest {
7
+
8
+    @Test
9
+    public void getShortDescriptionTest() {
10
+        // Arrange
11
+        Check check = new Check(81L, "Tia Mowry", "11432543", "134344551");
12
+        String expected = "Check Tia Mowry ***4551";
13
+
14
+        // Act
15
+        String actual = check.getShortDescription();
16
+
17
+        // Assert
18
+        Assert.assertEquals(expected, actual);
19
+    }
20
+}

+ 103
- 0
src/test/java/com/zipcoder/payment/CreditCardTest.java View File

@@ -0,0 +1,103 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class CreditCardTest {
7
+
8
+    @Test
9
+    public void idTest() {
10
+        // Arrange
11
+        CreditCard creditCard = new CreditCard();
12
+        Long expectedId = 100L;
13
+        creditCard.setId(expectedId);
14
+
15
+        // Act
16
+        Long actualId = creditCard.getId();
17
+
18
+        // Assert
19
+        Assert.assertEquals(expectedId, actualId);
20
+    }
21
+
22
+    @Test
23
+    public void payerNameTest() {
24
+        // Arrange
25
+        CreditCard creditCard = new CreditCard();
26
+        String expectedPayerName = "Joe";
27
+        creditCard.setPayerName(expectedPayerName);
28
+
29
+        // Act
30
+        String actualPayerName = creditCard.getPayerName();
31
+
32
+        // Assert
33
+        Assert.assertEquals(expectedPayerName, actualPayerName);
34
+    }
35
+
36
+    @Test
37
+    public void numberTest() {
38
+        // Arrange
39
+        CreditCard creditCard = new CreditCard();
40
+        String expectedNumber = "12345";
41
+        creditCard.setNumber(expectedNumber);
42
+
43
+        // Act
44
+        String actualNumber = creditCard.getNumber();
45
+
46
+        // Assert
47
+        Assert.assertEquals(expectedNumber, actualNumber);
48
+    }
49
+
50
+    @Test
51
+    public void expiredMonthTest() {
52
+        // Arrange
53
+        CreditCard creditCard = new CreditCard();
54
+        int expectedExpiredMonth = 2;
55
+        creditCard.setExpiredMonth(expectedExpiredMonth);
56
+
57
+        // Act
58
+        int actualExpiredMonth = creditCard.getExpiredMonth();
59
+
60
+        // Assert
61
+        Assert.assertEquals(expectedExpiredMonth, actualExpiredMonth);
62
+    }
63
+
64
+    @Test
65
+    public void expiredYearTest() {
66
+        // Arrange
67
+        CreditCard creditCard = new CreditCard();
68
+        int expectedExpiredYear = 2019;
69
+        creditCard.setExpiredYear(expectedExpiredYear);
70
+
71
+        // Act
72
+        int actualExpiredYear = creditCard.getExpiredYear();
73
+
74
+        // Assert
75
+        Assert.assertEquals(expectedExpiredYear, actualExpiredYear);
76
+    }
77
+
78
+    @Test
79
+    public void getShortDescription_DoubleDigitMonth_ShouldReturnShortDescription() {
80
+        // Arrange
81
+        CreditCard creditCard = new CreditCard(284914091L, "John Doe", "1234567890123456", 11, 2001);
82
+        String expectedShortDescription = "CC John Doe 3456 11/2001";
83
+
84
+        // Act
85
+        String actualShortDescription = creditCard.getShortDescription();
86
+
87
+        // Assert
88
+        Assert.assertEquals(expectedShortDescription, actualShortDescription);
89
+    }
90
+
91
+    @Test
92
+    public void getShortDescription_SingleDigitMonth_ShouldReturnShortDescription() {
93
+        // Arrange
94
+        CreditCard creditCard = new CreditCard(284914091L, "John Doe", "1234567890123456", 1, 2001);
95
+        String expectedShortDescription = "CC John Doe 3456 01/2001";
96
+
97
+        // Act
98
+        String actualShortDescription = creditCard.getShortDescription();
99
+
100
+        // Assert
101
+        Assert.assertEquals(expectedShortDescription, actualShortDescription);
102
+    }
103
+}

+ 0
- 4
src/test/java/com/zipcoder/payment/PaymentPresenterTest.java View File

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

+ 20
- 0
src/test/java/com/zipcoder/payment/PaypalTests.java View File

@@ -0,0 +1,20 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class PaypalTests {
7
+
8
+    @Test
9
+    public void getShortDescriptionTest() {
10
+        // Arrange
11
+        Paypal paypal = new Paypal(100L, "Tia Mowry", "tia@mowry.com");
12
+        String expectedShortDescription = "Paypal Tia Mowry tia@mowry.com";
13
+
14
+        // Act
15
+        String actualShortDescription = paypal.getShortDescription();
16
+
17
+        // Assert
18
+        Assert.assertEquals(expectedShortDescription, actualShortDescription);
19
+    }
20
+}