jpsp91 8 лет назад
Родитель
Сommit
18b67949ff
25 измененных файлов: 914 добавлений и 11 удалений
  1. Двоичные данные
      .DS_Store
  2. 4
    7
      README.MD
  3. 15
    4
      pom.xml
  4. Двоичные данные
      src/.DS_Store
  5. Двоичные данные
      src/main/.DS_Store
  6. Двоичные данные
      src/main/java/.DS_Store
  7. Двоичные данные
      src/main/java/com/.DS_Store
  8. Двоичные данные
      src/main/java/com/zipcoder/.DS_Store
  9. 82
    0
      src/main/java/com/zipcoder/payment/Check.java
  10. 118
    0
      src/main/java/com/zipcoder/payment/CreditCard.java
  11. 66
    0
      src/main/java/com/zipcoder/payment/PayPal.java
  12. 11
    0
      src/main/java/com/zipcoder/payment/Payment.java
  13. 44
    0
      src/main/java/com/zipcoder/payment/PaymentPresenter.java
  14. 17
    0
      src/main/java/com/zipcoder/payment/PaymentSortByID.java
  15. 39
    0
      src/main/java/com/zipcoder/payment/PaymentSortByPayer.java
  16. 17
    0
      src/main/java/com/zipcoder/payment/PaymentSortByShortDescription.java
  17. Двоичные данные
      src/test/.DS_Store
  18. Двоичные данные
      src/test/java/.DS_Store
  19. Двоичные данные
      src/test/java/com/.DS_Store
  20. Двоичные данные
      src/test/java/com/zipcoder/.DS_Store
  21. 115
    0
      src/test/java/com/zipcoder/payment/CheckTest.java
  22. 131
    0
      src/test/java/com/zipcoder/payment/CreditCardTest.java
  23. 91
    0
      src/test/java/com/zipcoder/payment/PayPalTest.java
  24. 68
    0
      src/test/java/com/zipcoder/payment/PaymentPresenterTest.java
  25. 96
    0
      src/test/java/com/zipcoder/payment/PaymentSortByPayerTest.java

Двоичные данные
.DS_Store Просмотреть файл


+ 4
- 7
README.MD Просмотреть файл

@@ -61,7 +61,7 @@
61 61
 # Section 2 - Comparable
62 62
 Note: You may use the String/Long compareTo methods in your code
63 63
 1. Edit the `Payment` class to extends the Comparable interface
64
-  - `public interface Payment extends Comparable<Payment>`
64
+  - `public class Payment extends Comparable<Payment>`
65 65
   - This indicate that payment can be comparable, which means it can be sorted
66 66
 2. Fix the syntax error in your CreditCard, Check, and Paypal class by adding the compare method
67 67
 3. Create a test for the `compareTo` method. Compare using the getShortDescription()
@@ -102,8 +102,7 @@ Note: You may use the String/Long compareTo methods in your code
102 102
     Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
103 103
 
104 104
     payment[0] = paypal;
105
-    payment[1] = check;
106
-    
105
+
107 106
     PaymentPresenter presenter = new PaymentPresenter();
108 107
     String expected = "Check Tia Mowry ***4551\nPaypal Tia Mowry tia@mowry.com\n";
109 108
 
@@ -120,12 +119,11 @@ Note: You may use the String/Long compareTo methods in your code
120 119
       Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
121 120
 
122 121
       payment[0] = paypal;
123
-      payment[1] = check;
124 122
 
125 123
       PaymentPresenter presenter = new PaymentPresenter();
126 124
       String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
127 125
 
128
-      String actual = presenter.toStringByPayerName(payments);
126
+      String actual = presenter.toString(payments);
129 127
       assertEquals(expected, actual);
130 128
     ```
131 129
     
@@ -138,11 +136,10 @@ Note: You may use the String/Long compareTo methods in your code
138 136
       Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551")
139 137
 
140 138
       payment[0] = paypal;
141
-      payment[1] = check;
142 139
 
143 140
       PaymentPresenter presenter = new PaymentPresenter();
144 141
       String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
145 142
 
146
-      String actual = presenter.toStringById(payments);
143
+      String actual = presenter.toString(payments);
147 144
       assertEquals(expected, actual);
148 145
     ```

