Просмотр исходного кода

completed except for the final test using lambda to sort, difficulty understand the concept currently. researching will update

David Thornley 8 лет назад
Родитель
Сommit
6c999ef79f

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

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

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

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

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

@@ -0,0 +1,85 @@
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(Long id){
11
+        this.id = id;
12
+    }
13
+
14
+    public CreditCard(Long id, String payerName, String number, int expiredMonth, int expiredYear) {
15
+        this.id = id;
16
+        this.payerName = payerName;
17
+        this.number = number;
18
+        this.expiredMonth = expiredMonth;
19
+        this.expiredYear = expiredYear;
20
+    }
21
+
22
+    public CreditCard(Long id, String payerName, String number) {
23
+        this.id = id;
24
+        this.payerName = payerName;
25
+        this.number = number;
26
+    }
27
+
28
+    public CreditCard(String payerName) {
29
+        this.payerName = payerName;
30
+    }
31
+
32
+
33
+    public Long getId() {
34
+        return id;
35
+    }
36
+
37
+    public void setId(Long id) {
38
+        this.id = id;
39
+    }
40
+
41
+    public String getPayerName() {
42
+        return payerName;
43
+    }
44
+
45
+    public void setPayerName(String payerName) {
46
+        this.payerName = payerName;
47
+    }
48
+
49
+    public String getNumber() {
50
+        return number;
51
+    }
52
+
53
+    public void setNumber(String number) {
54
+        this.number = number;
55
+    }
56
+
57
+    public int getExpiredMonth() {
58
+        return expiredMonth;
59
+    }
60
+
61
+    public void setExpiredMonth(int expiredMonth) {
62
+        this.expiredMonth = expiredMonth;
63
+    }
64
+
65
+    public int getExpiredYear() {
66
+        return expiredYear;
67
+    }
68
+
69
+    public void setExpiredYear(int expiredYear) {
70
+        this.expiredYear = expiredYear;
71
+    }
72
+
73
+    public String getLastFour(String number){
74
+        return number.substring(number.length()-4);
75
+    }
76
+
77
+    public String getShortDescription() {
78
+
79
+        return "CC " + getPayerName() + " " + getLastFour(this.number) + " " + getExpiredMonth() + "/" + getExpiredYear();
80
+    }
81
+
82
+    public int compareTo(Payment p) {
83
+        return this.getShortDescription().compareTo(p.getShortDescription());
84
+    }
85
+}

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

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

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

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

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

@@ -1,6 +1,42 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
+import java.util.Arrays;
4
+
3 5
 public class PaymentPresenter {
4 6
 
7
+    public PaymentPresenter() {
8
+    }
9
+
10
+    public String toString(Payment[] p){
11
+        Arrays.sort(p);
12
+        StringBuilder answer = new StringBuilder();
13
+
14
+        for(Payment payment: p){
15
+            answer.append(payment.getShortDescription()+"\n");
16
+        }
17
+        return answer.toString();
18
+    }
19
+
20
+    public String toStringByPayerName(Payment[] p) {
21
+        PaymentSortByPayer nameSort = new PaymentSortByPayer();
22
+        StringBuilder answer = new StringBuilder();
23
+        Arrays.sort(p, nameSort);
24
+
25
+        for(Payment payment: p){
26
+            answer.append(payment.getShortDescription()+"\n");
27
+        }
28
+        return answer.toString();
29
+    }
30
+
31
+    public String toStringById(Payment[] p){
32
+        Arrays.sort(p,
33
+                (Payment a, Payment b) -> {  return Integer.signum((int)(a.getId() - b.getId())); }
34
+        );
35
+        StringBuilder answer = new StringBuilder();
5 36
 
37
+        for(Payment payment: p){
38
+            answer.append(payment.getShortDescription()+"\n");
39
+        }
40
+        return answer.toString();
41
+    }
6 42
 }

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

@@ -0,0 +1,14 @@
1
+package com.zipcoder.payment;
2
+
3
+import java.util.Comparator;
4
+
5
+public class PaymentSortByPayer implements Comparator<Payment> {
6
+
7
+    public PaymentSortByPayer() {
8
+    }
9
+
10
+    public int compare(Payment p1, Payment p2) {
11
+        return p1.getPayerName().compareTo(p2.getPayerName());
12
+    }
13
+
14
+}

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

