Mexi пре 8 година
родитељ
комит
43ca15312a


BIN
src/main/.DS_Store Прегледај датотеку


BIN
src/main/java/.DS_Store Прегледај датотеку


BIN
src/main/java/com/.DS_Store Прегледај датотеку


BIN
src/main/java/com/zipcoder/.DS_Store Прегледај датотеку


+ 23
- 9
src/main/java/com/zipcoder/payment/Check.java Прегледај датотеку

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

+ 36
- 10
src/main/java/com/zipcoder/payment/CreditCard.java Прегледај датотеку

@@ -1,3 +1,4 @@
1
+
1 2
 package com.zipcoder.payment;
2 3
 
3 4
 public class CreditCard implements Payment {
@@ -9,44 +10,69 @@ public class CreditCard implements Payment {
9 10
 
10 11
 
11 12
     public Long getId() {
13
+
12 14
         return this.id;
13 15
     }
14 16
 
15
-    public void setId(long id){
17
+    public void setId(long id) {
16 18
         this.id = id;
17 19
 
18 20
     }
19 21
 
20 22
     public String getPayerName() {
23
+
21 24
         return this.payerName;
22 25
     }
23 26
 
24
-    public void setPayerName(String payerName){
27
+    public void setPayerName(String payerName) {
28
+
25 29
         this.payerName = payerName;
26 30
     }
31
+
27 32
     public String getShortDescription() {
28 33
 
29 34
 
30 35
         return "CC " + getPayerName() + " " + getNumber() + " " + getExpiredMonth() + "/" + getExpiredYear();
31 36
     }
32
-    public String getNumber(){
37
+
38
+    public String getNumber() {
39
+
33 40
         return this.number;
34 41
     }
35
-    public void setNumber(String number){
42
+
43
+    public void setNumber(String number) {
36 44
         this.number = number;
37 45
 
38 46
     }
39
-    public int getExpiredMonth(){
47
+
48
+    public int getExpiredMonth() {
49
+
40 50
         return this.expiredMonth;
41 51
     }
42
-    public void setExpiredMonth(int expiredMonth){
43
-     this.expiredMonth = expiredMonth;
52
+
53
+    public void setExpiredMonth(int expiredMonth) {
54
+
55
+        this.expiredMonth = expiredMonth;
44 56
     }
45
-    public int getExpiredYear(){
46
-     return this.expiredYear;
57
+
58
+    public int getExpiredYear() {
59
+
60
+        return this.expiredYear;
47 61
     }
48 62
 
49
-    public void setExpiredYear(int expiredYear){
63
+    public void setExpiredYear(int expiredYear) {
64
+
50 65
         this.expiredYear = expiredYear;
51 66
     }
67
+
68
+
69
+    public int compareTo(Payment o) {
70
+
71
+        int n = this.getShortDescription().compareTo(o.getShortDescription());
72
+        return n;
73
+
74
+        }
75
+
76
+
77
+
52 78
 }

+ 43
- 0
src/main/java/com/zipcoder/payment/PayPal.java Прегледај датотеку

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

+ 1
- 1
src/main/java/com/zipcoder/payment/Payment.java Прегледај датотеку

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

+ 10
- 0
src/main/java/com/zipcoder/payment/PaymentSortByPayer.java Прегледај датотеку

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

BIN
src/test/.DS_Store Прегледај датотеку


BIN
src/test/java/.DS_Store Прегледај датотеку


BIN
src/test/java/com/.DS_Store Прегледај датотеку


BIN
src/test/java/com/zipcoder/.DS_Store Прегледај датотеку


+ 61
- 3
src/test/java/com/zipcoder/payment/CheckTest.java Прегледај датотеку

@@ -1,28 +1,86 @@
1 1
 package com.zipcoder.payment;
2 2
 import org.junit.Assert;
3
+import org.junit.Before;
3 4
 import org.junit.Test;
4 5
 
5 6
 
7
+
6 8
 public class CheckTest {
7 9
 
10
+    Check check;
11
+    @Before
12
+    public void start(){
13
+        check = new Check(12312l, "Jo","33775", "8800");
14
+
15
+    }
16
+
8 17
     @Test
9 18
     public void testGetId() {
10
-        Check check = new Check();
11 19
         long expected = 12312;
12
-        check.setId(12312);
13 20
         long actual = check.getId();
14 21
         Assert.assertEquals(expected,actual);
15 22
     }
16 23
 
17 24
     @Test
18 25
     public void testSetId(){
19
-        Check check = new Check();
20 26
         check.setId(12345);
21 27
         long expected = 12345;
22 28
         long actual = check.getId();
23 29
         Assert.assertEquals(expected,actual);}
24 30
 
25 31
 
32
+    @Test
33
+    public void getPayerName() {
34
+        String expected = "Jo";
35
+        String actual = check.getPayerName();
36
+        Assert.assertEquals(expected,actual);
37
+    }
38
+
39
+    @Test
40
+    public void setPayerName() {
41
+        check.setPayerName("yes");
42
+        String expected = "yes";
43
+        String actual = check.getPayerName();
44
+        Assert.assertEquals(expected,actual);
45
+    }
46
+
47
+    @Test
48
+    public void getRoutingNumber() {
49
+        String expected = "33775";
50
+        String actual = check.getRoutingNumber();
51
+        Assert.assertEquals(expected,actual);
52
+    }
53
+
54
+    @Test
55
+    public void setRoutingNumber() {
56
+        check.setRoutingNumber("22322");
57
+        String expected = "22322";
58
+        String actual = check.getRoutingNumber();
59
+        Assert.assertEquals(expected,actual);
60
+    }
61
+
62
+    @Test
63
+    public void getAccountNumber() {
64
+        String expected = "8800";
65
+        String actual = check.getAccountNumber();
66
+        Assert.assertEquals(expected,actual);
67
+    }
68
+
69
+    @Test
70
+    public void setAccountNumber() {
71
+        check.setAccountNumber("2200");
72
+        String expected = "2200";
73
+        String actual = check.getAccountNumber();
74
+        Assert.assertEquals(expected,actual);
75
+    }
76
+
77
+    @Test
78
+    public void getShortDescription() {
79
+    }
80
+
81
+    @Test
82
+    public void compareTo() {
83
+    }
26 84
 }
27 85
 
28 86
 

+ 111
- 9
src/test/java/com/zipcoder/payment/CreditCardTest.java Прегледај датотеку

@@ -1,8 +1,16 @@
1 1
 package com.zipcoder.payment;
2 2
 import org.junit.Assert;
3
+import org.junit.Before;
3 4
 import org.junit.Test;
4 5
 public class CreditCardTest {
5 6
 
7
+    CreditCard cc;
8
+
9
+    @Before
10
+    public void setup(){
11
+        cc = new CreditCard();
12
+    }
13
+
6 14
     @Test
7 15
     public void testGetId() {
8 16
     CreditCard creditCard = new CreditCard();
@@ -24,44 +32,138 @@ public class CreditCardTest {
24 32
 
25 33
     @Test
26 34
     public void testGetPayerName() {
35
+        CreditCard creditCard = new CreditCard();
36
+        creditCard.setPayerName("Jo");
37
+        String expected = "Jo";
38
+        String actual = creditCard.getPayerName();
39
+        Assert.assertEquals(expected,actual);
27 40
     }
28 41
 
29
-    @Test
30
-    public void testGetShortDescription() {
31
-    }
42
+//    @Test
43
+//    public void testGetShortDescription() {
44
+//        CreditCard creditCard = new CreditCard("whoever", "1122", 12, 2019);
45
+//        PayPal payPal = new PayPal();
46
+//
47
+//    }
48
+
32 49
 
33 50
 
34 51
 
35
-    @Test
36
-    public void getPayerName() {
37
-    }
38 52
 
39 53
     @Test
40
-    public void setPayerName() {
54
+    public void testSetPayerName() {
55
+        CreditCard creditCard = new CreditCard();
56
+        String expected = "Jo";
57
+        creditCard.setPayerName("Jo");
58
+        String actual = creditCard.getPayerName();
59
+        Assert.assertEquals(expected,actual);
41 60
     }
42 61
 
43 62
 
44 63
     @Test
45
-    public void getNumber() {
64
+    public void testGetNumber() {
65
+        CreditCard creditCard = new CreditCard();
66
+        String expected = "12345";
67
+        creditCard.setNumber("12345");
68
+        String actual = creditCard.getNumber();
69
+        Assert.assertEquals(expected, actual);
46 70
     }
47 71
 
48 72
     @Test
49
-    public void setNumber() {
73
+    public void testSetNumber() {
74
+        CreditCard creditCard = new CreditCard();
75
+        creditCard.setNumber("12345");
76
+        String expected = "12345";
77
+        String actual = creditCard.getNumber();
78
+        Assert.assertEquals(expected, actual);
50 79
     }
51 80
 
52 81
     @Test
53 82
     public void getExpiredMonth() {
83
+        CreditCard creditCard = new CreditCard();
84
+        creditCard.setExpiredMonth(12);
85
+        int expected = 12;
86
+        int actual = creditCard.getExpiredMonth();
87
+        Assert.assertEquals(expected, actual);
54 88
     }
55 89
 
56 90
     @Test
57 91
     public void setExpiredMonth() {
92
+        CreditCard creditCard = new CreditCard();
93
+        int expected = 1;
94
+        creditCard.setExpiredMonth(1);
95
+        int actual = creditCard.getExpiredMonth();
96
+        Assert.assertEquals(expected, actual);
58 97
     }
59 98
 
60 99
     @Test
61 100
     public void getExpiredYear() {
101
+        CreditCard creditCard = new CreditCard();
102
+        int expected = 2008;
103
+        creditCard.setExpiredYear(2008);
104
+        int actual = creditCard.getExpiredYear();
105
+        Assert.assertEquals(expected, actual);
62 106
     }
63 107
 
64 108
     @Test
65 109
     public void setExpiredYear() {
110
+        CreditCard creditCard = new CreditCard();
111
+        creditCard.setExpiredYear(2008);
112
+        int expected = 2008;
113
+        int actual = creditCard.getExpiredYear();
114
+        Assert.assertEquals(expected, actual);
115
+
116
+
117
+
66 118
     }
119
+
120
+    @Test
121
+    public void compareToWhenPayment1ComesBeforePayment2() {
122
+    CreditCard creditCard = new CreditCard();
123
+    PayPal payPal = new PayPal();
124
+    creditCard.setId(1234);
125
+    creditCard.setPayerName("Jo");
126
+    creditCard.setNumber("334455");
127
+    creditCard.setExpiredMonth(01);
128
+    creditCard.setExpiredYear(2012);
129
+    payPal.setId(1234);
130
+    payPal.setPayerName("Harris");
131
+    payPal.setEmail("harris@zipcode.com");
132
+    Assert.assertTrue(creditCard.compareTo(payPal)<0);
133
+    }
134
+
135
+    @Test
136
+    public void compareToWhenPayment2ComesBeforePayment1() {
137
+        CreditCard creditCard = new CreditCard();
138
+        CreditCard creditCard1 = new CreditCard();
139
+        creditCard.setId(1234);
140
+        creditCard.setPayerName("Jo");
141
+        creditCard.setNumber("334455");
142
+        creditCard.setExpiredMonth(01);
143
+        creditCard.setExpiredYear(2012);
144
+        creditCard1.setId(0001);
145
+        creditCard1.setPayerName("Harris");
146
+        creditCard1.setNumber("223344");
147
+        creditCard1.setExpiredMonth(01);
148
+        creditCard1.setExpiredYear(2013);
149
+        Assert.assertTrue(creditCard.compareTo(creditCard1)>0);
150
+    }
151
+    @Test
152
+    public void compareToWhenEquals(){
153
+        CreditCard creditCard = new CreditCard();
154
+        CreditCard creditCard1 = new CreditCard();
155
+        creditCard.setId(1234);
156
+        creditCard.setPayerName("Jo");
157
+        creditCard.setNumber("334455");
158
+        creditCard.setExpiredMonth(01);
159
+        creditCard.setExpiredYear(2012);
160
+        creditCard1.setId(1234);
161
+        creditCard1.setPayerName("Jo");
162
+        creditCard1.setNumber("334455");
163
+        creditCard1.setExpiredMonth(01);
164
+        creditCard1.setExpiredYear(2012);
165
+        Assert.assertTrue(creditCard.compareTo(creditCard1)==0);
166
+    }
167
+
168
+
67 169
 }

+ 69
- 0
src/test/java/com/zipcoder/payment/PayPalTest.java Прегледај датотеку

@@ -0,0 +1,69 @@
1
+package com.zipcoder.payment;
2
+import org.junit.Assert;
3
+import org.junit.Test;
4
+
5
+public class PayPalTest {
6
+
7
+    @Test
8
+    public void testGetId() {
9
+        PayPal payPal = new PayPal();
10
+        long expected = 12312;
11
+        payPal.setId(12312);
12
+        long actual = payPal.getId();
13
+        Assert.assertEquals(expected,actual);
14
+    }
15
+
16
+    @Test
17
+    public void testSetId() {
18
+        PayPal payPal = new PayPal();
19
+        payPal.setId(12345);
20
+        long expected = 12345;
21
+        long actual = payPal.getId();
22
+        Assert.assertEquals(expected, actual);
23
+    }
24
+
25
+    @Test
26
+    public void getPayerName() {
27
+        PayPal payPal = new PayPal();
28
+        String expected = "World";
29
+        payPal.setPayerName("World");
30
+        String actual = payPal.getPayerName();
31
+        Assert.assertEquals(expected, actual);
32
+    }
33
+
34
+    @Test
35
+    public void setPayerName() {
36
+        PayPal payPal = new PayPal();
37
+        payPal.setPayerName("World");
38
+        String expected = "World";
39
+        String actual = payPal.getPayerName();
40
+        Assert.assertEquals(expected, actual);
41
+    }
42
+
43
+
44
+    @Test
45
+    public void getEmail() {
46
+        PayPal payPal = new PayPal();
47
+        payPal.setEmail("whatever@gmail.com");
48
+        String expected = "whatever@gmail.com";
49
+        String actual = payPal.getEmail();
50
+        Assert.assertEquals(expected, actual);
51
+    }
52
+
53
+    @Test
54
+    public void setEmail() {
55
+        PayPal payPal = new PayPal();
56
+        String expected = "whatever@gmail.com";
57
+        payPal.setEmail("whatever@gmail.com");
58
+        String actual = payPal.getEmail();
59
+        Assert.assertEquals(expected, actual);
60
+    }
61
+
62
+    @Test
63
+    public void getShortDescription() {
64
+    }
65
+
66
+    @Test
67
+    public void compareTo() {
68
+    }
69
+}

+ 38
- 0
src/test/java/com/zipcoder/payment/PaymentSortByPayerTest.java Прегледај датотеку

@@ -0,0 +1,38 @@
1
+package com.zipcoder.payment;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+public class PaymentSortByPayerTest {
7
+
8
+    @Test
9
+    public void compareWhenPaymentEquals() {
10
+        CreditCard creditCard = new CreditCard();
11
+        CreditCard creditCard1 = new CreditCard();
12
+        creditCard.setPayerName("Jo");
13
+        creditCard1.setPayerName("Jo");
14
+        PaymentSortByPayer c = new PaymentSortByPayer();
15
+        Assert.assertTrue(c.compare(creditCard,creditCard1)==0);
16
+
17
+    }
18
+
19
+    @Test
20
+    public void compareWhenPayment1ComesBeforePayment2(){
21
+
22
+        CreditCard creditCard = new CreditCard();
23
+        CreditCard creditCard1 = new CreditCard();
24
+        creditCard.setPayerName("Bo");
25
+        creditCard1.setPayerName("Jo");
26
+        PaymentSortByPayer c = new PaymentSortByPayer();
27
+        Assert.assertTrue(c.compare(creditCard,creditCard1)<0);
28
+    }
29
+    @Test
30
+    public void compareWhenPayment1ComesAfterPayment2() {
31
+        CreditCard creditCard = new CreditCard();
32
+        CreditCard creditCard1 = new CreditCard();
33
+        creditCard.setPayerName("Jo");
34
+        creditCard1.setPayerName("Bo");
35
+        PaymentSortByPayer c = new PaymentSortByPayer();
36
+        Assert.assertTrue(c.compare(creditCard, creditCard1) > 0);
37
+    }
38
+}