Lauren Green hace 7 años
padre
commit
64ad2a4908

+ 5
- 0
src/main/java/com/zipcoder/payment/Check.java Ver fichero

53
     public void setAccountNumber(String accountNumber) {
53
     public void setAccountNumber(String accountNumber) {
54
         this.accountNumber = accountNumber;
54
         this.accountNumber = accountNumber;
55
     }
55
     }
56
+
57
+    @Override
58
+    public int compareTo(Payment other) {
59
+        return this.getShortDescription().compareTo(other.getShortDescription());
60
+    }
56
 }
61
 }

+ 5
- 0
src/main/java/com/zipcoder/payment/CreditCard.java Ver fichero

64
     public void setId(Long id) {
64
     public void setId(Long id) {
65
         this.id = id;
65
         this.id = id;
66
     }
66
     }
67
+
68
+    @Override
69
+    public int compareTo(Payment other) {
70
+        return this.getShortDescription().compareTo(other.getShortDescription());
71
+    }
67
 }
72
 }

+ 51
- 0
src/main/java/com/zipcoder/payment/PayPal.java Ver fichero

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

+ 1
- 1
src/main/java/com/zipcoder/payment/Payment.java Ver fichero

1
 package com.zipcoder.payment;
1
 package com.zipcoder.payment;
2
 
2
 
3
-public interface Payment {
3
+public interface Payment extends Comparable<Payment>{
4
 
4
 
5
     Long getId();
5
     Long getId();
6
 
6
 

+ 60
- 0
src/test/java/com/zipcoder/payment/PayPalTest.java Ver fichero

1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class PayPalTest {
7
+
8
+    //Given
9
+    PayPal customer = new PayPal(1L, "Lauren Green", "lauren@mail.com");
10
+    PayPal customer2 = new PayPal(2L, "Hayden Stewart", "hayden@mail.com");
11
+
12
+    @Test
13
+    public void testId() {
14
+        //When
15
+        Long expected = 3L;
16
+        customer.setId(3L);
17
+        Long actual = customer.getId();
18
+
19
+        //Then
20
+        Assert.assertEquals(expected, actual);
21
+
22
+    }
23
+
24
+    @Test
25
+    public void testName() {
26
+        //When
27
+        String expected = "Lauren Stewart";
28
+        customer.setPayerName("Lauren Stewart");
29
+        String actual = customer.getPayerName();
30
+
31
+        //Then
32
+        Assert.assertEquals(expected, actual);
33
+
34
+    }
35
+
36
+    @Test
37
+    public void testEmail() {
38
+        //When
39
+        String expected = "lgreen@mail.com";
40
+        customer.setEmail("lgreen@mail.com");
41
+        String actual = customer.getEmail();
42
+
43
+        //Then
44
+        Assert.assertEquals(expected, actual);
45
+
46
+    }
47
+
48
+
49
+    @Test
50
+    public void testShortDescription() {
51
+        //When
52
+        String expected = "PayPal Hayden Stewart hayden@mail.com";
53
+        String actual = customer2.getShortDescription();
54
+
55
+        //Then
56
+        Assert.assertEquals(expected, actual);
57
+
58
+    }
59
+
60
+}