Jamez-s 8 years ago
parent
commit
152db494ba

+ 28
- 3
src/main/java/com/zipcoder/payment/PaymentPresenter.java View File

@@ -1,16 +1,41 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
+		import java.util.ArrayList;
3 4
 		import java.util.Arrays;
4 5
 		import java.util.Comparator;
5 6
 
6 7
 public class PaymentPresenter {
7 8
 
9
+
8 10
 	public String toString(Payments[] payments) {
9 11
 		StringBuilder sb = new StringBuilder();
10 12
 		Arrays.sort(payments);
11 13
 		for (int i = 0; i < payments.length; i++) {
12
-			payments[i].getShortDescription().toString();
14
+			sb.append(payments[i].getShortDescription()+"\n");
15
+		}
16
+		return sb.toString();
17
+	}
18
+
19
+
20
+	public String toStringByPayerName(Payments[] payments) {
21
+		StringBuilder sb = new StringBuilder();
22
+		Arrays.sort(payments, new PaymentSortByPayer());
23
+		for (int i = 0; i < payments.length; i++) {
24
+			sb.append(payments[i].getShortDescription()+"\n");
13 25
 		}
14
-		return null;
26
+		return sb.toString();
27
+
28
+	}
29
+
30
+	public String toStringById(Payments[] payments) {
31
+
32
+		Comparator<Payments> id = ((o1, o2) -> o1.getID().compareTo(o2.getID()));
33
+				StringBuilder sb = new StringBuilder();
34
+		Arrays.sort(payments, id);
35
+		for (int i = 0; i < payments.length; i++) {
36
+			sb.append(payments[i].getShortDescription()+"\n");
37
+		}
38
+		return sb.toString();
39
+
40
+	}
15 41
 	}
16
-}

+ 1
- 0
src/main/java/com/zipcoder/payment/PaymentSortByPayer.java View File

@@ -9,4 +9,5 @@ public class PaymentSortByPayer implements Comparator<Payments>{
9 9
 
10 10
 		return o1.getPayerName().compareTo(o2.getPayerName());
11 11
 	}
12
+
12 13
 }

+ 1
- 1
src/main/java/com/zipcoder/payment/Paypal.java View File

@@ -40,7 +40,7 @@ public class Paypal implements Payments {
40 40
 
41 41
 	@Override
42 42
 	public String getShortDescription() {
43
-		return "Paypal "+ payerName+ email;
43
+		return "Paypal "+ payerName +" "+email;
44 44
 	}
45 45
 
46 46
 	@Override

+ 53
- 2
src/test/java/com/zipcoder/payment/PaymentPresenterTest.java View File

@@ -6,15 +6,21 @@ import org.junit.Before;
6 6
 import org.junit.Test;
7 7
 
8 8
 import static org.junit.Assert.assertEquals;
9
+import static org.junit.Assert.assertTrue;
9 10
 
10 11
 public class PaymentPresenterTest {
11 12
 
13
+	Check check;
14
+	Paypal paypal;
15
+
16
+
17
+	PaymentPresenter presenter;
12 18
 
13 19
 	@Before
14 20
 	public void setup() {
15 21
 		StringBuilder sb = new StringBuilder();
16
-	}
17 22
 
23
+	}
18 24
 
19 25
 
20 26
 	@Test
@@ -31,8 +37,53 @@ public class PaymentPresenterTest {
31 37
 
32 38
 	@Test
33 39
 
34
-	public void multiplesToStringById() {
40
+	public void toStringByPayerName() {
41
+		Payments[] payments = new Payments[2];
42
+		Payments paypal = new Paypal(4L, "Tia Mowry", "tia@mowry.com");
43
+		Payments check = new Check(81L, "Tia Mowry", "11432543", "134344551");
44
+
45
+		payments[0] = paypal;
46
+		payments[1] = check;
47
+
48
+		PaymentPresenter presenter = new PaymentPresenter();
49
+		String expected = "Check Tia Mowry ***4551\nPaypal Tia Mowry tia@mowry.com\n";
50
+
51
+		String actual = presenter.toString(payments);
52
+		assertEquals(expected, actual);
53
+
35 54
 
36 55
 	}
37 56
 
57
+	@Test
58
+	public void toStringByPayer() {
59
+		Payments[] payments = new Payments[2];
60
+		Payments paypal = new Paypal(4L, "Tamara Mowry", "tamara@mowry.com");
61
+		Payments check = new Check(81L, "Tia Mowry", "11432543", "134344551");
62
+
63
+		payments[0] = paypal;
64
+		payments[1] = check;
65
+
66
+		PaymentPresenter presenter = new PaymentPresenter();
67
+		String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
68
+
69
+		String actual = presenter.toStringByPayerName(payments);
70
+		assertEquals(expected, actual);
71
+	}
72
+
73
+	@Test
74
+	public void toStringById(){
75
+		Payments[] payments = new Payments[2];
76
+		Payments paypal = new Paypal(81L, "Tamara Mowry", "tamara@mowry.com");
77
+		Payments check = new Check(120L, "Tia Mowry", "11432543", "134344551");
78
+
79
+		payments[0] = paypal;
80
+		payments[1] = check;
81
+
82
+		PaymentPresenter presenter = new PaymentPresenter();
83
+		String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
84
+
85
+		String actual = presenter.toStringById(payments);
86
+		assertEquals(expected, actual);
87
+	}
88
+
38 89
 }

+ 2
- 0
src/test/java/com/zipcoder/payment/PaypalTest.java View File

@@ -51,6 +51,8 @@ public class PaypalTest {
51 51
 
52 52
 		String expect = "Paypal Tia Mowry tia@mowry.com";
53 53
 		String actual = test.getShortDescription();
54
+		Assert.assertEquals(expect, actual);
55
+
54 56
 	}
55 57
 
56 58
 	@Test