@@ -0,0 +1,119 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.jupiter.api.Test;
4
+
5
+import static org.junit.jupiter.api.Assertions.*;
6
+
7
+class CheckTest {
8
+
9
+    @Test
10
+    void getId() {
11
+        Check test = new Check((long) 12345678, "Bruce Wayne", "00123456", "45367483973");
12
+        long expected = (long) 12345678;
13
+        long actual = test.getId();
14
+        assertEquals(expected, actual);
15
+    }
16
+
17
+    @Test
18
+    void setId() {
19
+        Check test = new Check((long) 12345678, "Bruce Wayne", "00123456", "45367483973");
20
+        test.setId((long)23456789);
21
+        long expected = (long) 23456789;
22
+        long actual = test.getId();
23
+        assertEquals(expected, actual);
24
+    }
25
+
26
+    @Test
27
+    void getPayerName() {
28
+        Check test = new Check((long) 12345678, "Bruce Wayne", "00123456", "45367483973");
29
+        String expected = "Bruce Wayne";
30
+        String actual = test.getPayerName();
31
+        assertEquals(expected,actual);
32
+    }
33
+
34
+    @Test
35
+    void setPayerName() {
36
+        Check test = new Check((long) 12345678, "Bruce Wayne", "00123456", "45367483973");
37
+        test.setPayerName("Edward Nigma");
38
+        String expected = "Edward Nigma";
39
+        String actual = test.getPayerName();
40
+        assertEquals(expected,actual);
41
+    }
42
+
43
+    @Test
44
+    void getRoutingNumber() {
45
+        Check test = new Check((long) 12345678, "Bruce Wayne", "00123456", "45367483973");
46
+        String expected = "00123456";
47
+        String actual = test.getRoutingNumber();
48
+        assertEquals(expected,actual);
49
+    }
50
+
51
+    @Test
52
+    void setRoutingNumber() {
53
+        Check test = new Check((long) 12345678, "Bruce Wayne", "00123456", "45367483973");
54
+        test.setRoutingNumber("00234567");
55
+        String expected = "00234567";
56
+        String actual = test.getRoutingNumber();
57
+        assertEquals(expected,actual);
58
+    }
59
+
60
+
61
+    @Test
62
+    void getAccountNumber() {
63
+        Check test = new Check((long) 12345678, "Bruce Wayne", "00123456", "45367483973");
64
+        String expected = "45367483973";
65
+        String actual = test.getAccountNumber();
66
+        assertEquals(expected,actual);
67
+    }
68
+
69
+
70
+    @Test
71
+    void setAccountNumber() {
72
+        Check test = new Check((long) 12345678, "Bruce Wayne", "00123456", "45367483973");
73
+        test.setAccountNumber("123456789101");
74
+        String expected = "123456789101";
75
+        String actual = test.getAccountNumber();
76
+        assertEquals(expected,actual);
77
+    }
78
+
79
+    @Test
80
+    void getLastFour() {
81
+        Check test = new Check((long) 12345678, "Bruce Wayne", "00123456", "45367483973");
82
+        String expected = "3973";
83
+        String actual = test.getLastFour(test.accountNumber);
84
+        assertEquals(expected,actual);
85
+    }
86
+
87
+    @Test
88
+    void getShortDescription() {
89
+        Check test = new Check((long) 12345678, "Bruce Wayne", "00123456", "45367483973");
90
+        String expected = "Check Bruce Wayne ***3973";
91
+        String actual = test.getShortDescription();
92
+        assertEquals(expected,actual);
93
+    }
94
+
95
+    @Test
96
+    void compareTest(){
97
+        Check test = new Check((long) 12345678, "Bruce Wayne", "00123456", "45367483973");
98
+        Check test2 = new Check((long) 23456789, "Edward Nigma", "00123456", "98765678987");
99
+        int actual = test.compareTo(test2);
100
+        assertTrue(actual < 0);
101
+    }
102
+
103
+    @Test
104
+    void compareTest2(){
105
+        Check test = new Check((long) 12345678, "Bruce Wayne", "00123456", "45367483973");
106
+        Check test2 = new Check((long) 23456789, "Edward Nigma", "00123456", "98765678987");
107
+        int actual = test2.compareTo(test);
108
+        assertTrue(actual > 0);
109
+    }
110
+
111
+    @Test
112
+    void compareTest3(){
113
+        Check test = new Check((long) 12345678, "Bruce Wayne", "00123456", "45367483973");
114
+        Check test2 = new Check((long) 23456789, "Edward Nigma", "00123456", "98765678987");
115
+        int actual = test.compareTo(test);
116
+        assertTrue(actual == 0);
117
+    }
118
+
119
+}

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

