Trinh Tong 7 年 前
コミット
c70f477b8b

+ 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>4.12</version>
15
+            <scope>test</scope>
16
+        </dependency>
17
+    </dependencies>
10 18
     <properties>
11 19
         <maven.compiler.source>1.8</maven.compiler.source>
12 20
         <maven.compiler.target>1.8</maven.compiler.target>

+ 56
- 0
src/main/java/com/zipcoder/payment/Check.java ファイルの表示

@@ -0,0 +1,56 @@
1
+package com.zipcoder.payment;
2
+
3
+public class Check implements Payment {
4
+    private long id;
5
+
6
+    private String payerName;
7
+    private String routingNumber;
8
+    private String accountNumber;
9
+
10
+    public Check() {
11
+        id = 0;
12
+        payerName = null;
13
+        routingNumber = null;
14
+        accountNumber = null;
15
+
16
+    }
17
+
18
+    @Override
19
+    public long getId() {
20
+        return this.id;
21
+    }
22
+
23
+    public void setPayerName(String payerName) {
24
+        this.payerName = payerName;
25
+    }
26
+
27
+    public String getRoutingNumber() {
28
+        return routingNumber;
29
+    }
30
+
31
+    public void setRoutingNumber(String routingNumber) {
32
+        this.routingNumber = routingNumber;
33
+    }
34
+
35
+    public String getAccountNumber() {
36
+        return accountNumber;
37
+    }
38
+
39
+    public void setAccountNumber(String accountNumber) {
40
+        this.accountNumber = accountNumber;
41
+    }
42
+
43
+    @Override
44
+    public String getPayerName() {
45
+        return this.payerName;
46
+    }
47
+
48
+    @Override
49
+    public String getShortDescription() {
50
+        return null;
51
+    }
52
+
53
+    public void setId(long l) {
54
+        this.id = l;
55
+    }
56
+}

+ 67
- 1
src/main/java/com/zipcoder/payment/CreditCard.java ファイルの表示

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

+ 1
- 1
src/main/java/com/zipcoder/payment/Payment.java ファイルの表示

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

+ 26
- 0
src/test/java/com/zipcoder/payment/CheckTest.java ファイルの表示

@@ -0,0 +1,26 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
7
+public class CheckTest {
8
+    private Check testCheck;
9
+
10
+    @Before
11
+    public void setUp() {
12
+        testCheck = new Check();
13
+        testCheck.setId(12345678910L);
14
+        testCheck.setPayerName("Biggie");
15
+        testCheck.setRoutingNumber("623852453");
16
+        testCheck.setAccountNumber("1234567");
17
+    }
18
+
19
+    @Test
20
+    public void testId() {
21
+        long expectedId = 12345678910L;
22
+        testCheck.setId(12345678910L);
23
+        Assert.assertEquals(expectedId, testCheck.getId());
24
+    }
25
+
26
+}

+ 54
- 0
src/test/java/com/zipcoder/payment/CreditcardTest.java ファイルの表示

@@ -1,4 +1,58 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
3 7
 public class CreditcardTest {
8
+    CreditCard cc;
9
+
10
+    @Before
11
+    public void setUp() {
12
+        cc = new CreditCard();
13
+
14
+        cc.setPayerName("Jared");
15
+        cc.setExpiredMonth(12);
16
+        cc.setExpiredyear(2020);
17
+        cc.setNumber("4539 1889 1071 9389");
18
+    }
19
+
20
+    @Test
21
+    public void testLongId() {
22
+        long expectedId =  1234567894321L;
23
+        cc.setId(1234567894321L);
24
+        Assert.assertEquals(expectedId, cc.getId());
25
+    }
26
+
27
+    @Test
28
+    public void testPayerName() {
29
+        String expectedName =  "Jared";
30
+        Assert.assertEquals(expectedName, cc.getPayerName());
31
+    }
32
+
33
+    @Test
34
+    public void testExpirationMonth() {
35
+        int expectedExpMonth = 12;
36
+        Assert.assertEquals(expectedExpMonth, cc.getExpiredMonth());
37
+    }
38
+
39
+    @Test
40
+    public void testExpirationYear() {
41
+        int expectedExpYear = 2020;
42
+        Assert.assertEquals(expectedExpYear, cc.getExpiredyear());
43
+    }
44
+
45
+    @Test
46
+    public void testNumFull() {
47
+        String expectedCCNum = "4539 1889 1071 9389";
48
+        Assert.assertEquals(expectedCCNum, cc.getNumber());
49
+    }
50
+
51
+    @Test
52
+    public void testShortDesc() {
53
+        String expectedCC = "CC [Jared] [9389] [12]/[2020]";
54
+        Assert.assertEquals(expectedCC, cc.getShortDescription());
55
+    }
56
+
57
+
4 58
 }