Kaynağa Gözat

TG complete

Tennessee Gibbs 8 yıl önce
ebeveyn
işleme
5d4928e455

+ 30
- 0
pom.xml Dosyayı Görüntüle

@@ -7,6 +7,36 @@
7 7
     <groupId>com.zipcoder</groupId>
8 8
     <artifactId>payment</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10
+    <properties>
11
+        <maven.compiler.source>1.8</maven.compiler.source>
12
+        <maven.compiler.target>1.8</maven.compiler.target>
13
+    </properties>
14
+    <dependencies>
15
+        <dependency>
16
+            <groupId>junit</groupId>
17
+            <artifactId>junit</artifactId>
18
+            <version>RELEASE</version>
19
+            <scope>test</scope>
20
+        </dependency>
21
+        <dependency>
22
+            <groupId>org.testng</groupId>
23
+            <artifactId>testng</artifactId>
24
+            <version>RELEASE</version>
25
+            <scope>compile</scope>
26
+        </dependency>
27
+        <dependency>
28
+            <groupId>org.junit.jupiter</groupId>
29
+            <artifactId>junit-jupiter-api</artifactId>
30
+            <version>RELEASE</version>
31
+            <scope>compile</scope>
32
+        </dependency>
33
+        <dependency>
34
+            <groupId>junit</groupId>
35
+            <artifactId>junit</artifactId>
36
+            <version>RELEASE</version>
37
+            <scope>compile</scope>
38
+        </dependency>
39
+    </dependencies>
10 40
 
11 41
 
12 42
 </project>

+ 67
- 0
src/main/java/Check.java Dosyayı Görüntüle

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

+ 78
- 0
src/main/java/CreditCard.java Dosyayı Görüntüle

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

+ 59
- 0
src/main/java/PayPal.java Dosyayı Görüntüle

@@ -0,0 +1,59 @@
1
+public class PayPal implements Payment {
2
+    long id;
3
+    String payerName;
4
+    String email;
5
+
6
+    public PayPal(long l, String tia_mowry, String s){
7
+        this.id = l;
8
+        this.payerName = tia_mowry;
9
+        this.email = s;
10
+    }
11
+
12
+    public PayPal(long id, String payerName, String number, String email){}
13
+
14
+
15
+
16
+    public void setId(long id) {
17
+        this.id = id;
18
+    }
19
+
20
+    public long getId() {
21
+        return id;
22
+    }
23
+
24
+
25
+    public void setPayerName(String payerName){
26
+        this.payerName = payerName;
27
+
28
+    }
29
+
30
+    public String getPayerName() {
31
+        return this.payerName;
32
+
33
+    }
34
+
35
+    public void setEmail(String email) {
36
+        this.email = email;
37
+    }
38
+
39
+    public  String getEmail(){
40
+
41
+        return this.email;
42
+    }
43
+
44
+    public String getShortDescription() {
45
+        return "PayPal " + getPayerName() + " " + getEmail();
46
+    }
47
+
48
+
49
+    public int compareTo(Payment o) {
50
+            PayPal payPal = new PayPal(4L, "Tia Mowry", "tia@mowry.com");
51
+            if ( this.getShortDescription().compareTo(o.getShortDescription()) == 0 )
52
+            {return 0;}
53
+            else if ( this.getShortDescription().compareTo(o.getShortDescription()) < 0 ){
54
+                return 1;}
55
+            else return -1;
56
+    }
57
+
58
+
59
+}

+ 14
- 0
src/main/java/Payment.java Dosyayı Görüntüle

@@ -0,0 +1,14 @@
1
+public interface Payment extends Comparable<Payment>{
2
+
3
+    public long getId();
4
+
5
+    public String getPayerName();
6
+
7
+    public String getShortDescription();
8
+
9
+
10
+
11
+
12
+
13
+
14
+}

+ 32
- 0
src/main/java/PaymentPresenter.java Dosyayı Görüntüle

