Explorar el Código

almost finished

Whitney Martinez hace 7 años
padre
commit
cb73c2b120

+ 20
- 0
pom.xml Ver fichero

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

+ 58
- 0
src/main/java/com/zipcoder/payment/Check.java Ver fichero

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

+ 81
- 0
src/main/java/com/zipcoder/payment/CreditCard.java Ver fichero

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

+ 51
- 0
src/main/java/com/zipcoder/payment/PayPal.java Ver fichero

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

+ 11
- 0
src/main/java/com/zipcoder/payment/Payment.java Ver fichero

@@ -0,0 +1,11 @@
1
+package com.zipcoder.payment;
2
+
3
+public interface Payment extends Comparable<Payment>{
4
+
5
+    public Long getId();
6
+
7
+    public String getPayerName();
8
+
9
+    public String getShortDescription();
10
+
11
+}

+ 27
- 0
src/main/java/com/zipcoder/payment/PaymentPresenter.java Ver fichero

@@ -1,6 +1,33 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
+import java.util.Comparator;
4
+
3 5
 public class PaymentPresenter {
4 6
 
7
+    public PaymentPresenter (){
8
+
9
+
10
+    }
11
+
12
+    Comparator<Payment>comparator = (Payment payCheck, Payment payCheck2) ->{
13
+
14
+        Long payCheckId = payCheck.getId();
15
+        Long payCheckId2 = payCheck2.getId();
16
+        return payCheck.compareTo(payCheck2);
17
+
18
+    };
19
+
20
+
21
+
22
+    public String stringGenerator(Payment[] payments){
23
+
24
+        StringBuilder str = new StringBuilder();
25
+        for(Payment pa : payments) {
26
+            str.append(pa.getShortDescription());
27
+        }
28
+        return str.toString();
29
+    }
30
+
31
+    
5 32
 
6 33
 }

+ 24
- 0
src/main/java/com/zipcoder/payment/PaymentSortByPayer.java Ver fichero

@@ -0,0 +1,24 @@
1
+package com.zipcoder.payment;
2
+
3
+import java.util.Comparator;
4
+
5
+public class PaymentSortByPayer implements Comparator<Payment> {
6
+    @Override
7
+    public int compare(Payment o1, Payment o2) {
8
+        int num = o1.getPayerName().compareTo(o2.getPayerName());
9
+
10
+       if(num > 0){
11
+
12
+           return 1;
13
+       }else if(num < 0){
14
+
15
+           return -1;
16
+       }else{
17
+
18
+           return 0;
19
+       }
20
+
21
+
22
+    }
23
+}
24
+

+ 168
- 0
src/test/java/com/zipcoder/payment/CheckTest.java Ver fichero