+ 15
- 4
pom.xml Просмотреть файл

@@ -7,9 +7,20 @@
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>
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>junit</groupId>
19
+            <artifactId>junit</artifactId>
20
+            <version>RELEASE</version>
21
+            <scope>test</scope>
22
+        </dependency>
23
+    </dependencies>
24
+
14 25
 
15 26
 </project>

Двоичные данные
src/.DS_Store Просмотреть файл


Двоичные данные
src/main/.DS_Store Просмотреть файл


Двоичные данные
src/main/java/.DS_Store Просмотреть файл


Двоичные данные
src/main/java/com/.DS_Store Просмотреть файл


Двоичные данные
src/main/java/com/zipcoder/.DS_Store Просмотреть файл


+ 82
- 0
src/main/java/com/zipcoder/payment/Check.java Просмотреть файл

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

+ 118
- 0
src/main/java/com/zipcoder/payment/CreditCard.java Просмотреть файл

@@ -0,0 +1,118 @@
1
+package com.zipcoder.payment;
2
+
3
+public class CreditCard implements Payment {
4
+
5
+
6
+    Long id;
7
+
8
+    String payerName;
9
+
10
+    String shortDescription;
11
+
12
+
13
+
14
+    String number;
15
+
16
+    int expiredMonth;
17
+
18
+    int expiredYear;
19
+
20
+
21
+
22
+    public CreditCard(){
23
+
24
+    }
25
+
26
+    public CreditCard(long id, String payerName, String number, int month, int year){
27
+        this.id = id;
28
+        this.payerName = payerName;
29
+        this.number = number;
30
+        this.expiredMonth = expiredMonth;
31
+        this.expiredYear = expiredYear;
32
+    }
33
+
34
+
35
+
36
+
37
+    public Long getId(){
38
+        return id;
39
+    }
40
+
41
+    public void setId(Long id) {
42
+        this.id = id;
43
+    }
44
+
45
+
46
+
47
+
48
+
49
+    public String getPayerName(){
50
+        return payerName;
51
+    }
52
+
53
+    public void setPayerName(String payerName) {
54
+        this.payerName = payerName;
55
+    }
56
+
57
+
58
+
59
+
60
+    public String getNumber (){
61
+        return number;
62
+    }
63
+
64
+    public void setNumber(String number) {
65
+        this.number = number;
66
+    }
67
+
68
+
69
+
70
+
71
+
72
+
73
+    public int getExpiredMonth (){
74
+        return expiredMonth;
75
+    }
76
+
77
+    public void setExpiredMonth(int expiredMonth) {
78
+        this.expiredMonth = expiredMonth;
79
+    }
80
+
81
+
82
+
83
+
84
+
85
+
86
+    public int getExpiredYear (){
87
+        return expiredYear;
88
+    }
89
+
90
+    public void setExpiredYear(int expiredYear) {
91
+        this.expiredYear = expiredYear;
92
+    }
93
+
94
+
95
+
96
+
97
+
98
+    public String getShortDescription(){
99
+
100
+        String numb = getNumber();
101
+        String lastFour = getNumber().substring(numb.length()-4, numb.length());
102
+
103
+        return "CC " + this.payerName + " " + lastFour + " " + this.expiredMonth + "/" + this.expiredYear + "\n";
104
+    }
105
+
106
+
107
+
108
+
109
+    public int compareTo(Payment o) {
110
+        if(this.getShortDescription().compareTo(o.getShortDescription()) > 0){
111
+            return 1;
112
+        } else if(this.getShortDescription().compareTo(o.getShortDescription()) < 0) {
113
+            return -1;
114
+        } else {
115
+            return 0;
116
+        }
117
+    }
118
+}

+ 66
- 0
src/main/java/com/zipcoder/payment/PayPal.java Просмотреть файл