@@ -0,0 +1,32 @@
1
+import java.util.ArrayList;
2
+import java.util.Arrays;
3
+
4
+public class PaymentPresenter {
5
+
6
+    public String toString(Payment[] payments) {
7
+        Arrays.sort(payments);
8
+
9
+        StringBuilder builder = new StringBuilder();
10
+        for (Payment o : payments) builder.append(o.getShortDescription() + "\n");
11
+        return builder.toString();
12
+    }
13
+
14
+    public String toStringByPayerName(Payment[] payments) {
15
+        Arrays.sort(payments, new PaymentSortByPayer());
16
+
17
+        StringBuilder builder = new StringBuilder();
18
+        for (Payment o : payments) builder.append(o.getShortDescription() + "\n");
19
+        return builder.toString();
20
+    }
21
+
22
+    public String toStringById(Payment[] payments) {
23
+        Arrays.sort(payments, (Payment o1, Payment o2) -> (Long.compare(o1.getId(), o2.getId())));
24
+
25
+        StringBuilder builder = new StringBuilder();
26
+        for (Payment o : payments) builder.append(o.getShortDescription() + "\n");
27
+        return builder.toString();
28
+    }
29
+
30
+}
31
+
32
+

+ 9
- 0
src/main/java/PaymentSortByPayer.java Dosyayı Görüntüle

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

+ 0
- 6
src/main/java/com/zipcoder/payment/PaymentPresenter.java Dosyayı Görüntüle

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

+ 73
- 0
src/test/java/CheckTest.java Dosyayı Görüntüle

@@ -0,0 +1,73 @@
1
+import org.junit.Test;
2
+
3
+import static org.junit.Assert.*;
4
+
5
+public class CheckTest {
6
+
7
+    Check check = new Check();
8
+    PayPal payPal = new PayPal(4L, "Tia Mowry", "tia@mowry.com");
9
+    CreditCard credit = new CreditCard();
10
+
11
+
12
+    @Test
13
+    public void getPayerName() {
14
+        Check check = new Check();
15
+
16
+        String expectedPayerName = "Tia Mowry";
17
+        check.setPayerName(expectedPayerName);
18
+        String actualPayerName = check.getPayerName();
19
+
20
+        assertEquals(expectedPayerName, actualPayerName);
21
+    }
22
+
23
+    @Test
24
+    public void getRoutingNumber() {
25
+        String expectedRoutingNumber = "445994551";
26
+        check.setRoutingNumber(expectedRoutingNumber);
27
+
28
+        String actualRoutingNumber = check.getRoutingNumber();
29
+
30
+        assertEquals(expectedRoutingNumber, actualRoutingNumber);
31
+}
32
+    @Test
33
+    public void getAccountNumber() {
34
+
35
+        String expectedAccountNumber = "***4551";
36
+        check.setAccountNumber(expectedAccountNumber);
37
+        String actualAccountNumber = check.getAccountNumber();
38
+
39
+        assertEquals(expectedAccountNumber, actualAccountNumber);
40
+    }
41
+
42
+    @Test
43
+    public void compareToCredit(){
44
+
45
+        int expected = 1;
46
+
47
+        int actual = check.compareTo(credit);
48
+
49
+        assertEquals(expected, actual);
50
+    }
51
+
52
+    @Test
53
+    public void compareToPayPal(){
54
+
55
+        int expected = -1;
56
+
57
+        int actual = check.compareTo(payPal);
58
+
59
+        assertEquals(expected, actual);
60
+    }
61
+
62
+    @Test
63
+    public void compareToCheck() {
64
+
65
+        int expected = 0;
66
+
67
+        int actual = check.compareTo(check);
68
+
69
+        assertEquals(expected, actual);
70
+    }
71
+
72
+
73
+}

+ 128
- 0
src/test/java/CreditCardTest.java Dosyayı Görüntüle

