nafis nibir 8 anni fa
parent
commit
f16ff8ef56

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

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

@@ -0,0 +1,66 @@
1
+package com.zipcoder.payment;
2
+
3
+public class Check implements Payment{
4
+
5
+    Long id;
6
+    String payerName;
7
+    String routingNumber;
8
+    String accountNumber;
9
+
10
+    public Check(){
11
+
12
+    }
13
+
14
+    public Check(String payerName, String routingNumber, String accountNumber){
15
+        this.payerName = payerName;
16
+        this.routingNumber = routingNumber;
17
+        this.accountNumber = accountNumber;
18
+    }
19
+    public String getRoutingNumber() {
20
+        return routingNumber;
21
+    }
22
+
23
+    public void setRoutingNumber(String routingNumber) {
24
+        this.routingNumber = routingNumber;
25
+    }
26
+
27
+
28
+    public String getAccountNumber() {
29
+        return accountNumber;
30
+    }
31
+
32
+    public void setAccountNumber(String accountNumber) {
33
+        this.accountNumber = accountNumber;
34
+    }
35
+
36
+    public Long getId(){
37
+        return id;
38
+    }
39
+
40
+    public void setId(Long id){
41
+        this.id = id;
42
+    }
43
+
44
+    public String getPayerName(){
45
+        return payerName;
46
+    }
47
+
48
+    public void setPayerName(String payerName) {
49
+        this.payerName = payerName;
50
+    }
51
+
52
+    public String getShortDescription(){
53
+        String result = "Check " + getPayerName() + " ***" + lastFour(getAccountNumber());
54
+        return result;
55
+    }
56
+
57
+    public String lastFour(String number){
58
+        return number.substring(number.length()-4);
59
+    }
60
+
61
+    public int compareTo(Payment o) {
62
+        return this.getShortDescription().compareTo(o.getShortDescription());
63
+    }
64
+
65
+
66
+}

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

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

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

@@ -0,0 +1,52 @@
1
+package com.zipcoder.payment;
2
+
3
+public class PayPal implements Payment {
4
+
5
+    Long id;
6
+    String payerName;
7
+    String email;
8
+
9
+    public PayPal(){
10
+
11
+    }
12
+
13
+    public PayPal(String payerName, String email){
14
+        this.payerName = payerName;
15
+        this.email = email;
16
+    }
17
+
18
+    public String getEmail() {
19
+        return email;
20
+    }
21
+
22
+    public void setEmail(String email) {
23
+        this.email = email;
24
+    }
25
+
26
+    public Long getId(){
27
+        return id;
28
+    }
29
+
30
+    public void setId(Long id){
31
+        this.id = id;
32
+    }
33
+
34
+
35
+    public String getPayerName(){
36
+        return payerName;
37
+    }
38
+
39
+    public void setPayerName(String payerName) {
40
+        this.payerName = payerName;
41
+    }
42
+
43
+    public String getShortDescription() {
44
+        String result = "Paypal " + getPayerName() + " " + getEmail();
45
+        return result;
46
+    }
47
+
48
+    public int compareTo(Payment o) {
49
+        return this.getShortDescription().compareTo(o.getShortDescription());
50
+    }
51
+
52
+}

+ 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 extends Comparable<Payment>{
4
+    Long getId();
5
+    String getPayerName();
6
+    String getShortDescription();
7
+
8
+
9
+}

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

@@ -0,0 +1,82 @@
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 test = new Check();
11
+
12
+
13
+        Long expected = 888L;
14
+        test.setId(888L);
15
+        Long actual = test.getId();
16
+        Assert.assertEquals(expected, actual);
17
+    }
18
+
19
+    @Test
20
+    public void payerNameGetterSetterTest(){
21
+        Check test = new Check();
22
+
23
+
24
+        String expected = "Nafis";
25
+        test.setPayerName("Nafis");
26
+        String actual = test.getPayerName();
27
+        Assert.assertEquals(expected, actual);
28
+    }
29
+
30
+    @Test
31
+    public void routingNumberGetterSetterTest(){
32
+        Check test = new Check();
33
+
34
+
35
+        String expected = "123456789";
36
+        test.setRoutingNumber("123456789");
37
+        String actual = test.getRoutingNumber();
38
+        Assert.assertEquals(expected, actual);
39
+    }
40
+
41
+    @Test
42
+    public void accountNumberGetterSetterTest(){
43
+        Check test = new Check();
44
+
45
+
46
+        String expected = "1234567890";
47
+        test.setAccountNumber("1234567890");
48
+        String actual = test.getAccountNumber();
49
+        Assert.assertEquals(expected, actual);
50
+    }
51
+
52
+    @Test
53
+    public void lastFourTest(){
54
+        Check test = new Check();
55
+
56
+        String expected = "1234";
57
+        String actual = test.lastFour("1111222233331234");
58
+        Assert.assertEquals(expected, actual);
59
+
60
+    }
61
+
62
+    @Test
63
+    public void getShortDescriptionTest(){
64
+        Check test = new Check("Nafis", "123456789", "1234567890");
65
+
66
+        String expected = "Check Nafis ***7890";
67
+        String actual = test.getShortDescription();
68
+        Assert.assertEquals(expected, actual);
69
+    }
70
+
71
+    @Test
72
+    public void compareToTest(){
73
+        CreditCard test1 = new CreditCard("Nafis", "1111222233331234", 9, 2018);
74
+        Check test2 = new Check("Nafis", "123456789", "1234567890");
75
+
76
+        Assert.assertTrue(test1.compareTo(test2) < 0);
77
+
78
+    }
79
+
80
+
81
+
82
+}

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

