1 4 package org.columba.core.config; 5 6 import junit.framework.TestCase; 7 8 import org.columa.core.config.IDefaultItem; 9 import org.columba.core.xml.XmlElement; 10 11 12 17 public class DefaultItemTest extends TestCase { 18 21 public void testHashCode() { 22 IDefaultItem item = new DefaultItem(new XmlElement()); 23 item.setBoolean("boolean", false); 24 item.setBoolean("badboolean", true); 25 item.setString("key", "value"); 26 27 IDefaultItem item2 = new DefaultItem(new XmlElement()); 28 item2.setBoolean("boolean", false); 29 item2.setBoolean("badboolean", true); 30 item2.setString("key", "value"); 31 assertTrue("The hashcodes are not the same", 32 item.hashCode() == item2.hashCode()); 33 assertTrue("The hashcodes are the same for different items.", 34 item.hashCode() != new DefaultItem(new XmlElement()).hashCode()); 35 } 36 37 40 public void testEqualsObject() { 41 IDefaultItem item = new DefaultItem(new XmlElement()); 42 item.setBoolean("boolean", false); 43 item.setBoolean("badboolean", true); 44 item.setString("key", "value"); 45 46 IDefaultItem item2 = new DefaultItem(new XmlElement()); 47 item2.setBoolean("boolean", false); 48 item2.setBoolean("badboolean", true); 49 item2.setString("key", "value"); 50 assertTrue("The items are not equal", item.equals(item2)); 51 assertTrue("The items are not equal", item2.equals(item)); 52 assertTrue("The items are not equal", item.equals(item)); 53 assertTrue("The items are not equal", item2.equals(item2)); 54 assertNotSame("The objects are the same", item, item2); 55 assertTrue("The items are equal", 56 !item.equals(new DefaultItem(new XmlElement()))); 57 58 assertFalse("The item is equal to an empty item", 59 item.equals(new DefaultItem(null))); 60 assertFalse("The item is equal to a null object", item.equals(null)); 61 assertTrue("The items are not equal", 62 item.equals(new DefaultItem((XmlElement) item.getRoot().clone()))); 63 } 64 65 68 public void testClone() { 69 IDefaultItem item1 = new DefaultItem(new XmlElement("EL")); 70 IDefaultItem item2 = (IDefaultItem) item1.clone(); 71 assertEquals("The parent and the cloned object are not equal", item1, 72 item2); 73 assertNotSame("The parent and the cloned object are the same", item1, 74 item2); 75 assertNotSame("The parent and the cloned Xml Elements objects are the same object.", 76 item1.getRoot(), item2.getRoot()); 77 assertEquals("The parent and the cloned Xml Elements objects are not equal.", 78 item1.getRoot(), item2.getRoot()); 79 assertEquals("The parent and the cloned object did not return the same hashcodes", 80 item1.hashCode(), item2.hashCode()); 81 82 XmlElement xml = new XmlElement(); 83 xml.setName("a NAME"); 84 xml.addAttribute("key", "values"); 85 xml.addAttribute("key2", "other values"); 86 xml.addSubElement("child"); 87 xml.addSubElement(new XmlElement("child2")); 88 89 item1 = new DefaultItem(xml); 90 item2 = (IDefaultItem) item1.clone(); 91 assertEquals("The parent and the cloned object are not equal", item1, 92 item2); 93 assertNotSame("The parent and the cloned object are the same", item1, 94 item2); 95 assertSame("The getRoot() method did not return the same object put in", 96 xml, item1.getRoot()); 97 assertNotSame("The parent and the cloned Xml Elements objects are the same object.", 98 item1.getRoot(), item2.getRoot()); 99 assertEquals("The parent and the cloned Xml Elements objects are not equal.", 100 item1.getRoot(), item2.getRoot()); 101 assertNotSame("The parent and the cloned Xml Elements objects are the same object.", 102 xml, item2.getRoot()); 103 assertEquals("The parent and the cloned object did not return the same hashcodes", 104 item1.hashCode(), item2.hashCode()); 105 } 106 107 public void testSet() { 108 XmlElement root = new XmlElement("root"); 109 IDefaultItem item = new DefaultItem(root); 110 item.setString("sub/path", "test", "value"); 111 112 assertTrue( root.getElement("sub/path")!= null ); 113 assertEquals( item.getString("sub/path","test"), "value"); 114 } 115 } 116 | Popular Tags |