Browse Source

refactored some of my test classes. Im think im getting better at TDD

Nicholas Maidanos 8 years ago
parent
commit
69f842aab9

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

25
     }
25
     }
26
 
26
 
27
     public String getShortDescription() {
27
     public String getShortDescription() {
28
-        return String.format("Check %s ****%d", this.getPayerName(), lastFourDigits());
28
+        return String.format("Check %s ****%d\n", this.getPayerName(), lastFourDigits());
29
     }
29
     }
30
 
30
 
31
     public int lastFourDigits(){
31
     public int lastFourDigits(){

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

61
     }
61
     }
62
 
62
 
63
     public String getShortDescription() {
63
     public String getShortDescription() {
64
-        return String.format("CC %s %d %d/%d", this.payerName, this.lastFourDigits(), this.expiredMonth, this.expiredYear);
64
+        return String.format("CC %s %d %d/%d\n", this.payerName, this.lastFourDigits(), this.expiredMonth, this.expiredYear);
65
     }
65
     }
66
 
66
 
67
     public int lastFourDigits(){
67
     public int lastFourDigits(){

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

40
 
40
 
41
 
41
 
42
     public String getShortDescription() {
42
     public String getShortDescription() {
43
-        return String.format("Paypal %s %s", this.payerName, this.email);
43
+        return String.format("Paypal %s %s\n", this.payerName, this.email);
44
     }
44
     }
45
 
45
 
46
     public int compareTo(Payment o) {
46
     public int compareTo(Payment o) {

+ 39
- 58
src/test/java/com/zipcoder/payment/CheckTest.java View File

1
 package com.zipcoder.payment;
1
 package com.zipcoder.payment;
2
 
2
 
3
 import static org.junit.Assert.*;
3
 import static org.junit.Assert.*;
4
+import org.junit.Before;
4
 import org.junit.Test;
5
 import org.junit.Test;
5
 
6
 
6
 public class CheckTest {
7
 public class CheckTest {
7
 
8
 
9
+    Check ck;
10
+
11
+    @Before
12
+    public void before(){
13
+        this.ck = new Check(45, "Nicholas M", "445784", "4451884");
14
+    }
15
+
8
     @Test
16
     @Test
9
     public void getId() {
17
     public void getId() {
10
-        //When
11
-        Check ck = new Check();
12
-        ck.setId(4456);
13
-
14
         //Expect
18
         //Expect
15
-        long expected = 4456;
19
+        long expected = 45;
16
 
20
 
17
         //Actual
21
         //Actual
18
         long actual =  ck.getId();
22
         long actual =  ck.getId();
19
-
20
         assertEquals(expected, actual);
23
         assertEquals(expected, actual);
21
     }
24
     }
22
 
25
 
23
     @Test
26
     @Test
24
-    public void getPayerName() {
27
+    public void setId(){
25
         //When
28
         //When
26
-        Check ck = new Check();
27
-        ck.setPayerName("Nicholas");
29
+        ck.setId(50);
28
 
30
 
29
         //Expect
31
         //Expect
30
-        String expected = "Nicholas";
32
+        long expect = 50;
31
 
33
 
32
         //Actual
34
         //Actual
33
-        String acual = ck.getPayerName();
34
-        assertEquals(expected, acual);
35
+        long actual = ck.getId();
36
+        assertEquals(expect, actual);
35
     }
37
     }
36
 
38
 
37
     @Test
39
     @Test
38
-    public void getShortDescription() {
39
-    }
40
+    public void getPayerName() {
41
+        //Expect
42
+        String expected = "Nicholas M";
43
+
44
+        //Actual
45
+        String actual = ck.getPayerName();
40
 
46
 
47
+        assertEquals(expected, actual);
48
+    }
41
 
49
 
42
     @Test
50
     @Test
43
-    public void getRoutingNumber() {
51
+    public void setPayerName(){
44
         //When
52
         //When
45
-        Check ck = new Check();
46
-        ck.setRoutingNumber("4532353");
53
+        ck.setPayerName("Dan Smith");
47
 
54
 
48
         //Expect
55
         //Expect
49
-        String expected = "4532353";
56
+        String expect = "Dan Smith";
57
+
58
+        //Actual
59
+        String actual = ck.getPayerName();
60
+
61
+        assertEquals(expect, actual);
62
+    }
63
+
64
+    @Test
65
+    public void getRoutingNumber() {
66
+        //Expect
67
+        String expected = "445784";
50
 
68
 
51
         //Actual
69
         //Actual
52
         String actual = ck.getRoutingNumber();
70
         String actual = ck.getRoutingNumber();
57
     @Test
75
     @Test
58
     public void setRoutingNumber() {
76
     public void setRoutingNumber() {
59
         //When
77
         //When
60
-        Check ck = new Check();
61
         ck.setRoutingNumber("4532353");
78
         ck.setRoutingNumber("4532353");
62
 
79
 
63
         //Expect
80
         //Expect
71
     @Test
88
     @Test
72
     public void setAccountNumber() {
89
     public void setAccountNumber() {
73
         //When
90
         //When
74
-        Check ck = new Check();
75
         ck.setAccountNumber("4532353");
91
         ck.setAccountNumber("4532353");
76
 
92
 
77
         //Expect
93
         //Expect
83
     }
99
     }
84
 
100
 
85
     @Test
101
     @Test
86
-    public void setPayerName() {
87
-        //When
88
-        Check ck = new Check();
89
-        ck.setPayerName("Nick M");
90
-
91
-        //Expect
92
-        String expected = "Nick M";
93
-
94
-        //Actual
95
-        String actual = ck.getPayerName();
96
-        assertEquals(expected,actual);
97
-    }
98
-
99
-    @Test
100
-    public void setId() {
101
-        //When
102
-        Check ck = new Check();
103
-        ck.setId(3423);
104
-
105
-        //Expect
106
-        long expected = 3423;
107
-
108
-        //Actual
109
-        long actual =  ck.getId();
110
-
111
-        assertEquals(expected, actual);
112
-    }
113
-
114
-    @Test
115
     public void getAccountNumber() {
102
     public void getAccountNumber() {
116
-        //When
117
-        Check ck = new Check();
118
-        ck.setAccountNumber("893456");
119
         //Expect
103
         //Expect
120
-        String expected = "893456";
104
+        String expected = "4451884";
121
 
105
 
122
         //Actual
106
         //Actual
123
         String actual = ck.getAccountNumber();
107
         String actual = ck.getAccountNumber();
127
     }
111
     }
128
 
112
 
129
     @Test
113
     @Test
130
-    public void getShortDescription1() {
131
-        //When
132
-        Check ck = new Check(4563, "Nicholas Maidanos", "45335665", "444545");
133
-
114
+    public void getShortDescriptionTest() {
134
         //Expect
115
         //Expect
135
-        String expected = "Check Nicholas Maidanos ****4545";
116
+        String expected = "Check Nicholas M ****1884\n";
136
 
117
 
137
         //Actual
118
         //Actual
138
         String actual = ck.getShortDescription();
119
         String actual = ck.getShortDescription();

+ 39
- 43
src/test/java/com/zipcoder/payment/CreditCardTest.java View File

7
 
7
 
8
 public class CreditCardTest {
8
 public class CreditCardTest {
9
 
9
 
10
+    CreditCard cc;
11
+
12
+    @Before
13
+    public void begin(){
14
+        this.cc = new CreditCard(12, 4111131,"Nicholas Maidanos", 4, 2011);
15
+    }
16
+
10
     @Test
17
     @Test
11
     public void getIdTest(){
18
     public void getIdTest(){
12
-        //When
13
-        CreditCard cc = new CreditCard();
14
-        cc.setId(100);
15
-
16
         //Expect
19
         //Expect
17
-        long expected = 100;
20
+        long expected = 12;
18
 
21
 
19
         //Actual
22
         //Actual
20
         long actual =  cc.getId();
23
         long actual =  cc.getId();
25
     @Test
28
     @Test
26
     public void setIdTest(){
29
     public void setIdTest(){
27
         //When
30
         //When
28
-        CreditCard cc = new CreditCard();
29
         cc.setId(100);
31
         cc.setId(100);
30
 
32
 
31
         //Expect
33
         //Expect
40
 
42
 
41
     @Test
43
     @Test
42
     public void getNameTest(){
44
     public void getNameTest(){
43
-        //When
44
-        CreditCard cc = new CreditCard();
45
-        cc.setPayerName("Nicholas Maidanos");
46
-
47
         //Expect
45
         //Expect
48
         String expected = "Nicholas Maidanos";
46
         String expected = "Nicholas Maidanos";
49
 
47
 
54
     }
52
     }
55
 
53
 
56
     @Test
54
     @Test
57
-    public void SetNumTest(){
55
+    public void setNameTest(){
56
+        //When
57
+        cc.setPayerName("Dan Smith");
58
+
59
+        //Expect
60
+        String expect = "Dan Smith";
61
+
62
+        //Actual
63
+        String actual = cc.getPayerName();
64
+
65
+        assertEquals(expect, actual);
66
+    }
67
+
68
+    @Test
69
+    public void getNumTest(){
70
+        //Expect
71
+        long expected = 4111131;
72
+
73
+        //Actual
74
+        long actual = cc.getNumber();
75
+
76
+        assertEquals(expected, actual);
77
+    }
78
+
79
+    @Test
80
+    public void setNumTest(){
58
         //When
81
         //When
59
-        CreditCard cc = new CreditCard();
60
         cc.setNumber(411111111);
82
         cc.setNumber(411111111);
61
 
83
 
62
         //Expect
84
         //Expect
70
 
92
 
71
     @Test
93
     @Test
72
     public void getMonthTest(){
94
     public void getMonthTest(){
73
-        //When
74
-        CreditCard cc = new CreditCard();
75
-        cc.setExpiredMonth(12);
76
-
77
         //Expect
95
         //Expect
78
-        int expected = 12;
96
+        int expected = 4;
79
 
97
 
80
         //Actual
98
         //Actual
81
         int actual =  cc.getExpiredMonth();
99
         int actual =  cc.getExpiredMonth();
86
     @Test
104
     @Test
87
     public void setMonthTest(){
105
     public void setMonthTest(){
88
         //When
106
         //When
89
-        CreditCard cc = new CreditCard();
90
         cc.setExpiredMonth(12);
107
         cc.setExpiredMonth(12);
91
 
108
 
92
         //Expect
109
         //Expect
99
     }
116
     }
100
 
117
 
101
     @Test
118
     @Test
102
-    public void setYearTest(){
103
-        //When
104
-        CreditCard cc = new CreditCard();
105
-        cc.setExpiredYear(1989);
106
-
119
+    public void getYearTest(){
107
         //Expect
120
         //Expect
108
-        int expected = 1989;
121
+        int expected = 2011;
109
 
122
 
110
         //Actual
123
         //Actual
111
         int actual =  cc.getExpiredYear();
124
         int actual =  cc.getExpiredYear();
114
     }
127
     }
115
 
128
 
116
     @Test
129
     @Test
117
-    public void getYearTest(){
130
+    public void setYearTest(){
118
         //When
131
         //When
119
-        CreditCard cc = new CreditCard();
120
         cc.setExpiredYear(1989);
132
         cc.setExpiredYear(1989);
121
 
133
 
122
         //Expect
134
         //Expect
130
 
142
 
131
     @Test
143
     @Test
132
     public void getAndShortDescriptionTest(){
144
     public void getAndShortDescriptionTest(){
133
-        //When
134
-        CreditCard cc = new CreditCard(12, 4111131,"Nicholas Maidanos", 4, 11);
135
-
136
         //Expect
145
         //Expect
137
-        String expected = "CC Nicholas Maidanos 1131 4/11";
146
+        String expected = "CC Nicholas Maidanos 1131 4/2011\n";
138
 
147
 
139
         //Actual
148
         //Actual
140
         String actual = cc.getShortDescription();
149
         String actual = cc.getShortDescription();
142
     }
151
     }
143
 
152
 
144
     @Test
153
     @Test
145
-    public void testGetLastFourDigits(){
146
-        //Given
147
-        CreditCard cc = new CreditCard();
148
-        cc.setNumber(888999);
149
-        Integer expected = 8999;
150
-
151
-        //When
152
-        Integer actual = cc.lastFourDigits();
153
-        assertEquals(expected, actual);
154
-
155
-    }
156
-
157
-    @Test
158
     public void compareToTest() {
154
     public void compareToTest() {
159
         //Given
155
         //Given
160
         Payment cc = new CreditCard(12, 4111131,"Nicholas Maidanos", 4, 11);
156
         Payment cc = new CreditCard(12, 4111131,"Nicholas Maidanos", 4, 11);

+ 27
- 36
src/test/java/com/zipcoder/payment/PaypalTest.java View File

2
 
2
 
3
 
3
 
4
 import static org.junit.Assert.*;
4
 import static org.junit.Assert.*;
5
+import org.junit.Before;
5
 import org.junit.Test;
6
 import org.junit.Test;
6
 
7
 
7
 public class PaypalTest {
8
 public class PaypalTest {
8
 
9
 
10
+    Paypal pp;
11
+
12
+    @Before
13
+    public void setup(){
14
+        this.pp = new Paypal(50, "Nicholas Maidanos", "nmaidanos@gmail.com");
15
+    }
16
+
9
     @Test
17
     @Test
10
-    void setId() {
18
+    public void setId() {
11
         //When
19
         //When
12
-        Paypal pp = new Paypal();
13
-        pp.setId(75);
20
+        pp.setId(48);
14
 
21
 
15
         //Expect
22
         //Expect
16
-        long expect = 75;
23
+        long expect = 48;
17
 
24
 
18
         //Actual
25
         //Actual
19
-        long actual = pp.getId();
26
+        long actual = this.pp.getId();
20
         assertEquals(expect, actual);
27
         assertEquals(expect, actual);
21
     }
28
     }
22
 
29
 
23
     @Test
30
     @Test
24
-    void getId() {
25
-        //When
26
-        Paypal pp = new Paypal();
27
-        pp.setId(75);
28
-
31
+    public void getId() {
29
         //Expect
32
         //Expect
30
-        long expect = 75;
33
+        long expect = 50;
31
 
34
 
32
         //Actual
35
         //Actual
33
         long actual = pp.getId();
36
         long actual = pp.getId();
35
     }
38
     }
36
 
39
 
37
     @Test
40
     @Test
38
-    void setPayerName() {
41
+    public void setPayerName() {
39
         //When
42
         //When
40
-        Paypal pp =  new Paypal();
41
-        pp.setPayerName("Nicholas Maidanos");
43
+        pp.setPayerName("Dan Smith");
42
 
44
 
43
         //Expect
45
         //Expect
44
-        String expect = "Nicholas Maidanos";
46
+        String expect = "Dan Smith";
45
 
47
 
46
         //Actual
48
         //Actual
47
         String actual = pp.getPayerName();
49
         String actual = pp.getPayerName();
49
     }
51
     }
50
 
52
 
51
     @Test
53
     @Test
52
-    void getPayerName() {
53
-        //When
54
-        Paypal pp =  new Paypal();
55
-        pp.setPayerName("Nicholas Maidanos");
56
-
54
+    public void getPayerName() {
57
         //Expect
55
         //Expect
58
         String expect = "Nicholas Maidanos";
56
         String expect = "Nicholas Maidanos";
59
 
57
 
63
     }
61
     }
64
 
62
 
65
     @Test
63
     @Test
66
-    void setEmail() {
64
+    public void setEmail() {
67
         //When
65
         //When
68
-        Paypal pp = new Paypal();
69
-        pp.setEmail("example@email.com");
66
+        pp.setEmail("desk@email.com");
70
 
67
 
71
         //Expect
68
         //Expect
72
-        String expect = "example@email.com";
69
+        String expect = "desk@email.com";
73
 
70
 
74
         //Actual
71
         //Actual
75
         String actual = pp.getEmail();
72
         String actual = pp.getEmail();
77
     }
74
     }
78
 
75
 
79
     @Test
76
     @Test
80
-    void getEmail() {
81
-        //When
82
-        Paypal pp = new Paypal();
83
-        pp.setEmail("example@email.com");
84
-
77
+    public void getEmail() {
85
         //Expect
78
         //Expect
86
-        String expect = "example@email.com";
79
+        String expect = "nmaidanos@gmail.com";
87
 
80
 
88
         //Actual
81
         //Actual
89
         String actual = pp.getEmail();
82
         String actual = pp.getEmail();
91
     }
84
     }
92
 
85
 
93
     @Test
86
     @Test
94
-    void getShortDescription() {
95
-        //When
96
-        Paypal pp = new Paypal(78, "Nicholas Maidanos", "nmaidanos@gmail.com");
97
-
87
+    public void getShortDescription() {
98
         //Expect
88
         //Expect
99
-        String expect = "PayPal Nicholas Maidanos nmaidanos@gmail.com";
89
+        String expect = "Paypal Nicholas Maidanos nmaidanos@gmail.com\n";
100
 
90
 
101
         //Actual
91
         //Actual
102
         String actual = pp.getShortDescription();
92
         String actual = pp.getShortDescription();
105
     }
95
     }
106
 
96
 
107
     @Test
97
     @Test
108
-    void compareTo() {
98
+    public void compareTo() {
99
+
109
     }
100
     }
110
 }
101
 }