Browse Source

test3ToArray

Nick Satinover 6 years ago
parent
commit
061975f102
1 changed files with 192 additions and 0 deletions
  1. 192
    0
      Checkbook/src/test/java/CheckbookTest.java

+ 192
- 0
Checkbook/src/test/java/CheckbookTest.java View File

@@ -1,3 +1,10 @@
1
+import junit.framework.Assert;
2
+import org.junit.Test;
3
+
4
+import javax.swing.text.html.HTMLDocument;
5
+
6
+import java.util.stream.Stream;
7
+
1 8
 import static org.junit.Assert.*;
2 9
 
3 10
 public class CheckbookTest {
@@ -21,11 +28,196 @@ public class CheckbookTest {
21 28
         this.checkbook = new Checkbook(owner, 1000.00);
22 29
     }
23 30
 
31
+    @Test
32
+    public void test1Size(){
33
+        checkbook.add(debit);
34
+        int expected = 1;
35
+        int actual = checkbook.size();
36
+        Assert.assertEquals(expected, actual);
37
+    }
38
+
39
+    @Test
40
+    public void test2Size(){
41
+        checkbook.add(debit);
42
+        checkbook.add(credit);
43
+        int expected = 2;
44
+        int actual = checkbook.size();
45
+        Assert.assertEquals(expected, actual);
46
+    }
47
+
48
+    @Test
49
+    public void test3Size(){
50
+        checkbook.add(debit);
51
+        checkbook.remove(debit);
52
+        int expected = 0;
53
+        int actual = checkbook.size();
54
+        Assert.assertEquals(expected, actual);
55
+    }
56
+//
57
+    @Test
58
+    public void test1IsEmpty(){
59
+        checkbook.add(debit);
60
+        boolean expected = false;
61
+        boolean actual = checkbook.isEmpty();
62
+        Assert.assertEquals(expected, actual);
63
+    }
64
+
65
+    @Test
66
+    public void test2IsEmpty(){
67
+        checkbook.add(debit);
68
+        boolean expected = false;
69
+        boolean actual = checkbook.isEmpty();
70
+        Assert.assertEquals(expected, actual);
71
+    }
72
+
73
+    @Test
74
+    public void test3IsEmpty(){
75
+        boolean expected = true;
76
+        boolean actual = checkbook.isEmpty();
77
+        Assert.assertEquals(expected, actual);
78
+    }
79
+//
80
+
81
+    @Test
82
+    public void test1Contains(){
83
+        checkbook.add(debit);
84
+        boolean expected = true;
85
+        boolean actual = checkbook.contains(debit);
86
+        Assert.assertEquals(expected, actual);
87
+    }
88
+
89
+    @Test
90
+    public void test2Contains(){
91
+        checkbook.add(debit);
92
+        boolean expected = false;
93
+        boolean actual = checkbook.contains(credit);
94
+        Assert.assertEquals(expected, actual);
95
+    }
96
+
97
+    @Test
98
+    public void test3Contains(){
99
+        checkbook.add(credit);
100
+        checkbook.add(debit);
101
+        boolean expected = true;
102
+        boolean actual = checkbook.contains(credit);
103
+        boolean actual2 = checkbook.contains(debit);
104
+        Assert.assertEquals(expected, actual);
105
+        Assert.assertEquals(expected, actual2);
106
+    }
107
+
108
+    @Test
109
+    public void test1Add(){
110
+        checkbook.add(debit);
111
+        int expected = 1;
112
+        int actual = checkbook.size();
113
+        Assert.assertEquals(expected, actual);
114
+    }
115
+
116
+    @Test
117
+    public void test2Add(){
118
+        checkbook.add(debit);
119
+        boolean expected = true;
120
+        boolean actual = checkbook.contains(debit);
121
+        Assert.assertEquals(expected, actual);
122
+    }
123
+
124
+    @Test
125
+    public void test3Add(){
126
+        checkbook.add(credit);
127
+        boolean expected = true;
128
+        boolean actual = checkbook.contains(credit);
129
+        Assert.assertEquals(expected, actual);
130
+    }
131
+
132
+    @Test
133
+    public void test1Remove(){
134
+        checkbook.add(debit);
135
+        checkbook.remove(debit);
136
+        int expected = 0;
137
+        int actual = checkbook.size();
138
+        Assert.assertEquals(expected, actual);
139
+    }
140
+
141
+    @Test
142
+    public void test2Remove(){
143
+        checkbook.add(debit);
144
+        boolean expected = false;
145
+        boolean actual = checkbook.remove(credit);
146
+        Assert.assertEquals(expected, actual);
147
+    }
148
+
149
+    @Test
150
+    public void test3Remove(){
151
+        checkbook.add(debit);
152
+        boolean expected = true;
153
+        boolean actual = checkbook.remove(debit);
154
+        Assert.assertEquals(expected, actual);
155
+    }
156
+
157
+    @Test
158
+    public void test1Iterator(){
159
+        checkbook.add(debit);
160
+        checkbook.add(credit);
161
+        String expected = "Itr";
162
+        String actual = checkbook.iterator().getClass().getSimpleName();
163
+        Assert.assertEquals(expected, actual);
164
+    }
165
+
166
+    @Test
167
+    public void test2Iterator(){
168
+        checkbook.add(debit);
169
+        String expected = "This is a Debit";
170
+        String actual = checkbook.iterator().next().getMemo();
171
+        Assert.assertEquals(expected, actual);
172
+    }
173
+
174
+    @Test
175
+    public void test3Iterator(){
176
+        checkbook.add(debit);
177
+        Payee expected = payeeDebit;
178
+        Payee actual = checkbook.iterator().next().getPayee();
179
+        Assert.assertEquals(expected, actual);
180
+    }
181
+
182
+    @Test
183
+    public void test1ToArray(){
184
+        checkbook.add(debit);
185
+        checkbook.add(credit);
186
+        String expected = "Transaction[]";
187
+        String actual = checkbook.toArray().getClass().getSimpleName();
188
+        Assert.assertEquals(expected, actual);
189
+    }
190
+
191
+    @Test
192
+    public void test2ToArray(){
193
+        checkbook.add(debit);
194
+        double expected = 100.50;
195
+        Transaction[] ret = checkbook.toArray();
196
+        double actual = ret[0].getAmount();
197
+        Assert.assertEquals(expected, actual);
198
+    }
199
+
200
+    @Test
201
+    public void test3ToArray(){
202
+        checkbook.add(debit);
203
+        checkbook.add(credit);
204
+        String expected = payeeCredit.getGivenName();
205
+        Transaction[] ret = checkbook.toArray();
206
+        String actual = ret[1].getPayee().getGivenName();
207
+        Assert.assertEquals(expected, actual);
208
+    }
209
+
210
+
211
+
212
+
213
+
214
+
24 215
     @org.junit.After
25 216
     public void tearDown() throws Exception {
26 217
         System.out.println("Running: TearDown");
27 218
         checkbook = null;
28 219
         assertNull(checkbook);
29 220
         if (checkbook == null) System.out.println("Checkbook null, TearDown complete.");
221
+        else System.out.println("TearDown NOT successful, checkbook did not evaluate to NULL");
30 222
     }
31 223
 }