@@ -0,0 +1,66 @@
1
+package com.zipcoder.payment;
2
+
3
+public class PayPal implements Payment{
4
+
5
+    Long id;
6
+
7
+    String payerName;
8
+
9
+    String email;
10
+
11
+
12
+
13
+    public static void main(String[] args){
14
+        int var = "Paypal Tia Mowry tia@mowry.com".compareTo("Check Tia Mowry ***4551");
15
+        System.out.println(var);
16
+    }
17
+
18
+    public Long getId() {
19
+        return id;
20
+    }
21
+
22
+    public void setId(Long id) {
23
+        this.id = id;
24
+    }
25
+
26
+    public String getPayerName() {
27
+        return payerName;
28
+    }
29
+
30
+    public void setPayerName(String payerName) {
31
+        this.payerName = payerName;
32
+    }
33
+
34
+    public String getEmail() {
35
+        return email;
36
+    }
37
+
38
+    public void setEmail(String email) {
39
+        this.email = email;
40
+    }
41
+
42
+
43
+    public PayPal(Long id, String payerName, String email){
44
+        this.id = id;
45
+        this.payerName = payerName;
46
+        this.email = email;
47
+    }
48
+
49
+
50
+
51
+
52
+    public String getShortDescription(){
53
+        return "PayPal " + this.payerName + " " + this.email + "\n";
54
+    }
55
+
56
+
57
+    public int compareTo(Payment o) {
58
+        if(this.getShortDescription().compareTo(o.getShortDescription()) > 0){
59
+            return 1;
60
+        } else if(this.getShortDescription().compareTo(o.getShortDescription()) < 0) {
61
+            return -1;
62
+        } else {
63
+            return 0;
64
+        }
65
+    }
66
+}

+ 11
- 0
src/main/java/com/zipcoder/payment/Payment.java Просмотреть файл

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

+ 44
- 0
src/main/java/com/zipcoder/payment/PaymentPresenter.java Просмотреть файл

@@ -1,6 +1,50 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
+import java.util.Arrays;
4
+
3 5
 public class PaymentPresenter {
4 6
 
5 7
 
8
+
9
+    public String toStringPayer(Payment[] payments) {
10
+
11
+        Arrays.sort(payments, new PaymentSortByPayer());
12
+
13
+        StringBuilder sb = new StringBuilder();
14
+
15
+        for (Payment payment:payments) {
16
+            sb.append(payment.getShortDescription());
17
+        }
18
+
19
+        return sb.toString();
20
+    }
21
+
22
+
23
+    public String toString(Payment[] payments) {
24
+
25
+        Arrays.sort(payments, new PaymentSortByShortDescription());
26
+
27
+        StringBuilder sb = new StringBuilder();
28
+
29
+        for (Payment payment:payments) {
30
+            sb.append(payment.getShortDescription());
31
+        }
32
+
33
+        return sb.toString();
34
+    }
35
+
36
+
37
+    public String toStringID(Payment[] payments) {
38
+
39
+        Arrays.sort(payments, new PaymentSortByID());
40
+
41
+        StringBuilder sb = new StringBuilder();
42
+
43
+        for (Payment payment:payments) {
44
+            sb.append(payment.getShortDescription());
45
+        }
46
+
47
+        return sb.toString();
48
+    }
49
+
6 50
 }

+ 17
- 0
src/main/java/com/zipcoder/payment/PaymentSortByID.java Просмотреть файл

@@ -0,0 +1,17 @@
1
+package com.zipcoder.payment;
2
+
3
+import java.util.Comparator;
4
+
5
+public class PaymentSortByID implements Comparator<Payment> {
6
+
7
+
8
+    public int compare(Payment o1, Payment o2) {
9
+        if (o1.getId().compareTo(o2.getId()) > 0){
10
+            return 1;
11
+        } else if(o1.getId().compareTo(o2.getId()) < 0) {
12
+            return -1;
13
+        } else {
14
+            return 0;
15
+        }
16
+    }
17
+}

+ 39
- 0
src/main/java/com/zipcoder/payment/PaymentSortByPayer.java Просмотреть файл