@@ -0,0 +1,168 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.jupiter.api.Test;
5
+
6
+public class CheckTest {
7
+    @Test
8
+    public void ImpleminationTest(){
9
+
10
+        //Given
11
+
12
+        Check check = new Check(0L, "", "", "");
13
+
14
+        //When
15
+        Assert.assertTrue(check instanceof Payment );
16
+
17
+    }
18
+
19
+    @Test
20
+    public void GetidCheckTest(){
21
+
22
+        //Given
23
+
24
+        Check check = new Check(81L, "Tia Mowry", "11432543", "134344551");
25
+        check.setId(4L);
26
+
27
+
28
+        //When
29
+
30
+        Long actual = check.getId();
31
+        Long expecting = 4L;
32
+
33
+        //Then
34
+        Assert.assertEquals(expecting,actual);
35
+
36
+    }
37
+    @Test
38
+    public void GetnameTest(){
39
+
40
+        //Given
41
+
42
+        Check check = new Check(81L, "Tia Mowry", "11432543", "134344551");
43
+        check.setName("Jose");
44
+
45
+
46
+        //When
47
+
48
+        String actual = check.getPayerName();
49
+        String expecting = "Jose";
50
+
51
+        //Then
52
+        Assert.assertEquals(expecting,actual);
53
+
54
+    }
55
+
56
+    @Test
57
+    public void GetRoutingTest(){
58
+
59
+        //Given
60
+
61
+        Check check = new Check(81L, "Tia Mowry", "11432543", "134344551");
62
+        check.setRoutingNumber("1233");
63
+
64
+
65
+        //When
66
+
67
+        String actual = check.getRoutingNumber();
68
+        String expecting = "1233";
69
+
70
+        //Then
71
+        Assert.assertEquals(expecting,actual);
72
+
73
+    }
74
+    @Test
75
+    public void GetaccountNumberTest(){
76
+
77
+        //Given
78
+
79
+        CreditCard creditCard = new CreditCard();
80
+        creditCard.setExpYear(2019);
81
+
82
+
83
+        //When
84
+
85
+        int actual = creditCard.getExpYear();
86
+        int expecting = 2019;
87
+
88
+        //Then
89
+        Assert.assertEquals(expecting,actual);
90
+
91
+    }
92
+    @Test
93
+    public void getDesc(){
94
+
95
+        //Given
96
+
97
+        Check check = new Check(81L, "Tia Mowry", "11432543", "134344551");
98
+        check.setName("Lola Lexly");
99
+        check.setAccountNumber("5633");
100
+        check.getShortDescription();
101
+
102
+        //When
103
+        String expecting = "Check Lola Lexly ***5633";
104
+        String actual = check.getShortDescription();
105
+
106
+        //Then
107
+
108
+        Assert.assertEquals(expecting,actual);
109
+
110
+    }
111
+
112
+    @Test
113
+    public void compareCheckTest(){
114
+        //Given
115
+        Check check = new Check(81L, "Tia Mowry", "11432543", "134344551");
116
+        PayPal payPal = new PayPal(56L,"Meliza","Meliza@aol.com");
117
+
118
+
119
+        check.setId(5L);
120
+        check.setAccountNumber("2");
121
+        check.setRoutingNumber("3");
122
+        payPal.setId(4L);
123
+
124
+
125
+        payPal.getShortDescription();
126
+        check.getShortDescription();
127
+        //When
128
+        int expected = 0;
129
+        int actual = check.compareTo(payPal);
130
+
131
+        //Then
132
+        Assert.assertTrue(actual < 0);
133
+    }
134
+    @Test
135
+    public void compareCheckTest2(){
136
+        //Given
137
+        Check check = new Check(81L, "Tia Mowry", "11432543", "134344551");
138
+        PayPal payPal = new PayPal(56L,"Meliza","Meliza@aol.com");
139
+
140
+
141
+        check.setId(4L);
142
+        check.setAccountNumber("2");
143
+        payPal.setId(10L);
144
+        payPal.setEmail("tina@nora");
145
+
146
+
147
+        payPal.getShortDescription();
148
+        check.getShortDescription();
149
+        //When
150
+        int expected = 0;
151
+        int actual = payPal.compareTo(check);
152
+
153
+        //Then
154
+        Assert.assertTrue(actual > 0);
155
+    }
156
+    @Test
157
+    public void compareCheckTest3() {
158
+        //Given
159
+        Check check = new Check(81L, "Tia Mowry", "11432543", "134344551");
160
+        check.getShortDescription();
161
+        //When
162
+        int expected = 0;
163
+        int actual = check.compareTo(check);
164
+
165
+        //Then
166
+        Assert.assertEquals(actual, expected);
167
+    }
168
+}

+ 132
- 0
src/test/java/com/zipcoder/payment/CreditCardTest.java Ver fichero

