KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > junitx > framework > NamingAssertTest


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

14 public class NamingAssertTest extends TestCase {
15
16     public NamingAssertTest(String JavaDoc name) {
17         super(name);
18     }
19
20     public void testEqualsAttributesSingleValue() {
21         Attributes JavaDoc expected = new BasicAttributes JavaDoc();
22         expected.put(new BasicAttribute("attrID", "value1"));
23
24         Attributes JavaDoc actual = new BasicAttributes JavaDoc();
25         actual.put(new BasicAttribute("attrID", "value1"));
26
27         NamingAssert.assertEquals(expected, actual);
28     }
29
30     public void testFailAttributesNullActual() {
31         Attributes JavaDoc expected = new BasicAttributes JavaDoc();
32         expected.put(new BasicAttribute("attrID", "value1"));
33         try {
34             NamingAssert.assertEquals(expected, null);
35         } catch (AssertionFailedError e) {
36             assertEquals("[actual] expected not <null>", e.getMessage());
37             return;
38         }
39         fail();
40     }
41
42     public void testFailAttributesNullExpected() {
43         Attributes JavaDoc actual = new BasicAttributes JavaDoc();
44         actual.put(new BasicAttribute("attrID", "value1"));
45         try {
46             NamingAssert.assertEquals(null, actual);
47         } catch (AssertionFailedError e) {
48             assertEquals("[expected] expected not <null>", e.getMessage());
49             return;
50         }
51         fail();
52     }
53
54     public void testFailEqualsAttributesSingleValue() {
55         Attributes JavaDoc expected = new BasicAttributes JavaDoc();
56         expected.put(new BasicAttribute("attrID", "value1"));
57
58         Attributes JavaDoc actual = new BasicAttributes JavaDoc();
59         actual.put(new BasicAttribute("attrID", "value2"));
60         try {
61             NamingAssert.assertEquals(expected, actual);
62         } catch (AssertionFailedError e) {
63             assertEquals("expecting <value1> in <value2>", e.getMessage());
64             return;
65         }
66         fail();
67     }
68
69     public void testEqualsAttributeSingleValue() {
70         Attribute JavaDoc expected = new BasicAttribute("attrID", "value1");
71         Attribute JavaDoc actual = new BasicAttribute("attrID", "value1");
72
73         NamingAssert.assertEquals(expected, actual);
74     }
75
76     public void testFailAttributeNullActual() {
77         Attribute JavaDoc expected = new BasicAttribute("attrID", "value1");
78         try {
79             NamingAssert.assertEquals(expected, null);
80         } catch (AssertionFailedError e) {
81             assertEquals("[actual] expected not <null>", e.getMessage());
82             return;
83         }
84         fail();
85     }
86
87     public void testFailAttributeNullExpected() {
88         Attribute JavaDoc actual = new BasicAttribute("attrID", "value1");
89         try {
90             NamingAssert.assertEquals(null, actual);
91         } catch (AssertionFailedError e) {
92             assertEquals("[expected] expected not <null>", e.getMessage());
93             return;
94         }
95         fail();
96     }
97
98     public void testFailEqualsAttributeSingleValue() {
99         Attribute JavaDoc expected = new BasicAttribute("attrID", "value1");
100         Attribute JavaDoc actual = new BasicAttribute("attrID", "value2");
101         try {
102             NamingAssert.assertEquals(expected, actual);
103         } catch (AssertionFailedError e) {
104             assertEquals("expecting <value1> in <value2>", e.getMessage());
105             return;
106         }
107         fail();
108     }
109
110 }
111
Popular Tags