Rachelle 8 anni fa
parent
commit
960590b946

+ 8
- 0
pom.xml Vedi File

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

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

@@ -0,0 +1,57 @@
1
+package com.zipcoder.payment;
2
+
3
+public class Check implements Payment {
4
+
5
+    Long id;
6
+    String payerName;
7
+    String routingName;
8
+    String accountNumber;
9
+
10
+    public Check(){}
11
+
12
+    public Check(String payerName, String accountNumber){
13
+        this.payerName = payerName;
14
+        this.accountNumber = accountNumber;
15
+    }
16
+
17
+    public Long getID() {
18
+        return id;
19
+    }
20
+
21
+    public void setID(Long id) {
22
+        this.id = id;
23
+    }
24
+
25
+    public String getPayerName() {
26
+        return  payerName;
27
+    }
28
+
29
+    public void setPayerName(String payerName){
30
+        this.payerName = payerName;
31
+    }
32
+
33
+    public String getRoutingName() {
34
+        return routingName;
35
+    }
36
+
37
+    public void setRoutingName(String routingName) {
38
+        this.routingName = routingName;
39
+    }
40
+
41
+    public String getAccountNumber() {
42
+        return accountNumber;
43
+    }
44
+
45
+    public void setAccountNumber(String accountNumber) {
46
+        this.accountNumber = accountNumber;
47
+    }
48
+
49
+    public String getShortDescription() {
50
+        return ("Check " + getPayerName() + " ***" + getLastFourDigits());
51
+    }
52
+
53
+    public String getLastFourDigits(){
54
+        String lastFour = accountNumber.substring(accountNumber.length()-4);
55
+        return lastFour;
56
+    }
57
+}

+ 74
- 0
src/main/java/com/zipcoder/payment/CreditCard.java Vedi File

@@ -0,0 +1,74 @@
1
+package com.zipcoder.payment;
2
+
3
+public class CreditCard implements Payment {
4
+
5
+    Long id;
6
+    String payerName;
7
+    String number;
8
+    int expiredMonth;
9
+    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
+    public String getPayerName() {
29
+        return payerName;
30
+    }
31
+
32
+    public void setPayerName(String payerName) {
33
+        this.payerName = payerName;
34
+    }
35
+
36
+    public String getNumber() {
37
+        return number;
38
+    }
39
+
40
+    public void setNumber(String number) {
41
+        this.number = number;
42
+    }
43
+
44
+    public int getExpiredMonth() {
45
+        return expiredMonth;
46
+    }
47
+
48
+    public void setExpiredMonth(int expiredMonth) {
49
+        this.expiredMonth = expiredMonth;
50
+    }
51
+
52
+    public int getExpiredYear() {
53
+        return expiredYear;
54
+    }
55
+
56
+    public void setExpiredYear(int expiredYear) {
57
+        this.expiredYear = expiredYear;
58
+    }
59
+
60
+    public Long getID() {
61
+        return null;
62
+    }
63
+
64
+    public String getShortDescription() {
65
+        String result = "CC " + getPayerName() + " " + getLastFourDigits() + " " + getExpiredMonth() + "/" + getExpiredYear();
66
+        return result;
67
+    }
68
+
69
+    public String getLastFourDigits(){
70
+        String lastFour = number.substring(number.length()-4);
71
+        return lastFour;
72
+    }
73
+
74
+}

+ 42
- 0
src/main/java/com/zipcoder/payment/PayPal.java Vedi File

@@ -0,0 +1,42 @@
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(String payerName, String email){
11
+        this.payerName = payerName;
12
+        this.email = email;
13
+    }
14
+
15
+    public Long getID() {
16
+        return id;
17
+    }
18
+
19
+    public void setId(Long id) {
20
+        this.id = id;
21
+    }
22
+
23
+    public String getPayerName() {
24
+        return payerName;
25
+    }
26
+
27
+    public void setPayerName(String payerName) {
28
+        this.payerName = payerName;
29
+    }
30
+
31
+    public String getEmail() {
32
+        return email;
33
+    }
34
+
35
+    public void setEmail(String email) {
36
+        this.email = email;
37
+    }
38
+
39
+    public String getShortDescription() {
40
+        return ("Paypal " + getPayerName() + " " + email);
41
+    }
42
+}

+ 9
- 0
src/main/java/com/zipcoder/payment/Payment.java Vedi File

@@ -0,0 +1,9 @@
1
+package com.zipcoder.payment;
2
+
3
+public interface Payment {
4
+    Long getID();
5
+
6
+    String getPayerName();
7
+
8
+    String getShortDescription();
9
+}

+ 67
- 0
src/test/java/com/zipcoder/payment/CheckTest.java Vedi File