@@ -0,0 +1,128 @@
1
+import org.junit.Test;
2
+
3
+import static org.junit.Assert.*;
4
+
5
+
6
+
7
+
8
+public class CreditCardTest  {
9
+
10
+
11
+    Check check = new Check();
12
+    PayPal payPal = new PayPal(4L, "Tia Mowry", "tia@mowry.com");
13
+    CreditCard credit = new CreditCard();
14
+
15
+    @org.junit.Before
16
+    public void setUp() throws Exception {
17
+    }
18
+
19
+    @org.junit.After
20
+    public void tearDown() throws Exception {
21
+    }
22
+
23
+    @Test
24
+    public void getId(){
25
+        CreditCard credit = new CreditCard();
26
+
27
+        long expectedId = 0;
28
+
29
+        long actualId = credit.getId();
30
+
31
+        assertEquals(expectedId, actualId);
32
+
33
+    }
34
+
35
+    @Test
36
+    public void getPayerName(){
37
+        CreditCard credit = new CreditCard();
38
+
39
+        String expectedPayerName = "Tia Mowry";
40
+        credit.setPayerName(expectedPayerName);
41
+
42
+        String actualPayerName = credit.getPayerName();
43
+
44
+        assertEquals(expectedPayerName, actualPayerName);
45
+
46
+
47
+    }
48
+
49
+    public void getShortDescription() {
50
+    }
51
+
52
+
53
+    @Test
54
+    public void getNumber(){
55
+        CreditCard credit = new CreditCard();
56
+
57
+        String expectedNumber = "4551";
58
+        credit.setNumber(expectedNumber);
59
+        String actualNumber = credit.getNumber();
60
+
61
+        assertEquals(expectedNumber, actualNumber);
62
+
63
+    }
64
+
65
+    @Test
66
+    public void getExpiredMonth(){
67
+        CreditCard credit = new CreditCard();
68
+
69
+        int expectedExpiredMonth = 10;
70
+        credit.setExpiredMonth(expectedExpiredMonth);
71
+        int actualExpiredMonth = credit.getExpiredMonth();
72
+
73
+        assertEquals(expectedExpiredMonth, actualExpiredMonth);
74
+
75
+    }
76
+
77
+
78
+    @Test
79
+    public void getExpiredYear(){
80
+        CreditCard credit = new CreditCard();
81
+
82
+        int expectedExpiredYear = 2019;
83
+        credit.setExpiredYear(expectedExpiredYear);
84
+
85
+        int actualExpiredYear = credit.getexpiredYear();
86
+
87
+        assertEquals(expectedExpiredYear, actualExpiredYear);
88
+
89
+
90
+
91
+    }
92
+    @Test
93
+    public void compareToCredit(){
94
+
95
+        int expected = 0;
96
+
97
+        int actual = credit.compareTo(credit);
98
+
99
+        assertEquals(expected, actual);
100
+
101
+
102
+    }
103
+    @Test
104
+    public void compareToPayPal(){
105
+
106
+
107
+
108
+        int expected = 1;
109
+
110
+        int actual = credit.compareTo(payPal);
111
+
112
+        assertEquals(expected, actual);
113
+
114
+    }
115
+    @Test
116
+    public void compareToCheck() {
117
+
118
+
119
+
120
+        int expected = 1;
121
+
122
+        int actual = credit.compareTo(check);
123
+
124
+        assertEquals(expected, actual);
125
+    }
126
+
127
+
128
+}

+ 86
- 0
src/test/java/PayPalTest.java Dosyayı Görüntüle

