瀏覽代碼

getting closer

Kris Blassingame 8 年之前
父節點
當前提交
b0a96d8673

+ 8
- 0
pom.xml 查看文件

7
     <groupId>com.zipcoder</groupId>
7
     <groupId>com.zipcoder</groupId>
8
     <artifactId>payment</artifactId>
8
     <artifactId>payment</artifactId>
9
     <version>1.0-SNAPSHOT</version>
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
 </project>
20
 </project>

二進制
src/main/java/com/zipcoder/.DS_Store 查看文件


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

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

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

1
+package com.zipcoder.payment;
2
+
3
+public interface Payment {
4
+
5
+    long getId();
6
+
7
+    String getPayerName();
8
+
9
+    String getShortDescription();
10
+
11
+
12
+}

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

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
+
9
+    @Test
10
+    public void getIdTest() {
11
+        CreditCard creditCard = new CreditCard();
12
+        creditCard.setId(1234L);
13
+
14
+        long expected = 1234L;
15
+        long actual = creditCard.getId();
16
+
17
+        assertEquals(expected, actual);
18
+    }
19
+
20
+
21
+    @Test
22
+    public void getPayerNameTest() {
23
+        CreditCard creditCard = new CreditCard();
24
+        creditCard.setPayerName("Kris Blassingame");
25
+
26
+        String expected = "Kris Blassingame";
27
+        String actual = creditCard.getPayerName();
28
+
29
+        assertEquals(expected, actual);
30
+    }
31
+
32
+    @Test
33
+    public void getNumberTest(){
34
+        CreditCard creditCard = new CreditCard();
35
+        creditCard.setNumber("1234567890123456");
36
+
37
+        String expected = "1234567890123456";
38
+        String actual = creditCard.getNumber();
39
+
40
+        assertEquals(expected, actual);
41
+    }
42
+
43
+    @Test
44
+    public void getExpiredMonthTest(){
45
+        CreditCard creditCard = new CreditCard();
46
+        creditCard.setExpiredMonth(06);
47
+
48
+        int expected = 06;
49
+        int actual = creditCard.getExpiredMonth();
50
+
51
+        assertEquals(expected, actual);
52
+    }
53
+
54
+    @Test
55
+    public void getExpiredYearTest(){
56
+        CreditCard creditCard = new CreditCard();
57
+        creditCard.setExpiredYear(2020);
58
+
59
+        int expected = 2020;
60
+        int actual = creditCard.getExpiredYear();
61
+
62
+        assertEquals(expected, actual);
63
+    }
64
+
65
+    @Test
66
+    public void getShortDescriptionTest(){
67
+        CreditCard creditCard = new CreditCard("Kris Blassingame", "1234567890987654", 6, 2020);
68
+
69
+        String expected = "CC Kris Blassingame 7654 6/2020";
70
+        String actual = creditCard.getShortDescription();
71
+
72
+        assertEquals(expected, actual);
73
+    }
74
+
75
+    @Test
76
+    public void getLastFourDigitsTest(){
77
+        CreditCard creditCard = new CreditCard();
78
+
79
+        String expected = "7654";
80
+        creditCard.setNumber("123456789098 7654");
81
+
82
+        assertEquals(expected, creditCard.getLastFourDigits());
83
+    }
84
+}