@@ -0,0 +1,39 @@
1
+package com.zipcoder.payment;
2
+
3
+import java.util.Comparator;
4
+
5
+public class PaymentSortByPayer implements Comparator<Payment> {
6
+
7
+
8
+
9
+    public int compare(Payment o1, Payment o2) {
10
+        if (o1.getPayerName().compareTo(o2.getPayerName()) > 0){
11
+            return 1;
12
+        } else if(o1.getPayerName().compareTo(o2.getPayerName()) < 0) {
13
+            return -1;
14
+        } else {
15
+            return 0;
16
+        }
17
+    }
18
+
19
+//    public int compareShortDescription(Payment o1, Payment o2) {
20
+//        if (o1.getShortDescription().compareTo(o2.getShortDescription()) > 0){
21
+//            return 1;
22
+//        } else if(o1.getShortDescription().compareTo(o2.getShortDescription()) < 0) {
23
+//            return -1;
24
+//        } else {
25
+//            return 0;
26
+//        }
27
+//    }
28
+//
29
+//    public int compareID(Payment o1, Payment o2) {
30
+//        if (o1.getId().compareTo(o2.getId()) > 0){
31
+//            return 1;
32
+//        } else if(o1.getId().compareTo(o2.getId()) < 0) {
33
+//            return -1;
34
+//        } else {
35
+//            return 0;
36
+//        }
37
+//    }
38
+
39
+}

+ 17
- 0
src/main/java/com/zipcoder/payment/PaymentSortByShortDescription.java Просмотреть файл

@@ -0,0 +1,17 @@
1
+package com.zipcoder.payment;
2
+
3
+import java.util.Comparator;
4
+
5
+public class PaymentSortByShortDescription implements Comparator<Payment> {
6
+
7
+
8
+    public int compare(Payment o1, Payment o2) {
9
+        if (o1.getShortDescription().compareTo(o2.getShortDescription()) > 0){
10
+            return 1;
11
+        } else if(o1.getShortDescription().compareTo(o2.getShortDescription()) < 0) {
12
+            return -1;
13
+        } else {
14
+            return 0;
15
+        }
16
+    }
17
+}

Двоичные данные
src/test/.DS_Store Просмотреть файл


Двоичные данные
src/test/java/.DS_Store Просмотреть файл


Двоичные данные
src/test/java/com/.DS_Store Просмотреть файл


Двоичные данные
src/test/java/com/zipcoder/.DS_Store Просмотреть файл


+ 115
- 0
src/test/java/com/zipcoder/payment/CheckTest.java Просмотреть файл

@@ -0,0 +1,115 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.jupiter.api.Test;
5
+
6
+public class CheckTest {
7
+
8
+    Check check = new Check(456L, "no", "123123");
9
+
10
+
11
+    @Test
12
+    public void getIdTest(){
13
+
14
+        //when
15
+        check.setId(555L);
16
+
17
+        //expected
18
+        Long expected = 555L;
19
+
20
+        //actual
21
+        Long actual = check.getId();
22
+
23
+        Assert.assertEquals(expected, actual);
24
+    }
25
+
26
+
27
+    @Test
28
+    public void getPayerNameTest(){
29
+        //when
30
+        check.setPayerName("Troy");
31
+
32
+        //expected
33
+        String expected = "Troy";
34
+
35
+        //actual
36
+        String actual = check.getPayerName();
37
+
38
+        Assert.assertEquals(expected, actual);
39
+    }
40
+
41
+
42
+    @Test
43
+    public void getRoutingNumberTest() {
44
+        //when
45
+        check.setRoutingNumber("90001");
46
+
47
+        //expected
48
+        String expected = "90001";
49
+
50
+        //actual
51
+        String actual = check.getRoutingNumber();
52
+
53
+        Assert.assertEquals(expected, actual);
54
+    }
55
+
56
+
57
+
58
+    @Test
59
+    public void getAccountNumberTest(){
60
+        //when
61
+        check.setAccountNumber("56789");
62
+
63
+        //expected
64
+        String expected = "56789";
65
+
66
+        //actual
67
+        String actual = check.getAccountNumber();
68
+
69
+        Assert.assertEquals(expected, actual);
70
+    }
71
+
72
+
73
+    //*********************************************************
74
+    @Test
75
+    public void getShortDescriptionTest(){
76
+        //when
77
+        check.setPayerName("Abed");
78
+        check.setAccountNumber("0001234");
79
+
80
+        //expected
81
+        String expected = "Check Abed ***1234\n";
82
+
83
+        //actual
84
+        String actual = check.getShortDescription();
85
+
86
+        Assert.assertEquals(expected, actual);
87
+
88
+    }
89
+
90
+    //*********************************************************
91
+
92
+
93
+    @Test
94
+    public void compareTo() {
95
+        //when
96
+        check.setPayerName("Abed");
97
+        check.setAccountNumber("0001234");
98
+        check.getShortDescription();
99
+
100
+        CreditCard cc = new CreditCard();
101
+        cc.setPayerName("Troy");
102
+        cc.setNumber("1110000");
103
+        cc.setExpiredMonth(12);
104
+        cc.setExpiredYear(2020);
105
+        cc.getShortDescription();
106
+
107
+        //expected
108
+        int expected = -1;
109
+
110
+        //actual
111
+        int actual = cc.compareTo(check);
112
+
113
+        Assert.assertEquals(expected,actual);
114
+    }
115
+}