@@ -0,0 +1,134 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.jupiter.api.BeforeEach;
4
+import org.junit.jupiter.api.Test;
5
+
6
+import static org.junit.jupiter.api.Assertions.*;
7
+
8
+class CreditCardTest {
9
+
10
+    @Test
11
+    void getId() {
12
+        CreditCard test = new CreditCard(((long) 12345678), "Bruce Wayne", "1234 5678 1234 5678",8,2023 );
13
+        long expected = (long) 12345678;
14
+        long actual = test.getId();
15
+        assertEquals(expected, actual);
16
+    }
17
+
18
+    @Test
19
+    void setId() {
20
+        CreditCard test = new CreditCard(((long) 12345678), "Bruce Wayne", "1234 5678 1234 5678",8,2023 );
21
+        test.setId((long) 23456789);
22
+        long expected = (long) 23456789;
23
+        long actual = test.getId();
24
+        assertEquals(expected, actual);
25
+    }
26
+
27
+    @Test
28
+    void getPayerName() {
29
+        CreditCard test = new CreditCard(((long) 12345678), "Bruce Wayne", "1234 5678 1234 5678",8,2023 );
30
+        String expected = "Bruce Wayne";
31
+        String actual = test.getPayerName();
32
+        assertEquals(expected, actual);
33
+    }
34
+
35
+    @Test
36
+    void setPayerName() {
37
+        CreditCard test = new CreditCard(((long) 12345678), "Bruce Wayne", "1234 5678 1234 5678",8,2023 );
38
+        test.setPayerName("Oswald Chesterfield Cobblepot");
39
+        String expected = "Oswald Chesterfield Cobblepot";
40
+        String actual = test.getPayerName();
41
+        assertEquals(expected, actual);
42
+    }
43
+
44
+    @Test
45
+    void getNumber() {
46
+        CreditCard test = new CreditCard(((long) 12345678), "Bruce Wayne", "1234 5678 1234 5678",8,2023 );
47
+        String expected = "1234 5678 1234 5678";
48
+        String actual = test.getNumber();
49
+        assertEquals(expected, actual);
50
+    }
51
+
52
+    @Test
53
+    void setNumber() {
54
+        CreditCard test = new CreditCard(((long) 12345678), "Bruce Wayne", "1234 5678 1234 5678",8,2023 );
55
+        test.setNumber("5678 1234 5678 1234");
56
+        String expected = "5678 1234 5678 1234";
57
+        String actual = test.getNumber();
58
+        assertEquals(expected, actual);
59
+    }
60
+
61
+    @Test
62
+    void getExpiredMonth() {
63
+        CreditCard test = new CreditCard(((long) 12345678), "Bruce Wayne", "1234 5678 1234 5678",8,2023 );
64
+        int expected = 8;
65
+        int actual = test.getExpiredMonth();
66
+        assertEquals(expected, actual);
67
+    }
68
+
69
+    @Test
70
+    void setExpiredMonth() {
71
+        CreditCard test = new CreditCard(((long) 12345678), "Bruce Wayne", "1234 5678 1234 5678",8,2023 );
72
+        test.setExpiredMonth(10);
73
+        int expected = 10;
74
+        int actual = test.getExpiredMonth();
75
+        assertEquals(expected, actual);
76
+    }
77
+
78
+    @Test
79
+    void getExpiredYear() {
80
+        CreditCard test = new CreditCard(((long) 12345678), "Bruce Wayne", "1234 5678 1234 5678",8,2023 );
81
+        int expected = 2023;
82
+        int actual = test.getExpiredYear();
83
+        assertEquals(expected, actual);
84
+    }
85
+
86
+    @Test
87
+    void setExpiredYear() {
88
+        CreditCard test = new CreditCard(((long) 12345678), "Bruce Wayne", "1234 5678 1234 5678",8,2023 );
89
+        test.setExpiredYear(2025);
90
+        int expected = 2025;
91
+        int actual = test.getExpiredYear();
92
+        assertEquals(expected, actual);
93
+    }
94
+
95
+    @Test
96
+    void getLastFour() {
97
+        CreditCard test = new CreditCard(((long) 12345678), "Bruce Wayne", "1234 5678 1234 5678",8,2023 );
98
+        String expected = "5678";
99
+        String actual = test.getLastFour(test.number);
100
+        assertEquals(expected, actual);
101
+    }
102
+
103
+    @Test
104
+    void getShortDescriptionTest(){
105
+        CreditCard test = new CreditCard(((long) 12345678), "Bruce Wayne", "1234 5678 1234 5678",8,2023 );
106
+        String expected = "CC Bruce Wayne 5678 8/2023";
107
+        String actual = test.getShortDescription();
108
+        assertEquals(expected,actual);
109
+    }
110
+
111
+    @Test
112
+    void compareTest(){
113
+        CreditCard test = new CreditCard(((long) 12345678), "Bruce Wayne", "1234 5678 1234 5678",8,2023 );
114
+        CreditCard test2 = new CreditCard(((long) 12345678), "Edward Nigma", "5678 1234 5678 1234",8,2023 );
115
+        int actual = test.compareTo(test2);
116
+        assertTrue(actual < 0);
117
+    }
118
+
119
+    @Test
120
+    void compareTest2(){
121
+        CreditCard test = new CreditCard(((long) 12345678), "Bruce Wayne", "1234 5678 1234 5678",8,2023 );
122
+        CreditCard test2 = new CreditCard(((long) 12345678), "Edward Nigma", "5678 1234 5678 1234",8,2023 );
123
+        int actual = test2.compareTo(test);
124
+        assertTrue(actual > 0);
125
+    }
126
+
127
+    @Test
128
+    void compareTest3(){
129
+        CreditCard test = new CreditCard(((long) 12345678), "Bruce Wayne", "1234 5678 1234 5678",8,2023 );
130
+        CreditCard test2 = new CreditCard(((long) 12345678), "Edward Nigma", "5678 1234 5678 1234",8,2023 );
131
+        int actual = test.compareTo(test);
132
+        assertTrue(actual == 0);
133
+    }
134
+}

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

