1 4 package org.columba.mail.config; 5 6 import junit.framework.TestCase; 7 8 import org.columba.core.xml.XmlElement; 9 10 11 16 public class AccountItemTest extends TestCase { 17 20 public void testHashCode() { 21 XmlElement xml = new XmlElement("account"); 23 xml.addAttribute("name", "my account"); 24 xml.addAttribute("uid", "0"); 25 26 XmlElement child = xml.addSubElement("identity"); 27 child.addAttribute("name", "John Doe"); 28 child.addAttribute("attach_signature", "false"); 29 child = xml.addSubElement("popserver"); 30 child.addAttribute("port", "25"); 31 child.addAttribute("login_method", "USER"); 32 child = xml.addSubElement("specialfolders"); 33 child.addAttribute("inbox", "101"); 34 child.addAttribute("sent", "104"); 35 36 AccountItem item = new AccountItem(xml); 37 38 XmlElement xml2 = new XmlElement("account"); 40 xml2.addAttribute("uid", "0"); 41 xml2.addAttribute("name", "my account"); 42 43 XmlElement child2 = xml2.addSubElement("identity"); 44 child2.addAttribute("attach_signature", "false"); 45 child2.addAttribute("name", "John Doe"); 46 child2 = xml2.addSubElement("popserver"); 47 child2.addAttribute("login_method", "USER"); 48 child2.addAttribute("port", "25"); 49 child2 = xml2.addSubElement("specialfolders"); 50 child2.addAttribute("sent", "104"); 51 child2.addAttribute("inbox", "101"); 52 53 AccountItem item2 = new AccountItem(xml2); 54 55 XmlElement xml3 = new XmlElement("account"); 57 xml3.addAttribute("name", "my account"); 58 xml3.addAttribute("uid", "0"); 59 60 XmlElement child3 = xml3.addSubElement("identity"); 61 child3.addAttribute("name", "Kalle Kamel"); 62 child3.addAttribute("attach_signature", "false"); 63 child3 = xml3.addSubElement("popserver"); 64 child3.addAttribute("port", "25"); 65 child3.addAttribute("login_method", "USER"); 66 child3 = xml3.addSubElement("specialfolders"); 67 child3.addAttribute("inbox", "101"); 68 child3.addAttribute("sent", "104"); 69 70 AccountItem item3 = new AccountItem(xml3); 71 72 assertTrue("The hashcodes of item and item2 are not the same", 74 item.hashCode() == item2.hashCode()); 75 76 assertFalse("The hashcodes of item and a new object are the same", 78 item.hashCode() == (new AccountItem(new XmlElement())).hashCode()); 79 80 assertFalse("The hashcodes of item and item3 are the same", 82 item.hashCode() == item3.hashCode()); 83 } 84 85 88 public void testEqualsObject() { 89 XmlElement xml = new XmlElement("account"); 91 xml.addAttribute("name", "my account"); 92 xml.addAttribute("uid", "0"); 93 94 XmlElement child = xml.addSubElement("identity"); 95 child.addAttribute("name", "John Doe"); 96 child.addAttribute("attach_signature", "false"); 97 child = xml.addSubElement("popserver"); 98 child.addAttribute("port", "25"); 99 child.addAttribute("login_method", "USER"); 100 child = xml.addSubElement("specialfolders"); 101 child.addAttribute("inbox", "101"); 102 child.addAttribute("sent", "104"); 103 104 AccountItem item = new AccountItem(xml); 105 106 XmlElement xml2 = new XmlElement("account"); 108 xml2.addAttribute("uid", "0"); 109 xml2.addAttribute("name", "my account"); 110 111 XmlElement child2 = xml2.addSubElement("identity"); 112 child2.addAttribute("attach_signature", "false"); 113 child2.addAttribute("name", "John Doe"); 114 child2 = xml2.addSubElement("popserver"); 115 child2.addAttribute("login_method", "USER"); 116 child2.addAttribute("port", "25"); 117 child2 = xml2.addSubElement("specialfolders"); 118 child2.addAttribute("sent", "104"); 119 child2.addAttribute("inbox", "101"); 120 121 AccountItem item2 = new AccountItem(xml2); 122 123 XmlElement xml3 = new XmlElement("account"); 125 xml3.addAttribute("name", "my account"); 126 xml3.addAttribute("uid", "0"); 127 128 XmlElement child3 = xml3.addSubElement("identity"); 129 child3.addAttribute("name", "Kalle Kamel"); 130 child3.addAttribute("attach_signature", "false"); 131 child3 = xml3.addSubElement("popserver"); 132 child3.addAttribute("port", "25"); 133 child3.addAttribute("login_method", "USER"); 134 child3 = xml3.addSubElement("specialfolders"); 135 child3.addAttribute("inbox", "101"); 136 child3.addAttribute("sent", "104"); 137 138 AccountItem item3 = new AccountItem(xml3); 139 140 assertTrue("Self equality failed for item", item.equals(item)); 142 assertTrue("Self equality failed for item2", item2.equals(item2)); 143 144 assertTrue("item and item2 are not equal", item.equals(item2)); 146 assertTrue("item2 and item are not equal", item2.equals(item)); 147 148 assertNotSame("item and item2 refers to the same object", item, item2); 150 151 assertFalse("item is equal to a newly created AccountItem", 153 item.equals(new AccountItem(new XmlElement()))); 154 assertFalse("item is equal to null", item.equals(null)); 155 156 assertFalse("item and item3 are equal", item.equals(item3)); 158 } 159 } 160 | Popular Tags |