+ 131
- 0
src/test/java/com/zipcoder/payment/CreditCardTest.java Просмотреть файл

@@ -0,0 +1,131 @@
1
+
2
+
3
+package com.zipcoder.payment;
4
+
5
+
6
+import org.junit.Assert;
7
+import org.junit.jupiter.api.Test;
8
+
9
+
10
+import static org.junit.jupiter.api.Assertions.assertEquals;
11
+
12
+public class CreditCardTest {
13
+
14
+
15
+    CreditCard cc = new CreditCard();
16
+
17
+
18
+
19
+    @Test
20
+    public void getIdTest(){
21
+        //When
22
+        cc.setId(13L);
23
+
24
+        //Expected
25
+        long expected = 13L;
26
+
27
+        //Actual
28
+        long actual = cc.getId();
29
+
30
+        Assert.assertEquals(expected,actual);
31
+
32
+    }
33
+
34
+
35
+    @Test
36
+    public void getPayerNameTest(){
37
+        //when
38
+        cc.setPayerName("Abed");
39
+
40
+        //Expected
41
+        String expected = "Abed";
42
+
43
+        //Actual
44
+        String actual = cc.getPayerName();
45
+
46
+        assertEquals(expected,actual);
47
+    }
48
+
49
+    @Test
50
+    public void getNumberTest(){
51
+        //when
52
+        cc.setNumber("112233");
53
+
54
+        //Expected
55
+        String expected = "112233";
56
+
57
+        //Actual
58
+        String actual = cc.getNumber();
59
+
60
+        assertEquals(expected,actual);
61
+    }
62
+
63
+
64
+    @Test
65
+    public void getExpiredMonthTest(){
66
+        //when
67
+        cc.setExpiredMonth(12);
68
+
69
+        //Expected
70
+        int expected = 12;
71
+
72
+        //Actual
73
+        int actual = cc.getExpiredMonth();
74
+
75
+        assertEquals(expected, actual);
76
+    }
77
+
78
+
79
+    @Test
80
+    public void getExpiredYearTest(){
81
+        //when
82
+        cc.setExpiredYear(2019);
83
+
84
+        //Expected
85
+        int expected = 2019;
86
+
87
+        //Actual
88
+        int actual = cc.getExpiredYear();
89
+
90
+        assertEquals(expected, actual);
91
+    }
92
+
93
+
94
+
95
+    @Test
96
+    public void getShortDescriptionTest(){
97
+        //when
98
+        cc.setPayerName("Troy");
99
+        cc.setNumber("1110000");
100
+        cc.setExpiredMonth(12);
101
+        cc.setExpiredYear(2020);
102
+
103
+        //expected
104
+        String expected = "CC Troy 0000 12/2020\n";
105
+
106
+        //actual
107
+        String actual = cc.getShortDescription();
108
+
109
+        Assert.assertEquals(expected, actual);
110
+    }
111
+
112
+
113
+    @Test
114
+    public void compareTo() {
115
+        //when
116
+        cc.setPayerName("Troy");
117
+        cc.setNumber("1110000");
118
+        cc.setExpiredMonth(12);
119
+        cc.setExpiredYear(2020);
120
+        cc.getShortDescription();
121
+
122
+        //expected
123
+        int expected = 0;
124
+
125
+        //actual
126
+        int actual = cc.compareTo(cc);
127
+
128
+        Assert.assertEquals(expected,actual);
129
+
130
+    }
131
+}