@@ -0,0 +1,91 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.jupiter.api.Test;
4
+
5
+import static org.junit.jupiter.api.Assertions.*;
6
+
7
+class PayPalTest {
8
+
9
+    @Test
10
+    void getId() {
11
+        PayPal test = new PayPal(((long)12345678), "Bruce Wayne", "totallyNotBatman@theBatCave.com");
12
+        Long expected = (long) 12345678;
13
+        Long actual = test.getId();
14
+        assertEquals(expected,actual);
15
+    }
16
+
17
+    @Test
18
+    void setId() {
19
+        PayPal test = new PayPal(((long)12345678), "Bruce Wayne", "totallyNotBatman@theBatCave.com");
20
+        test.setId((long)23456789);
21
+        Long expected = (long) 23456789;
22
+        Long actual = test.getId();
23
+        assertEquals(expected,actual);
24
+    }
25
+
26
+    @Test
27
+    void getPayerName() {
28
+        PayPal test = new PayPal(((long)12345678), "Bruce Wayne", "totallyNotBatman@theBatCave.com");
29
+        String expected = "Bruce Wayne";
30
+        String actual = test.getPayerName();
31
+        assertEquals(expected,actual);
32
+    }
33
+
34
+    @Test
35
+    void setPayerName() {
36
+        PayPal test = new PayPal(((long)12345678), "Bruce Wayne", "totallyNotBatman@theBatCave.com");
37
+        test.setPayerName("Alfred Pennyworth");
38
+        String expected = "Alfred Pennyworth";
39
+        String actual = test.getPayerName();
40
+        assertEquals(expected,actual);
41
+    }
42
+
43
+    @Test
44
+    void getEmail() {
45
+        PayPal test = new PayPal(((long)12345678), "Bruce Wayne", "totallyNotBatman@theBatCave.com");
46
+        String expected = "totallyNotBatman@theBatCave.com";
47
+        String actual = test.getEmail();
48
+        assertEquals(expected,actual);
49
+    }
50
+
51
+    @Test
52
+    void setEmail() {
53
+        PayPal test = new PayPal(((long)12345678), "Bruce Wayne", "totallyNotBatman@theBatCave.com");
54
+        test.setEmail("okIAmBatman@theBatCave.com");
55
+        String expected = "okIAmBatman@theBatCave.com";
56
+        String actual = test.getEmail();
57
+        assertEquals(expected,actual);
58
+    }
59
+
60
+    @Test
61
+    void getShortDescription() {
62
+        PayPal test = new PayPal(((long)12345678), "Bruce Wayne", "totallyNotBatman@theBatCave.com");
63
+        String expected = "Paypal Bruce Wayne totallyNotBatman@theBatCave.com";
64
+        String actual = test.getShortDescription();
65
+        assertEquals(expected,actual);
66
+    }
67
+
68
+    @Test
69
+    void compareTest(){
70
+        PayPal test = new PayPal(((long) 12345678), "Bruce Wayne", "totallyNotBatMan@theBatCave.com" );
71
+        PayPal test2 = new PayPal(((long) 12345678), "Edward Nigma", "iAmNotTheRiddler@riddleMeThis.com" );
72
+        int actual = test.compareTo(test2);
73
+        assertTrue(actual < 0);
74
+    }
75
+
76
+    @Test
77
+    void compareTest2(){
78
+        PayPal test = new PayPal(((long) 12345678), "Bruce Wayne", "totallyNotBatMan@theBatCave.com" );
79
+        PayPal test2 = new PayPal(((long) 12345678), "Edward Nigma", "iAmNotTheRiddler@riddleMeThis.com" );
80
+        int actual = test2.compareTo(test);
81
+        assertTrue(actual > 0);
82
+    }
83
+
84
+    @Test
85
+    void compareTest3(){
86
+        PayPal test = new PayPal(((long) 12345678), "Bruce Wayne", "totallyNotBatMan@theBatCave.com" );
87
+        PayPal test2 = new PayPal(((long) 12345678), "Edward Nigma", "iAmNotTheRiddler@riddleMeThis.com" );
88
+        int actual = test.compareTo(test);
89
+        assertTrue(actual == 0);
90
+    }
91
+}

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

