1 29 30 package nextapp.echo2.app.test; 31 32 import java.util.HashSet ; 33 import java.util.Iterator ; 34 import java.util.Set ; 35 36 import nextapp.echo2.app.MutableStyle; 37 import junit.framework.TestCase; 38 39 42 public class MutableStyleTest extends TestCase { 43 44 public void testAddStyle() { 45 MutableStyle style1 = new MutableStyle(); 46 style1.setIndexedProperty("alpha", 0, "tango"); 47 style1.setIndexedProperty("alpha", 2, "uniform"); 48 style1.setIndexedProperty("alpha", 3, "victor"); 49 style1.setProperty("charlie", "delta"); 50 style1.setProperty("echo", "foxtrot"); 51 52 MutableStyle style2 = new MutableStyle(); 53 style2.setProperty("charlie", "golf"); 54 assertEquals("golf", style2.getProperty("charlie")); 55 56 style2.addStyleContent(style1); 57 58 assertEquals("tango", style2.getIndexedProperty("alpha", 0)); 59 assertEquals("uniform", style2.getIndexedProperty("alpha", 2)); 60 assertEquals("victor", style2.getIndexedProperty("alpha", 3)); 61 assertEquals("delta", style2.getProperty("charlie")); 62 assertEquals("foxtrot", style2.getProperty("echo")); 63 64 style2.setIndexedProperty("alpha", 3, "whiskey"); 65 assertEquals("whiskey", style2.getIndexedProperty("alpha", 3)); 66 assertEquals("victor", style1.getIndexedProperty("alpha", 3)); 67 68 style2.setProperty("echo", "hotel"); 69 assertEquals("hotel", style2.getProperty("echo")); 70 assertEquals("foxtrot", style1.getProperty("echo")); 71 } 72 73 public void testBasic() { 74 MutableStyle style = new MutableStyle(); 75 assertEquals(0, style.size()); 76 assertFalse(style.isPropertySet("alpha")); 77 assertNull(style.getProperty("alpha")); 78 79 style.setProperty("alpha", "bravo"); 80 assertEquals(1, style.size()); 81 assertTrue(style.isPropertySet("alpha")); 82 assertFalse(style.isPropertySet("bravo")); 83 84 style.setProperty("bravo", "charlie"); 85 assertEquals(2, style.size()); 86 assertEquals("bravo", style.getProperty("alpha")); 87 assertEquals("charlie", style.getProperty("bravo")); 88 89 style.setProperty("bravo", "delta"); 90 assertEquals(2, style.size()); 91 assertEquals("bravo", style.getProperty("alpha")); 92 assertEquals("delta", style.getProperty("bravo")); 93 94 style.setProperty("echo", "foxtrot"); 95 style.setProperty("golf", "hotel"); 96 style.setProperty("india", "juliet"); 97 style.setProperty("kilo", "lima"); 98 assertEquals(6, style.size()); 99 assertEquals("juliet", style.getProperty("india")); 100 101 style.removeProperty("kilo"); 102 assertEquals(5, style.size()); 103 assertNull(style.getProperty("kilo")); 104 105 style.removeProperty("alpha"); 106 assertEquals(4, style.size()); 107 assertNull(style.getProperty("alpha")); 108 109 style.removeProperty("mike"); 110 assertEquals(4, style.size()); 111 112 style.removeProperty("echo"); 113 style.removeProperty("golf"); 114 style.removeProperty("india"); 115 assertEquals(1, style.size()); 116 117 style.removeProperty("bravo"); 118 assertEquals(0, style.size()); 119 } 120 121 public void testGetPropertyIndices() { 122 MutableStyle style = new MutableStyle(); 123 style.setIndexedProperty("alpha", 0, "zero"); 124 style.setIndexedProperty("alpha", 1, "one"); 125 style.setIndexedProperty("alpha", 5, "five"); 126 Iterator it = style.getPropertyIndices("alpha"); 127 assertNotNull(it); 128 Set indices = new HashSet (); 129 while (it.hasNext()) { 130 indices.add(it.next()); 131 } 132 assertTrue(indices.contains(new Integer (0))); 133 assertTrue(indices.contains(new Integer (1))); 134 assertFalse(indices.contains(new Integer (2))); 135 assertTrue(indices.contains(new Integer (5))); 136 } 137 138 public void testGetPropertyNames() { 139 MutableStyle style = new MutableStyle(); 140 style.setProperty("alpha", "bravo"); 141 style.setProperty("charlie", "delta"); 142 style.setProperty("echo", "foxtrot"); 143 Iterator it = style.getPropertyNames(); 144 assertNotNull(it); 145 Set names = new HashSet (); 146 while (it.hasNext()) { 147 names.add(it.next()); 148 } 149 assertTrue(names.contains("alpha")); 150 assertTrue(names.contains("charlie")); 151 assertTrue(names.contains("echo")); 152 assertFalse(names.contains("bravo")); 153 assertFalse(names.contains("delta")); 154 assertFalse(names.contains("foxtrot")); 155 } 156 157 public void testIndexedProperty() { 158 MutableStyle style = new MutableStyle(); 159 style.setIndexedProperty("alpha", 0, "0"); 160 style.setIndexedProperty("alpha", 1, "1"); 161 style.setIndexedProperty("alpha", 2, "2"); 162 style.setIndexedProperty("alpha", 0, "3"); 163 164 assertFalse(style.isIndexedPropertySet("alpha", -1)); 165 assertTrue(style.isIndexedPropertySet("alpha", 0)); 166 assertTrue(style.isIndexedPropertySet("alpha", 1)); 167 assertTrue(style.isIndexedPropertySet("alpha", 2)); 168 assertFalse(style.isIndexedPropertySet("alpha", 3)); 169 assertEquals("3", style.getIndexedProperty("alpha", 0)); 170 assertEquals("1", style.getIndexedProperty("alpha", 1)); 171 assertEquals("2", style.getIndexedProperty("alpha", 2)); 172 173 style.removeIndexedProperty("alpha", 1); 174 assertFalse(style.isIndexedPropertySet("alpha", 1)); 175 } 176 177 public void testSet1Set2Remove2Set2() { 178 MutableStyle style = new MutableStyle(); 179 style.setProperty("golf", "hotel"); 180 style.setProperty("alpha", "bravo"); 181 assertEquals("hotel", style.getProperty("golf")); 182 assertEquals("bravo", style.getProperty("alpha")); 183 style.setProperty("alpha", null); 184 assertEquals("hotel", style.getProperty("golf")); 185 assertEquals(null, style.getProperty("alpha")); 186 style.setProperty("alpha", "bravo"); 187 assertEquals("hotel", style.getProperty("golf")); 188 assertEquals("bravo", style.getProperty("alpha")); 189 } 190 } | Popular Tags |