001: /*
002: * Created on 2003-11-02
003: */
004: package org.columba.mail.config;
005:
006: import junit.framework.TestCase;
007:
008: import org.columba.core.xml.XmlElement;
009:
010: /**
011: * Test cases for the <code>AccountItem</code> class.
012: *
013: * @author karlpeder
014: */
015: public class AccountItemTest extends TestCase {
016: /*
017: * Test for int hashCode().
018: */
019: public void testHashCode() {
020: // first account item
021: XmlElement xml = new XmlElement("account");
022: xml.addAttribute("name", "my account");
023: xml.addAttribute("uid", "0");
024:
025: XmlElement child = xml.addSubElement("identity");
026: child.addAttribute("name", "John Doe");
027: child.addAttribute("attach_signature", "false");
028: child = xml.addSubElement("popserver");
029: child.addAttribute("port", "25");
030: child.addAttribute("login_method", "USER");
031: child = xml.addSubElement("specialfolders");
032: child.addAttribute("inbox", "101");
033: child.addAttribute("sent", "104");
034:
035: AccountItem item = new AccountItem(xml);
036:
037: // second account item
038: XmlElement xml2 = new XmlElement("account");
039: xml2.addAttribute("uid", "0");
040: xml2.addAttribute("name", "my account");
041:
042: XmlElement child2 = xml2.addSubElement("identity");
043: child2.addAttribute("attach_signature", "false");
044: child2.addAttribute("name", "John Doe");
045: child2 = xml2.addSubElement("popserver");
046: child2.addAttribute("login_method", "USER");
047: child2.addAttribute("port", "25");
048: child2 = xml2.addSubElement("specialfolders");
049: child2.addAttribute("sent", "104");
050: child2.addAttribute("inbox", "101");
051:
052: AccountItem item2 = new AccountItem(xml2);
053:
054: // third item, a bit different from the first
055: XmlElement xml3 = new XmlElement("account");
056: xml3.addAttribute("name", "my account");
057: xml3.addAttribute("uid", "0");
058:
059: XmlElement child3 = xml3.addSubElement("identity");
060: child3.addAttribute("name", "Kalle Kamel");
061: child3.addAttribute("attach_signature", "false");
062: child3 = xml3.addSubElement("popserver");
063: child3.addAttribute("port", "25");
064: child3.addAttribute("login_method", "USER");
065: child3 = xml3.addSubElement("specialfolders");
066: child3.addAttribute("inbox", "101");
067: child3.addAttribute("sent", "104");
068:
069: AccountItem item3 = new AccountItem(xml3);
070:
071: // should have the same hashcodes...
072: assertTrue("The hashcodes of item and item2 are not the same",
073: item.hashCode() == item2.hashCode());
074:
075: // expect a different hashcode from a newly created item...
076: assertFalse(
077: "The hashcodes of item and a new object are the same",
078: item.hashCode() == (new AccountItem(new XmlElement()))
079: .hashCode());
080:
081: // expect a different hashcode for item and item3
082: assertFalse("The hashcodes of item and item3 are the same",
083: item.hashCode() == item3.hashCode());
084: }
085:
086: /*
087: * Test for boolean equals(Object)
088: */
089: public void testEqualsObject() {
090: // first account item
091: XmlElement xml = new XmlElement("account");
092: xml.addAttribute("name", "my account");
093: xml.addAttribute("uid", "0");
094:
095: XmlElement child = xml.addSubElement("identity");
096: child.addAttribute("name", "John Doe");
097: child.addAttribute("attach_signature", "false");
098: child = xml.addSubElement("popserver");
099: child.addAttribute("port", "25");
100: child.addAttribute("login_method", "USER");
101: child = xml.addSubElement("specialfolders");
102: child.addAttribute("inbox", "101");
103: child.addAttribute("sent", "104");
104:
105: AccountItem item = new AccountItem(xml);
106:
107: // second account item
108: XmlElement xml2 = new XmlElement("account");
109: xml2.addAttribute("uid", "0");
110: xml2.addAttribute("name", "my account");
111:
112: XmlElement child2 = xml2.addSubElement("identity");
113: child2.addAttribute("attach_signature", "false");
114: child2.addAttribute("name", "John Doe");
115: child2 = xml2.addSubElement("popserver");
116: child2.addAttribute("login_method", "USER");
117: child2.addAttribute("port", "25");
118: child2 = xml2.addSubElement("specialfolders");
119: child2.addAttribute("sent", "104");
120: child2.addAttribute("inbox", "101");
121:
122: AccountItem item2 = new AccountItem(xml2);
123:
124: // third item, a bit different from the first
125: XmlElement xml3 = new XmlElement("account");
126: xml3.addAttribute("name", "my account");
127: xml3.addAttribute("uid", "0");
128:
129: XmlElement child3 = xml3.addSubElement("identity");
130: child3.addAttribute("name", "Kalle Kamel");
131: child3.addAttribute("attach_signature", "false");
132: child3 = xml3.addSubElement("popserver");
133: child3.addAttribute("port", "25");
134: child3.addAttribute("login_method", "USER");
135: child3 = xml3.addSubElement("specialfolders");
136: child3.addAttribute("inbox", "101");
137: child3.addAttribute("sent", "104");
138:
139: AccountItem item3 = new AccountItem(xml3);
140:
141: // test self equality...
142: assertTrue("Self equality failed for item", item.equals(item));
143: assertTrue("Self equality failed for item2", item2
144: .equals(item2));
145:
146: // item and item2 should be equal...
147: assertTrue("item and item2 are not equal", item.equals(item2));
148: assertTrue("item2 and item are not equal", item2.equals(item));
149:
150: // item and item2 should be two different objects
151: assertNotSame("item and item2 refers to the same object", item,
152: item2);
153:
154: // item should not be equal to a newly created item or null
155: assertFalse("item is equal to a newly created AccountItem",
156: item.equals(new AccountItem(new XmlElement())));
157: assertFalse("item is equal to null", item.equals(null));
158:
159: // item and item3 should not be equal
160: assertFalse("item and item3 are equal", item.equals(item3));
161: }
162: }
|