Преглед изворни кода

shortDescription refactoring

Nicholas Maidanos пре 8 година
родитељ
комит
9c21048a24

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

25
     }
25
     }
26
 
26
 
27
     public String getShortDescription() {
27
     public String getShortDescription() {
28
-        StringBuilder sb = new StringBuilder();
29
-        sb.append("Check ");
30
-        sb.append(this.payerName + " ");
31
-        sb.append("****");
32
-        sb.append(lastFourDigits());
33
-        return sb.toString();
28
+        return String.format("Check %s ****%d", this.getPayerName(), lastFourDigits());
34
     }
29
     }
35
 
30
 
36
     public int lastFourDigits(){
31
     public int lastFourDigits(){

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

61
     }
61
     }
62
 
62
 
63
     public String getShortDescription() {
63
     public String getShortDescription() {
64
-        StringBuilder sb = new StringBuilder();
65
-
66
-        sb.append("CC ");
67
-        sb.append(this.payerName + " ");
68
-        sb.append(lastFourDigits() + " ");
69
-        sb.append(this.expiredMonth + "/" + this.expiredYear);
70
-
71
-        return sb.toString();
64
+        return String.format("CC %s %d %d/%d", this.payerName, this.lastFourDigits(), this.expiredMonth, this.expiredYear);
72
     }
65
     }
73
 
66
 
74
     public int lastFourDigits(){
67
     public int lastFourDigits(){

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

40
 
40
 
41
 
41
 
42
     public String getShortDescription() {
42
     public String getShortDescription() {
43
-        StringBuilder sb = new StringBuilder();
44
-        sb.append("PayPal ");
45
-        sb.append(this.payerName + " ");
46
-        sb.append(this.email);
47
-        return sb.toString();
43
+        return String.format("Paypal %s %s", this.payerName, this.email);
48
     }
44
     }
49
 
45
 
50
     public int compareTo(Payment o) {
46
     public int compareTo(Payment o) {

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

1
 package com.zipcoder.payment;
1
 package com.zipcoder.payment;
2
 
2
 
3
-import org.junit.jupiter.api.Test;
3
+import static org.junit.Assert.*;
4
+import org.junit.Test;
4
 
5
 
5
-import static org.junit.Assert.assertEquals;
6
-import static org.junit.Assert.assertThat;
7
-import static org.junit.jupiter.api.Assertions.*;
8
-
9
-class CheckTest {
6
+public class CheckTest {
10
 
7
 
11
     @Test
8
     @Test
12
-    void getId() {
9
+    public void getId() {
13
         //When
10
         //When
14
         Check ck = new Check();
11
         Check ck = new Check();
15
         ck.setId(4456);
12
         ck.setId(4456);
24
     }
21
     }
25
 
22
 
26
     @Test
23
     @Test
27
-    void getPayerName() {
24
+    public void getPayerName() {
28
         //When
25
         //When
29
         Check ck = new Check();
26
         Check ck = new Check();
30
         ck.setPayerName("Nicholas");
27
         ck.setPayerName("Nicholas");
38
     }
35
     }
39
 
36
 
40
     @Test
37
     @Test
41
-    void getShortDescription() {
38
+    public void getShortDescription() {
42
     }
39
     }
43
 
40
 
44
 
41
 
45
     @Test
42
     @Test
46
-    void getRoutingNumber() {
43
+    public void getRoutingNumber() {
47
         //When
44
         //When
48
         Check ck = new Check();
45
         Check ck = new Check();
49
         ck.setRoutingNumber("4532353");
46
         ck.setRoutingNumber("4532353");
58
     }
55
     }
59
 
56
 
60
     @Test
57
     @Test
61
-    void setRoutingNumber() {
58
+    public void setRoutingNumber() {
62
         //When
59
         //When
63
         Check ck = new Check();
60
         Check ck = new Check();
64
         ck.setRoutingNumber("4532353");
61
         ck.setRoutingNumber("4532353");
72
     }
69
     }
73
 
70
 
74
     @Test
71
     @Test
75
-    void setAccountNumber() {
72
+    public void setAccountNumber() {
76
         //When
73
         //When
77
         Check ck = new Check();
74
         Check ck = new Check();
78
         ck.setAccountNumber("4532353");
75
         ck.setAccountNumber("4532353");
86
     }
83
     }
87
 
84
 
88
     @Test
85
     @Test
89
-    void setPayerName() {
86
+    public void setPayerName() {
90
         //When
87
         //When
91
         Check ck = new Check();
88
         Check ck = new Check();
92
         ck.setPayerName("Nick M");
89
         ck.setPayerName("Nick M");
100
     }
97
     }
101
 
98
 
102
     @Test
99
     @Test
103
-    void setId() {
100
+    public void setId() {
104
         //When
101
         //When
105
         Check ck = new Check();
102
         Check ck = new Check();
106
         ck.setId(3423);
103
         ck.setId(3423);
115
     }
112
     }
116
 
113
 
117
     @Test
114
     @Test
118
-    void getAccountNumber() {
115
+    public void getAccountNumber() {
119
         //When
116
         //When
120
         Check ck = new Check();
117
         Check ck = new Check();
121
         ck.setAccountNumber("893456");
118
         ck.setAccountNumber("893456");
130
     }
127
     }
131
 
128
 
132
     @Test
129
     @Test
133
-    void getShortDescription1() {
130
+    public void getShortDescription1() {
134
         //When
131
         //When
135
         Check ck = new Check(4563, "Nicholas Maidanos", "45335665", "444545");
132
         Check ck = new Check(4563, "Nicholas Maidanos", "45335665", "444545");
136
 
133
 
143
     }
140
     }
144
 
141
 
145
     @Test
142
     @Test
146
-    void compareTo() {
143
+    public void compareTo() {
147
     }
144
     }
148
 }
145
 }

+ 5
- 6
src/test/java/com/zipcoder/payment/PaypalTest.java Прегледај датотеку

1
 package com.zipcoder.payment;
1
 package com.zipcoder.payment;
2
 
2
 
3
-import org.junit.jupiter.api.Test;
4
 
3
 
4
+import static org.junit.Assert.*;
5
+import org.junit.Test;
5
 
6
 
6
-import static org.junit.Assert.assertEquals;
7
-
8
-class PaypalTest {
7
+public class PaypalTest {
9
 
8
 
10
     @Test
9
     @Test
11
     void setId() {
10
     void setId() {
94
     @Test
93
     @Test
95
     void getShortDescription() {
94
     void getShortDescription() {
96
         //When
95
         //When
97
-        Paypal pp = new Paypal(78, "Nicholas Madianos", "nmaidanos@gmail.com");
96
+        Paypal pp = new Paypal(78, "Nicholas Maidanos", "nmaidanos@gmail.com");
98
 
97
 
99
         //Expect
98
         //Expect
100
-        String expect = "PayPal Nicholas Madianos nmaidanos@gmail.com";
99
+        String expect = "PayPal Nicholas Maidanos nmaidanos@gmail.com";
101
 
100
 
102
         //Actual
101
         //Actual
103
         String actual = pp.getShortDescription();
102
         String actual = pp.getShortDescription();