Arin Turpin il y a 8 ans
Parent
révision
8dfd25dc21

+ 10
- 0
src/main/java/com/zipcoder/payment/Check.java Voir le fichier

@@ -8,6 +8,16 @@ public class Check implements Payment {
8 8
     private String accountNumber;
9 9
 
10 10
 
11
+    public Check(){
12
+
13
+    }
14
+
15
+
16
+    public Check(long id, String payerName, String routingNumber, String accountNumber){
17
+
18
+    }
19
+
20
+
11 21
     public void setId(int id) {
12 22
         this.id = id;
13 23
     }

+ 33
- 0
src/main/java/com/zipcoder/payment/PaymentPresenter.java Voir le fichier

@@ -3,4 +3,37 @@ package com.zipcoder.payment;
3 3
 public class PaymentPresenter {
4 4
 
5 5
 
6
+    public String toString(Payment[] payments) {
7
+        Payment q = null;
8
+
9
+        for(Payment x : payments){
10
+            if(x != null){
11
+                q = x;
12
+            }
13
+        }
14
+        if(q == null){
15
+            return "";
16
+        }
17
+
18
+
19
+//        if(payments.length == 0){
20
+//            return "";
21
+//        }
22
+
23
+        String x = toString(payments);
24
+        System.out.println(x);
25
+        return x;
26
+    }
27
+
28
+
29
+    public String toStringByPayerName(Payment[] payments) {
30
+
31
+        return null;
32
+    }
33
+
34
+    public String toStringById(Payment[] payments) {
35
+
36
+        return null;
37
+
38
+    }
6 39
 }

+ 6
- 9
src/main/java/com/zipcoder/payment/PaymentSortByPayer.java Voir le fichier

@@ -1,16 +1,13 @@
1 1
 package com.zipcoder.payment;
2
+import java.util.Comparator;
3
+public class PaymentSortByPayer implements Comparator<Payment> {
2 4
 
3
-public class PaymentSortByPayer implements java.util.Comparator {
4
-
5
-//    public int comparee(Payment payment1, Payment payment2) {
6
-//        return payment1.compareTo(payment2);
7
-//    }
8 5
 
9 6
     @Override
10
-    public int compare(Object o1, Object o2) {
11
-
12
-        int x = compare(o1, o2);
13
-
7
+    public int compare(Payment o1, Payment o2) {
8
+        int x = o1.getPayerName().compareTo(o2.getPayerName());
14 9
         return x;
15 10
     }
11
+
16 12
 }
13
+

+ 71
- 0
src/test/java/com/zipcoder/payment/PaymentPresenterTest.java Voir le fichier

@@ -1,4 +1,75 @@
1 1
 package com.zipcoder.payment;
2 2
 
3
+import org.junit.Test;
4
+
5
+import static junit.framework.TestCase.assertEquals;
6
+
3 7
 public class PaymentPresenterTest {
8
+
9
+    @Test
10
+    public void test_toString_with_no_payment(){
11
+
12
+        Payment[] payments = new Payment[0];
13
+        PaymentPresenter presenter = new PaymentPresenter();
14
+        String expected = "";
15
+
16
+        String actual = presenter.toString(payments);
17
+
18
+        assertEquals(expected, actual);
19
+
20
+    }
21
+
22
+    @Test
23
+    public void test_toString_with_multiple_payments(){
24
+
25
+        Payment[] payments = new Payment[2];
26
+        Payment payPal = new PayPal(4, "Tia Mowry", "tia@mowry.com");
27
+        Payment check = new Check(81, "Tia Mowry", "11432543", "9936275");
28
+
29
+        payments[0] = payPal;
30
+        payments[1] = check;
31
+
32
+        PaymentPresenter presenter = new PaymentPresenter();
33
+        String expected = "Check Tia Mowry ***4551\nPaypal Tia Mowry tia@mowry.com\n";
34
+
35
+        String actual = presenter.toString(payments);
36
+        assertEquals(expected, actual);
37
+
38
+    }
39
+
40
+    @Test
41
+    public void test_toStringByPayerName_with_multiple_payments(){
42
+
43
+        Payment[] payments = new Payment[2];
44
+        Payment payPal = new PayPal(4, "Tamara Mowry", "tamara@mowry.com");
45
+        Payment check = new Check(81, "Tia Mowry", "11432543", "2273080");
46
+
47
+        payments[0] = payPal;
48
+        payments[1] = check;
49
+
50
+        PaymentPresenter presenter = new PaymentPresenter();
51
+        String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
52
+
53
+        String actual = presenter.toStringByPayerName(payments);
54
+        assertEquals(expected, actual);
55
+
56
+    }
57
+
58
+    @Test
59
+    public void test_toStringById(){
60
+
61
+        Payment[] payments = new Payment[2];
62
+        Payment payPal = new PayPal(120, "Tamara Mowry", "tamara@mowry.com");
63
+        Payment check = new Check(81, "Tia Mowry", "11432543", "134344551");
64
+
65
+        payments[0] = payPal;
66
+        payments[1] = check;
67
+
68
+        PaymentPresenter presenter = new PaymentPresenter();
69
+        String expected = "Paypal Tamara Mowry tamara@mowry.com\nCheck Tia Mowry ***4551\n";
70
+
71
+        String actual = presenter.toStringById(payments);
72
+        assertEquals(expected, actual);
73
+
74
+    }
4 75
 }

+ 52
- 27
src/test/java/com/zipcoder/payment/PaymentSortByPayerTest.java Voir le fichier

@@ -7,54 +7,79 @@ public class PaymentSortByPayerTest {
7 7
 
8 8
     PaymentSortByPayer paymentSortByPayer1 = new PaymentSortByPayer();
9 9
     PaymentSortByPayer paymentSortByPayer2 = new PaymentSortByPayer();
10
-    PaymentSortByPayer paymentSortByPayer3= new PaymentSortByPayer();
11 10
 
12 11
 
13
-    Payment payment1 = new PayPal();
14
-    Payment payment2 = new Check();
12
+    PayPal payment1 = new PayPal();
13
+    Check payment2 = new Check();
15 14
 
16 15
     @Test
17
-    public void compare() {
16
+    public void test_compare_when_payments_are_equal() {
18 17
 
19
-        int x = paymentSortByPayer3.compare(paymentSortByPayer1, paymentSortByPayer2);
18
+        payment1.setPayerName("Ken");
19
+        payment1.setEmail("peace_459@live.com");
20
+        payment1.setId(888);
20 21
 
21
-        Assert.assertEquals(-1, x < 0);
22
-        Assert.assertEquals(0, x == 0);
23
-        Assert.assertEquals(1, x > 0);
22
+        payment2.setId(459);
23
+        payment2.setRoutingNumber("2815");
24
+        payment2.setPayerName("Angel");
25
+        payment2.setAccountNumber("9532850");
24 26
 
25 27
 
28
+        //int actual = paymentSortByPayer1.compare(payment1, payment1);
26 29
 
30
+        Assert.assertTrue(paymentSortByPayer1.compare(payment1, payment1)==0);
31
+//        Assert.assertFalse(actual < 0);
32
+//        Assert.assertFalse(actual > 0);
27 33
 
28 34
 
35
+        }
29 36
 
30 37
 
38
+    @Test
39
+    public void test_compare_when_payment1_is_before_payment2(){
40
+
41
+        payment1.setPayerName("Kenn");
42
+        payment1.setEmail("peace_459@livee.com");
43
+        payment1.setId(8888);
44
+
45
+        payment2.setId(4559);
46
+        payment2.setRoutingNumber("28155");
47
+        payment2.setPayerName("Angell");
48
+        payment2.setAccountNumber("9532857");
49
+
50
+        int actual = paymentSortByPayer1.compare(payment1, payment2);
51
+
52
+        Assert.assertTrue(actual > 0);
53
+        Assert.assertFalse(actual < 0);
54
+        Assert.assertFalse(actual == 0);
55
+    }
56
+
57
+
58
+
59
+    @Test
60
+    public void test_compare_when_payment2_is_before_payment1(){
31 61
 
62
+        PayPal payment5 = new PayPal();
63
+        Check payment6 = new Check();
32 64
 
65
+        payment5.setPayerName("Kennn");
66
+        payment5.setEmail("peace_459@liveee.com");
67
+        payment5.setId(88888);
33 68
 
69
+        payment6.setId(45559);
70
+        payment6.setRoutingNumber("281555");
71
+        payment6.setPayerName("Angelll");
72
+        payment6.setAccountNumber("9532852");
34 73
 
35
-        //     //   boolean answer;
36
-//        int fuego = 0;
37
-//
38
-//        if(payment1.compareTo(payment2) > 0){
39
-//            fuego = 88;
40
-//        } else
41
-//            if(payment1.compareTo(payment2) == 0){
42
-//            fuego = 0;
43
-//            } else
44
-//                if(payment1.compareTo(payment2) < 0){
45
-//            fuego = -3849;
46
-//                }
47
-//
48
-//        Assert.assertTrue("fuego is greater than zero", fuego > 0);
49
-//        Assert.assertTrue("fuego equals zero", fuego == 0);
50
-//        Assert.assertTrue("fuego is less than zero", fuego < 0);
51
-//
52
-//    }
74
+        int actual = paymentSortByPayer2.compare(payment5, payment6);
53 75
 
76
+        Assert.assertTrue(actual > 0);
77
+        Assert.assertFalse(actual < 0);
78
+        Assert.assertFalse(actual == 0);
54 79
 
55 80
     }
56 81
 }
57 82
 
58 83
 //Leaving test broken so that I remember to come back to it.
59
-xyz
84
+//xyz
60 85
 //Leaving test broken so that I remember to come back to it.