KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junitx > framework > ListAssertTest


1 package junitx.framework;
2
3 import java.util.List JavaDoc;
4 import java.util.Vector JavaDoc;
5
6 import junit.framework.AssertionFailedError;
7 import junit.framework.TestCase;
8
9 /**
10  * @version $Revision: 1.1 $ $Date: 2003/04/28 03:08:08 $
11  * @author <a HREF="mailto:vbossica@users.sourceforge.net">Vladimir R. Bossicard</a>
12  */

13 public class ListAssertTest extends TestCase {
14
15     public ListAssertTest(String JavaDoc name) {
16         super(name);
17     }
18
19     public void testEqualsSingleValue() {
20         List JavaDoc expected = new Vector JavaDoc();
21         expected.add(new Integer JavaDoc(1));
22
23         List JavaDoc actual = new Vector JavaDoc();
24         actual.add(new Integer JavaDoc(1));
25
26         ListAssert.assertEquals(expected, actual);
27     }
28
29     public void testEqualsMultipleValues() {
30         List JavaDoc expected = new Vector JavaDoc();
31         expected.add(new Integer JavaDoc(1));
32         expected.add(new Integer JavaDoc(2));
33
34         List JavaDoc actual = new Vector JavaDoc();
35         actual.add(new Integer JavaDoc(2));
36         actual.add(new Integer JavaDoc(1));
37
38         ListAssert.assertEquals(expected, actual);
39     }
40
41     public void testFailEqualsDifferentLength() {
42         List JavaDoc expected = new Vector JavaDoc();
43         expected.add(new Integer JavaDoc(1));
44         expected.add(new Integer JavaDoc(2));
45
46         List JavaDoc actual = new Vector JavaDoc();
47         actual.add(new Integer JavaDoc(1));
48
49         try {
50             ListAssert.assertEquals(expected, actual);
51         } catch (AssertionFailedError e) {
52             assertEquals("expecting <2> in <1>", e.getMessage());
53             return;
54         }
55         fail();
56     }
57
58     public void testFailEqualsDifferentLength_2() {
59         List JavaDoc expected = new Vector JavaDoc();
60         expected.add(new Integer JavaDoc(2));
61
62         List JavaDoc actual = new Vector JavaDoc();
63         actual.add(new Integer JavaDoc(2));
64         actual.add(new Integer JavaDoc(1));
65
66         try {
67             ListAssert.assertEquals(expected, actual);
68         } catch (AssertionFailedError e) {
69             assertEquals("[length] expected:<1> but was:<2>", e.getMessage());
70             return;
71         }
72         fail();
73     }
74
75     public void testContains() {
76         List JavaDoc expected = new Vector JavaDoc();
77         expected.add(new Integer JavaDoc(1));
78         expected.add(new Integer JavaDoc(2));
79
80         ListAssert.assertContains(expected, new Integer JavaDoc(1));
81     }
82
83     public void testFailContains() {
84         List JavaDoc expected = new Vector JavaDoc();
85         expected.add(new Integer JavaDoc(1));
86         expected.add(new Integer JavaDoc(2));
87
88         try {
89             ListAssert.assertContains(expected, new Integer JavaDoc(3));
90         } catch (AssertionFailedError e) {
91             assertEquals("expecting <3> in <1, 2>", e.getMessage());
92             return;
93         }
94         fail();
95     }
96
97 }
98
Popular Tags