@@ -0,0 +1,86 @@
1
+import org.junit.Test;
2
+
3
+import static org.junit.Assert.*;
4
+
5
+public class PayPalTest {
6
+
7
+
8
+    Check check = new Check();
9
+    PayPal payPal = new PayPal(4L, "Tia Mowry", "tia@mowry.com");
10
+    CreditCard credit = new CreditCard();
11
+
12
+
13
+    @Test
14
+    public void getPayerName() {
15
+        PayPal payPal = new PayPal(4L, "Tia Mowry", "tia@mowry.com");
16
+
17
+        String expectedPayerName = "Tia Mowry";
18
+        payPal.setPayerName(expectedPayerName);
19
+        String actualPayerName = payPal.getPayerName();
20
+
21
+        assertEquals(expectedPayerName, actualPayerName);
22
+
23
+    }
24
+
25
+    @Test
26
+    public void getEmail() {
27
+        PayPal payPal = new PayPal(4L, "Tia Mowry", "tia@mowry.com");
28
+
29
+        String expectedEmail = "tia@mowry.com";
30
+        payPal.setEmail(expectedEmail);
31
+        String actualEmail = payPal.getEmail();
32
+
33
+        assertEquals(expectedEmail, actualEmail);
34
+
35
+    }
36
+
37
+    @Test
38
+    public void getId() {
39
+
40
+
41
+    }
42
+
43
+    @Test
44
+    public void getEmail1() {
45
+    }
46
+
47
+    @Test
48
+    public void getShortDescription() {
49
+    }
50
+
51
+    @Test
52
+    public void compareToCredit(){
53
+
54
+        int expected = 0;
55
+
56
+        int actual = credit.compareTo(credit);
57
+
58
+        assertEquals(expected, actual);
59
+
60
+
61
+    }
62
+    @Test
63
+    public void compareToPayPal(){
64
+
65
+
66
+
67
+        int expected = 1;
68
+
69
+        int actual = credit.compareTo(payPal);
70
+
71
+        assertEquals(expected, actual);
72
+
73
+    }
74
+    @Test
75
+    public void compareToCheck() {
76
+
77
+
78
+
79
+        int expected = 1;
80
+
81
+        int actual = credit.compareTo(check);
82
+
83
+        assertEquals(expected, actual);
84
+    }
85
+
86
+}

+ 78
- 0
src/test/java/PaymentPresenterTest.java Dosyayı Görüntüle

@@ -0,0 +1,78 @@
1
+import org.junit.Test;
2
+
3
+import static org.junit.jupiter.api.Assertions.assertEquals;
4
+
5
+
6
+public class PaymentPresenterTest {
7
+
8
+
9
+    private Payment[] payment;
10
+
11
+    @Test
12
+    public void testToStringNoPayments() {
13
+        Payment[] payments = new Payment[0];
14
+        PaymentPresenter presenter = new PaymentPresenter();
15
+        String expected = "";
16
+        String actual = presenter.toString(payments);
17
+
18
+    }
19
+
20
+
21
+    @Test
22
+    public void testMultiplePayments() {
23
+        Payment[] payments = new Payment[2];
24
+        Payment paypal = new PayPal(4L, "Tia Mowry", "tia@mowry.com");
25
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
26
+
27
+        payments[0] = paypal;
28
+        payments[1] = check;
29
+
30
+        PaymentPresenter presenter = new PaymentPresenter();
31
+        String expected = "Check Tia Mowry ***4551\nPaypal Tia Mowry tia@mowry.com\n";
32
+
33
+        String actual = presenter.toString(payments);
34
+        assertEquals(expected, actual);
35
+    }
36
+
37
+
38
+
39
+    @Test
40
+    public void testToStringByPayerName() {
41
+
42
+
43
+        Payment[] payments = new Payment[2];
44
+        Payment paypal = new PayPal(4L, "Tamara Mowry", "tamara@mowry.com");
45
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
46
+
47
+        payments[0] = paypal;
48
+        payments[1] = check;
49
+
50
+        PaymentPresenter presenter = new PaymentPresenter();
51
+        String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
52
+
53
+        String actual = presenter.toStringByPayerName(payments);
54
+        assertEquals(expected, actual);
55
+    }
56
+    @Test
57
+
58
+    public void testToStringById(){
59
+
60
+        Payment[] payments = new Payment[2];
61
+        Payment paypal = new PayPal(120L, "Tamara Mowry", "tamara@mowry.com");
62
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
63
+
64
+        payments[0] = paypal;
65
+        payments[1] = check;
66
+
67
+        PaymentPresenter presenter = new PaymentPresenter();
68
+        String expected = "Check Tia Mowry ***4551\nPaypal Tamara Mowry tamara@mowry.com\n";
69
+
70
+        String actual = presenter.toStringById(payments);
71
+        assertEquals(expected, actual);
72
+
73
+    }
74
+
75
+
76
+}
77
+
78
+

+ 0
- 4
src/test/java/com/zipcoder/payment/PaymentPresenterTest.java Dosyayı Görüntüle

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