+ 91
- 0
src/test/java/com/zipcoder/payment/PayPalTest.java Просмотреть файл

@@ -0,0 +1,91 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.jupiter.api.Test;
5
+
6
+public class PayPalTest {
7
+
8
+    PayPal pp = new PayPal(123L, "yes", "yesyes");
9
+
10
+    @Test
11
+    public void getIdTest() {
12
+
13
+    //when
14
+    pp.setId(5000L);
15
+
16
+    //expected
17
+    Long expected = 5000L;
18
+
19
+    //actual
20
+    Long actual = pp.getId();
21
+
22
+    Assert.assertEquals(expected, actual);
23
+    }
24
+
25
+
26
+
27
+    @Test
28
+    public void getPayerName(){
29
+        //when
30
+        pp.setPayerName("Tia Mowry");
31
+
32
+        //expected
33
+        String expected = "Tia Mowry";
34
+
35
+        //actual
36
+        String actual = pp.getPayerName();
37
+
38
+        Assert.assertEquals(expected, actual);
39
+    }
40
+
41
+
42
+    @Test
43
+    public void getEmailTest(){
44
+        //when
45
+        pp.setEmail("tia@mowry.com");
46
+
47
+        //expected
48
+        String expected = "tia@mowry.com";
49
+
50
+        //actual
51
+        String actual = pp.getEmail();
52
+
53
+        Assert.assertEquals(expected, actual);
54
+    }
55
+
56
+
57
+    @Test
58
+    public void getShortDescriptionTest(){
59
+        //when
60
+        pp.setPayerName("Tia Mowry");
61
+        pp.setEmail("tia@mowry.com");
62
+
63
+        //expected
64
+        String expected = "PayPal Tia Mowry tia@mowry.com";
65
+
66
+        //actual
67
+        String actual = pp.getShortDescription();
68
+    }
69
+
70
+
71
+    @Test
72
+    public void compareTo() {
73
+        //when
74
+        pp.setPayerName("Tia Mowry");
75
+        pp.setEmail("tia@mowry.com");
76
+        pp.getShortDescription();
77
+
78
+        Check check = new Check(123L, "Tia Mowry", "123123");
79
+        check.setPayerName("Tia Mowry");
80
+        check.setAccountNumber("0001234");
81
+        check.getShortDescription();
82
+
83
+        //expected
84
+        int expected = 1;
85
+
86
+        //actual
87
+        int actual = pp.compareTo(check);
88
+
89
+        Assert.assertEquals(expected,actual);
90
+    }
91
+}

+ 68
- 0
src/test/java/com/zipcoder/payment/PaymentPresenterTest.java Просмотреть файл

