|
|
@@ -1,4 +1,123 @@
|
|
1
|
1
|
package com.zipcoder.payment;
|
|
2
|
2
|
|
|
|
3
|
+import org.junit.Assert;
|
|
|
4
|
+import org.junit.Test;
|
|
|
5
|
+
|
|
3
|
6
|
public class PaymentPresenterTest {
|
|
|
7
|
+
|
|
|
8
|
+ Payment paypal = new PayPal(4L, "Tia Mowry", "tia@mowry.com");
|
|
|
9
|
+ Payment check = new Check(81L, "Abigail Henry", "11432543", "134344551");
|
|
|
10
|
+ Payment creditCard = new CreditCard(15L, "Danny Tanner", "45454545", 12, 2099);
|
|
|
11
|
+
|
|
|
12
|
+ @Test
|
|
|
13
|
+ public void testNoPayment() {
|
|
|
14
|
+ Payment[] payments = new Payment[0];
|
|
|
15
|
+ PaymentPresenter presenter = new PaymentPresenter();
|
|
|
16
|
+ String expected = "";
|
|
|
17
|
+
|
|
|
18
|
+ String actual = presenter.toString(payments);
|
|
|
19
|
+
|
|
|
20
|
+ Assert.assertEquals(expected, actual);
|
|
|
21
|
+ }
|
|
|
22
|
+
|
|
|
23
|
+ @Test
|
|
|
24
|
+ public void testPaymentsNoSort() {
|
|
|
25
|
+ Payment[] payments = {paypal, check, creditCard};
|
|
|
26
|
+ PaymentPresenter presenter = new PaymentPresenter();
|
|
|
27
|
+ String expected = "CC Danny Tanner 4545 12/2099\n" +
|
|
|
28
|
+ "Check Abigail Henry ***4551\n" +
|
|
|
29
|
+ "PayPal Tia Mowry tia@mowry.com";
|
|
|
30
|
+
|
|
|
31
|
+ String actual = presenter.toString(payments);
|
|
|
32
|
+
|
|
|
33
|
+ Assert.assertEquals(expected, actual);
|
|
|
34
|
+ }
|
|
|
35
|
+
|
|
|
36
|
+ @Test
|
|
|
37
|
+ public void testPaymentsSort() {
|
|
|
38
|
+ Payment[] payments = {creditCard, check, paypal};
|
|
|
39
|
+ PaymentPresenter presenter = new PaymentPresenter();
|
|
|
40
|
+ String expected = "CC Danny Tanner 4545 12/2099\n" +
|
|
|
41
|
+ "Check Abigail Henry ***4551\n" +
|
|
|
42
|
+ "PayPal Tia Mowry tia@mowry.com";
|
|
|
43
|
+
|
|
|
44
|
+ String actual = presenter.toString(payments);
|
|
|
45
|
+
|
|
|
46
|
+ Assert.assertEquals(expected, actual);
|
|
|
47
|
+ }
|
|
|
48
|
+
|
|
|
49
|
+ @Test
|
|
|
50
|
+ public void testNoPaymentByName() {
|
|
|
51
|
+ Payment[] payments = new Payment[0];
|
|
|
52
|
+ PaymentPresenter presenter = new PaymentPresenter();
|
|
|
53
|
+ String expected = "";
|
|
|
54
|
+
|
|
|
55
|
+ String actual = presenter.toStringByPayerName(payments);
|
|
|
56
|
+
|
|
|
57
|
+ Assert.assertEquals(expected, actual);
|
|
|
58
|
+ }
|
|
|
59
|
+
|
|
|
60
|
+ @Test
|
|
|
61
|
+ public void testPaymentsByNameNoSort() {
|
|
|
62
|
+ Payment[] payments = {check, creditCard, paypal};
|
|
|
63
|
+ PaymentPresenter presenter = new PaymentPresenter();
|
|
|
64
|
+ String expected = "Check Abigail Henry ***4551\n" +
|
|
|
65
|
+ "CC Danny Tanner 4545 12/2099\n" +
|
|
|
66
|
+ "PayPal Tia Mowry tia@mowry.com";
|
|
|
67
|
+
|
|
|
68
|
+ String actual = presenter.toStringByPayerName(payments);
|
|
|
69
|
+
|
|
|
70
|
+ Assert.assertEquals(expected, actual);
|
|
|
71
|
+ }
|
|
|
72
|
+
|
|
|
73
|
+ @Test
|
|
|
74
|
+ public void testPaymentsByNameSort() {
|
|
|
75
|
+ Payment[] payments = {creditCard, check, paypal};
|
|
|
76
|
+ PaymentPresenter presenter = new PaymentPresenter();
|
|
|
77
|
+ String expected = "Check Abigail Henry ***4551\n" +
|
|
|
78
|
+ "CC Danny Tanner 4545 12/2099\n" +
|
|
|
79
|
+ "PayPal Tia Mowry tia@mowry.com";
|
|
|
80
|
+
|
|
|
81
|
+ String actual = presenter.toStringByPayerName(payments);
|
|
|
82
|
+
|
|
|
83
|
+ Assert.assertEquals(expected, actual);
|
|
|
84
|
+ }
|
|
|
85
|
+
|
|
|
86
|
+ @Test
|
|
|
87
|
+ public void testNoPaymentById() {
|
|
|
88
|
+ Payment[] payments = new Payment[0];
|
|
|
89
|
+ PaymentPresenter presenter = new PaymentPresenter();
|
|
|
90
|
+ String expected = "";
|
|
|
91
|
+
|
|
|
92
|
+ String actual = presenter.toStringById(payments);
|
|
|
93
|
+
|
|
|
94
|
+ Assert.assertEquals(expected, actual);
|
|
|
95
|
+ }
|
|
|
96
|
+
|
|
|
97
|
+ @Test
|
|
|
98
|
+ public void testPaymentsByIdNoSort() {
|
|
|
99
|
+ Payment[] payments = {paypal, creditCard, check};
|
|
|
100
|
+ PaymentPresenter presenter = new PaymentPresenter();
|
|
|
101
|
+ String expected = "PayPal Tia Mowry tia@mowry.com\n" +
|
|
|
102
|
+ "CC Danny Tanner 4545 12/2099\n" +
|
|
|
103
|
+ "Check Abigail Henry ***4551";
|
|
|
104
|
+
|
|
|
105
|
+ String actual = presenter.toStringById(payments);
|
|
|
106
|
+
|
|
|
107
|
+ Assert.assertEquals(expected, actual);
|
|
|
108
|
+ }
|
|
|
109
|
+
|
|
|
110
|
+ @Test
|
|
|
111
|
+ public void testPaymentsByIdSort() {
|
|
|
112
|
+ Payment[] payments = {creditCard, check, paypal};
|
|
|
113
|
+ PaymentPresenter presenter = new PaymentPresenter();
|
|
|
114
|
+ String expected = "PayPal Tia Mowry tia@mowry.com\n" +
|
|
|
115
|
+ "CC Danny Tanner 4545 12/2099\n" +
|
|
|
116
|
+ "Check Abigail Henry ***4551";
|
|
|
117
|
+
|
|
|
118
|
+ String actual = presenter.toStringById(payments);
|
|
|
119
|
+
|
|
|
120
|
+ Assert.assertEquals(expected, actual);
|
|
|
121
|
+ }
|
|
|
122
|
+
|
|
4
|
123
|
}
|