KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junitx > framework > ArrayAssertTest


1 package junitx.framework;
2
3 import junit.framework.AssertionFailedError;
4 import junit.framework.TestCase;
5
6 /**
7  * @version $Revision: 1.5 $ $Date: 2003/01/20 10:44:50 $
8  * @author <a HREF="mailto:vbossica@users.sourceforge.net">Vladimir R. Bossicard</a>
9  */

10 public class ArrayAssertTest
11         extends TestCase {
12
13     public ArrayAssertTest(String JavaDoc name) {
14         super(name);
15     }
16
17     public void testSuccessAssertEquals1() {
18         Object JavaDoc a[] = null;
19         Object JavaDoc b[] = null;
20         ArrayAssert.assertEquals(a, b);
21     }
22
23     public void testSuccessAssertEquals2() {
24         Object JavaDoc a[] = {new Integer JavaDoc(1), new Integer JavaDoc(2)};
25         Object JavaDoc b[] = {new Integer JavaDoc(1), new Integer JavaDoc(2)};
26         ArrayAssert.assertEquals(a, b);
27     }
28
29     public void testSuccessAssertEquals3() {
30         Object JavaDoc a[] = {new Integer JavaDoc(1), null, new Integer JavaDoc(2)};
31         Object JavaDoc b[] = {new Integer JavaDoc(1), null, new Integer JavaDoc(2)};
32         ArrayAssert.assertEquals(a, b);
33     }
34
35     public void testSuccessAssertEquals4() {
36         Object JavaDoc a[] = {null};
37         Object JavaDoc b[] = {null};
38         ArrayAssert.assertEquals(a, b);
39     }
40
41     public void testFailAssertEquals1() {
42         Object JavaDoc a[] = null;
43         Object JavaDoc b[] = {new Integer JavaDoc(2)};
44         try {
45             ArrayAssert.assertEquals(a, b);
46         } catch (AssertionFailedError e) {
47             return;
48         }
49         fail();
50     }
51
52     public void testFailAssertEquals2() {
53         Object JavaDoc a[] = {new Integer JavaDoc(1)};
54         Object JavaDoc b[] = null;
55         try {
56             ArrayAssert.assertEquals(a, b);
57         } catch (AssertionFailedError e) {
58             return;
59         }
60         fail();
61     }
62
63     public void testFailAssertEquals3() {
64         Object JavaDoc a[] = {new Integer JavaDoc(1)};
65         Object JavaDoc b[] = {new Integer JavaDoc(2)};
66         try {
67             ArrayAssert.assertEquals(a, b);
68         } catch (AssertionFailedError e) {
69             return;
70         }
71         fail();
72     }
73
74     public void testFailAssertEquals4() {
75         Object JavaDoc a[] = {new Integer JavaDoc(1)};
76         Object JavaDoc b[] = {new Integer JavaDoc(1), new Integer JavaDoc(1)};
77         try {
78             ArrayAssert.assertEquals(a, b);
79         } catch (AssertionFailedError e) {
80             return;
81         }
82         fail();
83     }
84
85     public void testFailAssertEquals5() {
86         Object JavaDoc a[] = {new Integer JavaDoc(1), null};
87         Object JavaDoc b[] = {new Integer JavaDoc(1), new Integer JavaDoc(1)};
88         try {
89             ArrayAssert.assertEquals(a, b);
90         } catch (AssertionFailedError e) {
91             return;
92         }
93         fail();
94     }
95
96     public void testFailAssertEquals6() {
97         Object JavaDoc a[] = {new Integer JavaDoc(1), new Integer JavaDoc(1)};
98         Object JavaDoc b[] = {new Integer JavaDoc(1), null};
99         try {
100             ArrayAssert.assertEquals(a, b);
101         } catch (AssertionFailedError e) {
102             return;
103         }
104         fail();
105     }
106
107     public void testFailAssertEquals7() {
108         Object JavaDoc a[] = {new Integer JavaDoc(1), new Integer JavaDoc(1), new Integer JavaDoc(2)};
109         Object JavaDoc b[] = {new Integer JavaDoc(1), new Integer JavaDoc(2), new Integer JavaDoc(1)};
110         try {
111             ArrayAssert.assertEquals(a, b);
112         } catch (AssertionFailedError e) {
113             return;
114         }
115         fail();
116     }
117
118     public void testSuccessAssertEqualsDouble() {
119         double[] expected = new double[]{3.2, 1.3, 4.5, 5.63};
120         double[] actual = new double[]{3.2, 1.32, 4.6, 5.63};
121
122         ArrayAssert.assertEquals(expected, expected, 0);
123         ArrayAssert.assertEquals(expected, actual, .1);
124     }
125
126     public void testFailAssertEqualsDouble() {
127         double[] expected = new double[]{3.2, 1.3, 4.5, 5.63};
128         double[] actual = new double[]{3.2, 5.3, 4.5, 5.63};
129
130         try {
131             ArrayAssert.assertEquals(expected, actual, 0);
132         } catch (AssertionFailedError e) {
133             return;
134         }
135         fail();
136     }
137
138     public void testFailAssertEqualsDouble2() {
139         double[] expected = new double[]{3.2, 1.3, 4.5, 5.63};
140         double[] actual = new double[]{3.2, 5.3, 4.5, 5.63};
141
142         try {
143             ArrayAssert.assertEquals(expected, actual, 0);
144         } catch (AssertionFailedError e) {
145             return;
146         }
147         fail();
148     }
149
150     public void testSuccessAssertEqualsFloat() {
151         float[] expected = new float[]{3.2f, 1.3f, 4.5f, 5.63f};
152         float[] actual = new float[]{3.2f, 1.32f, 4.6f, 5.63f};
153
154         ArrayAssert.assertEquals(expected, expected, 0);
155         ArrayAssert.assertEquals(expected, actual, 0.1f);
156     }
157
158     public void testFailAssertEqualsFloat() {
159         float[] expected = new float[]{3.2f, 1.3f, 4.5f, 5.63f};
160         float[] actual = new float[]{3.2f, 5.3f, 4.5f, 5.63f};
161
162         try {
163             ArrayAssert.assertEquals(expected, actual, 0);
164         } catch (AssertionFailedError e) {
165             return;
166         }
167         fail();
168     }
169
170     public void testFailAssertEqualsFloat2() {
171         float[] expected = new float[]{3.2f, 1.3f, 4.5f, 5.63f};
172         float[] actual = new float[]{3.2f, 5.3f, 4.5f, 5.63f};
173
174         try {
175             ArrayAssert.assertEquals(expected, actual, 0.1f);
176             fail();
177         } catch (AssertionFailedError e) {
178             return;
179         }
180     }
181
182     public void testSuccessAssertEqualsLong() {
183         long[] expected = new long[]{32, 10393, -483092, 39898};
184         long[] actual = new long[]{32, 10393, -483092, 39898};
185
186         ArrayAssert.assertEquals(expected, actual);
187     }
188
189     public void testFailAssertEqualsLong() {
190         long[] expected = new long[]{32, 10393, -483092, 39898};
191         long[] notExpected = new long[]{31, 10394, 483092, 39898};
192
193         try {
194             ArrayAssert.assertEquals(expected, notExpected);
195         } catch (AssertionFailedError e) {
196             return;
197         }
198         fail();
199     }
200
201     public void testSuccessAssertEqualsInt() {
202         int[] expected = new int[]{32, 10393, -483092, 39898};
203         int[] actual = new int[]{32, 10393, -483092, 39898};
204
205         ArrayAssert.assertEquals(expected, actual);
206     }
207
208     public void testFaileAssertEqualsInt() {
209         int[] expected = new int[]{32, 10393, -483092, 39898};
210         int[] notExpected = new int[]{31, 10394, 483092, 39898};
211
212         try {
213             ArrayAssert.assertEquals(expected, notExpected);
214         } catch (AssertionFailedError e) {
215             return;
216         }
217         fail();
218     }
219
220     public void testSuccessAssertEqualsShort() {
221         short[] expected = new short[]{32, 10393, -48, 398};
222         short[] actual = new short[]{32, 10393, -48, 398};
223
224         ArrayAssert.assertEquals(expected, actual);
225     }
226
227     public void testFailAssertEqualsShort() {
228
229         short[] expected = new short[]{32, 10393, -48, 398};
230         short[] notExpected = new short[]{31, 10394, 48, 398};
231
232         try {
233             ArrayAssert.assertEquals(expected, notExpected);
234         } catch (AssertionFailedError e) {
235             return;
236         }
237         fail();
238     }
239
240     public void testSuccessAssertEqualsChar() {
241         char[] expected = new char[]{'a', 'b', 'c', 'z'};
242         char[] actual = new char[]{'a', 'b', 'c', 'z'};
243
244         ArrayAssert.assertEquals(expected, actual);
245     }
246
247     public void testFailAssertEqualsChar() {
248         char[] expected = new char[]{'a', 'b', 'c', 'z'};
249         char[] notExpected = new char[]{'a', 'b', 'c', 'y'};
250
251         try {
252             ArrayAssert.assertEquals(expected, notExpected);
253         } catch (AssertionFailedError e) {
254             return;
255         }
256         fail();
257     }
258
259     public void testSuccessAssertEqualsBoolean() {
260         boolean[] expected = new boolean[]{true, false, false, true};
261         boolean[] actual = new boolean[]{true, false, false, true};
262
263         ArrayAssert.assertEquals(expected, actual);
264     }
265
266     public void testSuccessFailEqualsBoolean() {
267         boolean[] expected = new boolean[]{true, false, false, true};
268         boolean[] notExpected = new boolean[]{true, true, false, true};
269
270         try {
271             ArrayAssert.assertEquals(expected, notExpected);
272         } catch (AssertionFailedError e) {
273             return;
274         }
275         fail();
276     }
277
278     public void testSuccessAssertEqualsByte()
279             throws Exception JavaDoc {
280         String JavaDoc s = "This is the test";
281         byte[] expected = s.getBytes("UTF8");
282         byte[] actual = s.getBytes("UTF8");
283
284         ArrayAssert.assertEquals(expected, actual);
285     }
286
287     public void testFailAssertEqualsByte()
288             throws Exception JavaDoc {
289         String JavaDoc s = "This is the test";
290         byte[] expected = s.getBytes("UTF8");
291         String JavaDoc notS = " This is not the test";
292         byte[] notExpected = notS.getBytes("UTF8");
293
294         try {
295             ArrayAssert.assertEquals(expected, notExpected);
296         } catch (AssertionFailedError e) {
297             return;
298         }
299         fail();
300     }
301
302     public void testMissingAssertEquivalence() {
303         String JavaDoc[] actual = {"Bird", "Cat"};
304         try {
305             ArrayAssert.assertEquivalenceArrays("Test1", new String JavaDoc[]{"Cat", "Dog"}, actual);
306         } catch (AssertionFailedError e) {
307             return;
308         }
309         fail();
310     }
311
312     public void testMissingAssertEquivalence2() {
313         String JavaDoc[] actual = {"Bird", "Cat"};
314         try {
315             ArrayAssert.assertEquivalenceArrays(new String JavaDoc[]{"Cat", "Dog"}, actual);
316         } catch (AssertionFailedError e) {
317             return;
318         }
319         fail();
320     }
321
322     public void testExtraAssertEquivalence() {
323         String JavaDoc[] actual = {"Bird", "Cat"};
324         try {
325             ArrayAssert.assertEquivalenceArrays("Test1", new String JavaDoc[]{"Cat"}, actual);
326         } catch (AssertionFailedError e) {
327             return;
328         }
329         fail();
330     }
331
332 }
333
334
Popular Tags