@@ -1,4 +1,60 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
-public class PaymentPresenterTest {
4
-}
3
+import org.junit.jupiter.api.Test;
4
+
5
+import static org.junit.jupiter.api.Assertions.*;
6
+
7
+class PaymentPresenterTest {
8
+
9
+    @Test
10
+    void toStringTest() {
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
+    @Test
21
+    void toStringTest2() {
22
+        Payment paypal = new PayPal(4L, "Tia Mowry", "tia@mowry.com");
23
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
24
+        Payment[] payments = new Payment[]{paypal,check};
25
+
26
+        PaymentPresenter presenter = new PaymentPresenter();
27
+        String expected = "Check Tia Mowry ***4551\nPaypal Tia Mowry tia@mowry.com\n";
28
+
29
+        String actual = presenter.toString(payments);
30
+        assertEquals(expected, actual);
31
+    }
32
+
33
+    @Test
34
+    void toStringByPayerNameTest() {
35
+        Payment paypal = new PayPal(4L, "Tamara Mowry", "tamara@mowry.com");
36
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
37
+        Payment[] payments = new Payment[]{check,paypal};
38
+
39
+        PaymentPresenter presenter = new PaymentPresenter();
40
+        String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
41
+
42
+        String actual = presenter.toStringByPayerName(payments);
43
+        assertEquals(expected, actual);
44
+    }
45
+
46
+    @Test
47
+    void toStringByIdTest(){
48
+        Payment paypal = new PayPal(120L, "Tamara Mowry", "tamara@mowry.com");
49
+        Payment check = new Check(81L, "Tia Mowry", "11432543", "134344551");
50
+        Payment[] payments = new Payment[]{paypal,check};
51
+
52
+
53
+        PaymentPresenter presenter = new PaymentPresenter();
54
+        String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
55
+
56
+        String actual = presenter.toStringById(payments);
57
+        assertEquals(expected, actual);
58
+
59
+    }
60
+}

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

@@ -0,0 +1,36 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.jupiter.api.Test;
4
+
5
+import static org.junit.jupiter.api.Assertions.*;
6
+
7
+class PaymentSortByPayerTest {
8
+
9
+    PayPal pp = new PayPal(((long) 12345678), "Bruce Wayne", "totallyNotBatMan@theBatCave.com" );
10
+    PayPal pp2 = new PayPal(((long) 12345678), "Edward Nigma", "iAmNotTheRiddler@riddleMeThis.com" );
11
+    Check check1 = new Check((long) 12345678, "Bruce Wayne", "00123456", "45367483973");
12
+    Check check2 = new Check((long) 23456789, "Edward Nigma", "00123456", "98765678987");
13
+    CreditCard cc1 = new CreditCard(((long) 12345678), "Bruce Wayne", "1234 5678 1234 5678",8,2023 );
14
+    CreditCard cc2 = new CreditCard(((long) 12345678), "Edward Nigma", "5678 1234 5678 1234",8,2023 );
15
+
16
+    PaymentSortByPayer test = new PaymentSortByPayer();
17
+
18
+    @Test
19
+    void compareTest() {
20
+
21
+        int actual = test.compare(cc1,pp);
22
+        assertTrue(actual == 0);
23
+    }
24
+
25
+    @Test
26
+    void compareTest2() {
27
+        int actual = test.compare(cc2,pp);
28
+        assertTrue(actual > 0);
29
+    }
30
+
31
+    @Test
32
+    void compareTest3() {
33
+        int actual = test.compare(pp,cc2);
34
+        assertTrue(actual < 0);
35
+    }
36
+}