@@ -0,0 +1,67 @@
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 idGetterSetterTest(){
10
+        Check check = new Check();
11
+        check.setID(12345L);
12
+
13
+        Long expected = 12345L;
14
+
15
+        Assert.assertEquals(expected, check.getID());
16
+    }
17
+
18
+    @Test
19
+    public void payerNameGetterSetterTest(){
20
+        Check check = new Check();
21
+        check.setPayerName("John Jacob");
22
+
23
+        String expected = "John Jacob";
24
+
25
+        Assert.assertEquals(expected, check.getPayerName());
26
+    }
27
+
28
+    @Test
29
+    public void routingNumberGetterSetterTest(){
30
+        Check check = new Check();
31
+        check.setRoutingName("6789123");
32
+
33
+        String expected = "6789123";
34
+
35
+        Assert.assertEquals(expected, check.getRoutingName());
36
+    }
37
+
38
+    @Test
39
+    public void accountNumberGetterSetterTest(){
40
+        Check check = new Check();
41
+        check.setAccountNumber("234678");
42
+
43
+        String expected = "234678";
44
+
45
+        Assert.assertEquals(expected, check.getAccountNumber());
46
+    }
47
+
48
+    @Test
49
+    public void getShortDescriptionTest(){
50
+        Check check = new Check("John Jacob", "12345");
51
+
52
+        String expected = "Check John Jacob ***2345";
53
+
54
+        Assert.assertEquals(expected,check.getShortDescription());
55
+    }
56
+
57
+    @Test
58
+    public void getLastFourDigitsTest(){
59
+        Check check = new Check();
60
+
61
+        String expected = "3456";
62
+
63
+        check.setAccountNumber("1234567890123456");
64
+
65
+        Assert.assertEquals(expected,check.getLastFourDigits());
66
+    }
67
+}

+ 76
- 0
src/test/java/com/zipcoder/payment/CreditCardTest.java Vedi File

@@ -0,0 +1,76 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class CreditCardTest {
7
+    @Test
8
+    public void idGetterSetterTest(){
9
+        CreditCard creditCard = new CreditCard();
10
+        creditCard.setId(987654321L);
11
+
12
+        Long expected = 987654321L;
13
+
14
+        Assert.assertEquals(expected, creditCard.getID());
15
+    }
16
+
17
+    @Test
18
+    public void payerNameGetterSetterTest(){
19
+        CreditCard creditCard = new CreditCard();
20
+        creditCard.setPayerName("John Jacob");
21
+
22
+        String expected = "John Jacob";
23
+
24
+        Assert.assertEquals(expected, creditCard.getPayerName());
25
+    }
26
+
27
+    @Test
28
+    public void numberGetterSetterTest(){
29
+        CreditCard creditCard = new CreditCard();
30
+        creditCard.setNumber("1234567890123456");
31
+
32
+        String expected = "1234567890123456";
33
+
34
+        Assert.assertEquals(expected, creditCard.getNumber());
35
+    }
36
+
37
+    @Test
38
+    public void expiredMonthGetterSetterTest(){
39
+        CreditCard creditCard = new CreditCard();
40
+        creditCard.setExpiredMonth(12);
41
+
42
+        int expected = 12;
43
+
44
+        Assert.assertEquals(expected, creditCard.getExpiredMonth());
45
+    }
46
+
47
+    @Test
48
+    public void expiredYearGetterSetterTest(){
49
+        CreditCard creditCard = new CreditCard();
50
+        creditCard.setExpiredYear(2018);
51
+
52
+        int expected = 2018;
53
+
54
+        Assert.assertEquals(expected, creditCard.getExpiredYear());
55
+    }
56
+
57
+    @Test
58
+    public void getShortDescriptionTest(){
59
+        CreditCard creditCard = new CreditCard("John Jacob", "1234567890123456", 12, 2018);
60
+
61
+        String expected = "CC John Jacob 3456 12/2018";
62
+
63
+        Assert.assertEquals(expected,creditCard.getShortDescription());
64
+    }
65
+
66
+    @Test
67
+    public void getLastFourDigitsTest(){
68
+        CreditCard creditCard = new CreditCard();
69
+
70
+        String expected = "3456";
71
+
72
+        creditCard.setNumber("1234567890123456");
73
+
74
+        Assert.assertEquals(expected,creditCard.getLastFourDigits());
75
+    }
76
+}

+ 46
- 0
src/test/java/com/zipcoder/payment/PayPalTest.java Vedi File

@@ -0,0 +1,46 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class PayPalTest {
7
+
8
+    @Test
9
+    public void idGetterSetterTest(){
10
+        PayPal payPal = new PayPal();
11
+        payPal.setId(12345L);
12
+
13
+        Long expected = 12345L;
14
+
15
+        Assert.assertEquals(expected, payPal.getID());
16
+    }
17
+
18
+    @Test
19
+    public void payerNameGetterSetterTest(){
20
+        PayPal payPal = new PayPal();
21
+        payPal.setPayerName("John Jacob");
22
+
23
+        String expected = "John Jacob";
24
+
25
+        Assert.assertEquals(expected, payPal.getPayerName());
26
+    }
27
+
28
+    @Test
29
+    public void emailGetterSetterTest(){
30
+        PayPal payPal = new PayPal();
31
+        payPal.setEmail("John.Jacob@fakeemail.com");
32
+
33
+        String expected = "John.Jacob@fakeemail.com";
34
+
35
+        Assert.assertEquals(expected, payPal.getEmail());
36
+    }
37
+
38
+    @Test
39
+    public void getShortDescriptionTest(){
40
+        PayPal payPal = new PayPal("John Jacob", "john.jacob@fakeemail.com");
41
+
42
+        String expected = "Paypal John Jacob john.jacob@fakeemail.com";
43
+
44
+        Assert.assertEquals(expected, payPal.getShortDescription());
45
+    }
46
+}