@@ -1,4 +1,72 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
+import org.junit.Assert;
4
+import org.junit.jupiter.api.Test;
5
+
3 6
 public class PaymentPresenterTest {
7
+
8
+        @Test
9
+        public void noPaymentTest() {
10
+        Payment[] payments = new Payment[0];
11
+
12
+        PaymentPresenter presenter = new PaymentPresenter();
13
+        String expected = "";
14
+
15
+        String actual = presenter.toString(payments);
16
+
17
+        Assert.assertEquals(expected, actual);
18
+}
19
+
20
+    @Test
21
+    public void multiplePaymentTest(){
22
+        Payment[] payments = new Payment[2];
23
+        Payment paypal = new PayPal(4L, "Tia Mowry", "tia@mowry.com");
24
+        Payment check = new Check(81L, "Tia Mowry", "134344551");
25
+
26
+        payments[0] = paypal;
27
+        payments[1] = check;
28
+
29
+        PaymentPresenter presenter = new PaymentPresenter();
30
+        String expected = "Check Tia Mowry ***4551\nPayPal Tia Mowry tia@mowry.com\n";
31
+
32
+        String actual = presenter.toString(payments);
33
+        Assert.assertEquals(expected, actual);
34
+    }
35
+
36
+
37
+    @Test
38
+    public void multiplePaymentTestPayerName(){
39
+        Payment[] payments = new Payment[2];
40
+        Payment paypal = new PayPal(4L, "Tia Mowry", "tia@mowry.com");
41
+        Payment check = new Check(81L, "Alice Wonder", "134344551");
42
+
43
+        payments[0] = paypal;
44
+        payments[1] = check;
45
+
46
+        PaymentPresenter presenter = new PaymentPresenter();
47
+        String expected = "Check Alice Wonder ***4551\nPayPal Tia Mowry tia@mowry.com\n";
48
+
49
+        String actual = presenter.toStringPayer(payments);
50
+        Assert.assertEquals(expected, actual);
51
+    }
52
+
53
+    @Test
54
+    public void multiplePaymentTestID(){
55
+        Payment[] payments = new Payment[2];
56
+        Payment paypal = new PayPal(4L, "Tia Mowry", "tia@mowry.com");
57
+        Payment check = new Check(81L, "Tia Mowry", "134344551");
58
+
59
+        payments[0] = paypal;
60
+        payments[1] = check;
61
+
62
+        PaymentPresenter presenter = new PaymentPresenter();
63
+        String expected = "PayPal Tia Mowry tia@mowry.com\nCheck Tia Mowry ***4551\n";
64
+
65
+        String actual = presenter.toStringID(payments);
66
+        Assert.assertEquals(expected, actual);
67
+    }
68
+
69
+
70
+
71
+
4 72
 }

+ 96
- 0
src/test/java/com/zipcoder/payment/PaymentSortByPayerTest.java Просмотреть файл

@@ -0,0 +1,96 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.jupiter.api.Test;
6
+
7
+import java.util.Arrays;
8
+
9
+public class PaymentSortByPayerTest {
10
+
11
+    PaymentSortByPayer psbp;
12
+
13
+//    Payment payment1;
14
+//
15
+//    Payment payment2;
16
+
17
+
18
+//    @Before
19
+//    public void setup(){
20
+//        payment1 = new PayPal(123L, "Dexter", "dexter@gmail.com");
21
+//        payment2 = new Check(456L, "Mandark");
22
+//
23
+//    }
24
+
25
+//    @Test
26
+//    public void compareTest(){
27
+//        System.out.println(payment1.getShortDescription());
28
+//        System.out.println(payment2.getShortDescription());
29
+//        //expected
30
+//        int expected = -1;
31
+//
32
+//        //actual
33
+//        int actual = psbp.compare(payment1, payment2);
34
+//
35
+//        Assert.assertEquals(expected, actual);
36
+//
37
+//    }
38
+
39
+    @Test
40
+    public void compareTest2(){
41
+        //when
42
+        Check check = new Check(123L,"Dexter", "123123");
43
+        Check check2 = new Check(456L, "Mandark", "456456");
44
+
45
+        //expected
46
+        int expected = -1;
47
+
48
+        //actual
49
+        //int actual = check.getPayerName().compareTo(check2.getPayerName());
50
+
51
+        int actual = check.compareTo(check2);
52
+
53
+        Assert.assertEquals(expected, actual);
54
+
55
+    }
56
+
57
+    @Test
58
+    public void compareTest3(){
59
+        //when
60
+        Check check = new Check(123L,"Dexter", "123123");
61
+        Check check2 = new Check(456L, "Mandark", "456456");
62
+
63
+        //expected
64
+        int expected = 1;
65
+
66
+        //actual
67
+        int actual = check2.compareTo(check);
68
+
69
+        Assert.assertEquals(expected, actual);
70
+
71
+    }
72
+
73
+
74
+    @Test
75
+    public void compareTest4(){
76
+        //when
77
+        Check check = new Check(123L,"Dexter", "123123");
78
+        //Check check2 = new Check(456L, "Mandark", "456456");
79
+
80
+        //expected
81
+        int expected = 0;
82
+
83
+        //actual
84
+        int actual = check.compareTo(check);
85
+
86
+        Assert.assertEquals(expected, actual);
87
+
88
+
89
+    }
90
+
91
+
92
+
93
+
94
+
95
+
96
+}