@@ -0,0 +1,132 @@
1
+package com.zipcoder.payment;
2
+import org.junit.Assert;
3
+import org.junit.jupiter.api.Test;
4
+
5
+public class CreditCardTest {
6
+
7
+
8
+    @Test
9
+    public void ImpleminationTest(){
10
+
11
+        //Given
12
+
13
+            CreditCard creditCard = new CreditCard();
14
+
15
+        //When
16
+            Assert.assertTrue(creditCard instanceof Payment );
17
+
18
+    }
19
+
20
+    @Test
21
+    public void Getid(){
22
+
23
+        //Given
24
+
25
+            CreditCard creditCard = new CreditCard();
26
+            creditCard.setId(4L);
27
+
28
+
29
+        //When
30
+
31
+            Long actual = creditCard.getId();
32
+            Long expecting = 4L;
33
+
34
+        //Then
35
+        Assert.assertEquals(expecting,actual);
36
+
37
+    }
38
+    @Test
39
+    public void Getname(){
40
+
41
+        //Given
42
+
43
+        CreditCard creditCard = new CreditCard();
44
+        creditCard.setPayerName("Jose");
45
+
46
+
47
+        //When
48
+
49
+        String actual = creditCard.getPayerName();
50
+        String expecting = "Jose";
51
+
52
+        //Then
53
+        Assert.assertEquals(expecting,actual);
54
+
55
+    }
56
+
57
+    @Test
58
+    public void GetexpMonth(){
59
+
60
+        //Given
61
+
62
+        CreditCard creditCard = new CreditCard();
63
+        creditCard.setExpMonth(12);
64
+
65
+
66
+        //When
67
+
68
+        int actual = creditCard.getExpMonth();
69
+        int expecting = 12;
70
+
71
+        //Then
72
+        Assert.assertEquals(expecting,actual);
73
+
74
+    }
75
+    @Test
76
+    public void GetYearexp(){
77
+
78
+        //Given
79
+
80
+        CreditCard creditCard = new CreditCard();
81
+        creditCard.setExpYear(2019);
82
+
83
+
84
+        //When
85
+
86
+        int actual = creditCard.getExpYear();
87
+        int expecting = 2019;
88
+
89
+        //Then
90
+        Assert.assertEquals(expecting,actual);
91
+
92
+    }
93
+
94
+    @Test
95
+    public void getNumber(){
96
+
97
+        //Given
98
+
99
+        CreditCard creditCard = new CreditCard();
100
+        creditCard.setNumber("48389");
101
+
102
+        //When
103
+        String expecting = "48389";
104
+        String actual = creditCard.getNumber();
105
+
106
+        //Then
107
+
108
+        Assert.assertEquals(expecting,actual);
109
+
110
+    }
111
+    @Test
112
+    public void getDesc(){
113
+
114
+        //Given
115
+
116
+        CreditCard creditCard = new CreditCard();
117
+        creditCard.setPayerName("Lola Lexly");
118
+        creditCard.setNumber("5633");
119
+        creditCard.setExpMonth(10);
120
+        creditCard.setExpYear(2019);
121
+        creditCard.getShortDescription();
122
+
123
+        //When
124
+        String expecting = "CC Lola Lexly 5633 10/2019";
125
+        String actual = creditCard.getShortDescription();
126
+
127
+        //Then
128
+
129
+        Assert.assertEquals(expecting,actual);
130
+
131
+    }
132
+}

+ 8
- 0
src/test/java/com/zipcoder/payment/PayPalTest.java Ver fichero

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

+ 32
- 0
src/test/java/com/zipcoder/payment/PaymentPresenterTest.java Ver fichero

@@ -1,4 +1,36 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
+import org.junit.jupiter.api.Test;
4
+
5
+import static org.junit.jupiter.api.Assertions.assertEquals;
6
+
3 7
 public class PaymentPresenterTest {
8
+    @Test
9
+    public void TestingtoString(){
10
+
11
+        Payment[] payments = new Payment[0];
12
+        PaymentPresenter presenter = new PaymentPresenter();
13
+        String expected = "";
14
+
15
+        String actual = presenter.toString(payments);
16
+
17
+        assertEquals(expected, actual);
18
+
19
+    }
20
+
21
+    @Test
22
+    public void multiplepayments() {
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
+        payment[0] = paypal;
28
+        payment[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
+    }
4 36
 }