@@ -0,0 +1,102 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+import static junit.framework.TestCase.assertTrue;
7
+
8
+public class CreditCardTest {
9
+
10
+    @Test
11
+    public void idGetterSetterTest(){
12
+        CreditCard test = new CreditCard();
13
+
14
+
15
+        Long expected = 888L;
16
+        test.setId(888L);
17
+        Long actual = test.getId();
18
+        Assert.assertEquals(expected, actual);
19
+    }
20
+
21
+    @Test
22
+    public void payerNameGetterSetterTest(){
23
+        CreditCard test = new CreditCard();
24
+
25
+
26
+        String expected = "Nafis";
27
+        test.setPayerName("Nafis");
28
+        String actual = test.getPayerName();
29
+        Assert.assertEquals(expected, actual);
30
+    }
31
+
32
+    @Test
33
+    public void numberGetterSetterTest(){
34
+        CreditCard test = new CreditCard();
35
+
36
+
37
+        String expected = "1234123412341234";
38
+        test.setNumber("1234123412341234");
39
+        String actual = test.getNumber();
40
+        Assert.assertEquals(expected, actual);
41
+    }
42
+
43
+    @Test
44
+    public void expiredMonthGetterSetterTest(){
45
+        CreditCard test = new CreditCard();
46
+
47
+
48
+        int expected = 9;
49
+        test.setExpiredMonth(9);
50
+        int actual = test.getExpiredMonth();
51
+        Assert.assertEquals(expected, actual);
52
+    }
53
+
54
+    @Test
55
+    public void expiredYearGetterSetterTest(){
56
+        CreditCard test = new CreditCard();
57
+
58
+
59
+        int expected = 2018;
60
+        test.setExpiredYear(2018);
61
+        int actual = test.getExpiredYear();
62
+        Assert.assertEquals(expected, actual);
63
+    }
64
+
65
+    @Test
66
+    public void getShortDescriptionTest(){
67
+        CreditCard test = new CreditCard("Nafis", "1111222233331234", 9, 2018);
68
+
69
+        String expected = "CC Nafis 1234 9/2018";
70
+        String actual = test.getShortDescription();
71
+        Assert.assertEquals(expected, actual);
72
+    }
73
+
74
+    @Test
75
+    public void lastFourTest(){
76
+        CreditCard test = new CreditCard();
77
+
78
+        String expected = "1234";
79
+        String actual = test.lastFour("1111222233331234");
80
+        Assert.assertEquals(expected, actual);
81
+
82
+    }
83
+
84
+    @Test
85
+    public void constructorTest(){
86
+        CreditCard test = new CreditCard("Nafis", "1111222233331234", 9, 2018);
87
+
88
+        String expected = "CC Nafis 1234 9/2018";
89
+        String actual = test.getShortDescription();
90
+        Assert.assertEquals(expected, actual);
91
+    }
92
+
93
+    @Test
94
+    public void compareToTest(){
95
+        CreditCard test1 = new CreditCard("Nafis", "1111222233331234", 9, 2018);
96
+        PayPal test2 = new PayPal("Nafis", "nafisnibir@gmail.com");
97
+
98
+        Assert.assertTrue(test1.compareTo(test2) < 0);
99
+
100
+    }
101
+
102
+}

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

@@ -0,0 +1,51 @@
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 test = new PayPal();
11
+
12
+
13
+        Long expected = 888L;
14
+        test.setId(888L);
15
+        Long actual = test.getId();
16
+        Assert.assertEquals(expected, actual);
17
+    }
18
+
19
+    @Test
20
+    public void payerNameGetterSetterTest(){
21
+        PayPal test = new PayPal();
22
+
23
+
24
+        String expected = "Nafis";
25
+        test.setPayerName("Nafis");
26
+        String actual = test.getPayerName();
27
+        Assert.assertEquals(expected, actual);
28
+    }
29
+
30
+    @Test
31
+    public void emailetterSetterTest(){
32
+        PayPal test = new PayPal();
33
+
34
+
35
+        String expected = "nafisnibir@gmail.com";
36
+        test.setEmail("nafisnibir@gmail.com");
37
+        String actual = test.getEmail();
38
+        Assert.assertEquals(expected, actual);
39
+    }
40
+
41
+    @Test
42
+    public void getShortDescriptionTest(){
43
+        PayPal test = new PayPal("Nafis", "nafisnibir@gmail.com");
44
+
45
+        String expected = "Paypal Nafis nafisnibir@gmail.com";
46
+        String actual = test.getShortDescription();
47
+        Assert.assertEquals(expected, actual);
48
+    }
49
+
50
+
51
+}