- Timestamp:
- 2016-01-15T02:23:39+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/data/osm/OsmPrimitiveKeyHandlingTest.java
r9214 r9459 2 2 package org.openstreetmap.josm.data.osm; 3 3 4 import static org.junit.Assert.assertEquals; 4 5 import static org.junit.Assert.assertFalse; 5 import static org.junit.Assert.assertNull;6 import static org.junit.Assert.assertSame;7 6 import static org.junit.Assert.assertTrue; 8 7 … … 32 31 public void emptyNode() { 33 32 Node n = new Node(); 34 assertSame(n.getKeys().size(), 0); 35 assertFalse(n.hasKeys()); 36 assertFalse(n.hasKey("nosuchkey")); 37 assertTrue(n.keySet().isEmpty()); 33 testKeysSize(n, 0); 34 testGetKey(n, "nosuchkey", null); 38 35 39 36 n.remove("nosuchkey"); // should work 37 testKeysSize(n, 0); 38 testGetKey(n, "nosuchkey", null); 40 39 } 41 40 … … 47 46 Node n = new Node(); 48 47 n.put("akey", "avalue"); 49 assertTrue(n.get("akey").equals("avalue")); 50 assertSame(n.getKeys().size(), 1); 48 testKeysSize(n, 1); 51 49 52 assertSame(n.keySet().size(), 1); 53 assertTrue(n.keySet().contains("akey")); 50 testGetKey(n, "akey", "avalue"); 54 51 } 55 52 … … 64 61 assertTrue(n.get("key.1").equals("value.1")); 65 62 assertTrue(n.get("key.2").equals("value.2")); 66 assertSame(n.getKeys().size(), 2);63 testKeysSize(n, 2); 67 64 assertTrue(n.hasKeys()); 68 65 assertTrue(n.hasKey("key.1")); … … 78 75 Node n = new Node(); 79 76 n.put("key.1", "value.1"); 80 n.put("key.2", "value.2"); 77 n.put(new String("key.2"), new String("value.2")); // Test that equals is used and not == 78 79 testGetKey(n, "key.1", "value.1"); 80 testGetKey(n, "key.2", "value.2"); 81 81 82 82 n.remove("nosuchkey"); // should work 83 assertSame(n.getKeys().size(), 2); // still 2 tags ? 83 testKeysSize(n, 2); // still 2 tags ? 84 85 testGetKey(n, "key.1", "value.1"); 86 testGetKey(n, "key.2", "value.2"); 84 87 85 88 n.remove("key.1"); 86 assertSame(n.getKeys().size(), 1);87 assert False(n.hasKey("key.1"));88 assertNull(n.get("key.1")); 89 assertTrue(n.hasKey("key.2"));90 assertTrue(n.get("key.2").equals("value.2"));89 testKeysSize(n, 1); 90 assertTrue(n.hasKeys()); 91 92 testGetKey(n, "key.1", null); 93 testGetKey(n, "key.2", "value.2"); 91 94 92 95 n.remove("key.2"); 93 assertSame(n.getKeys().size(), 0); 94 assertFalse(n.hasKey("key.1")); 95 assertNull(n.get("key.1")); 96 assertFalse(n.hasKey("key.2")); 97 assertNull(n.get("key.2")); 96 testKeysSize(n, 0); 97 assertFalse(n.hasKeys()); 98 testGetKey(n, "key.1", null); 99 testGetKey(n, "key.2", null); 98 100 } 99 101 … … 109 111 110 112 n.removeAll(); 111 assertSame(n.getKeys().size(), 0);113 testKeysSize(n, 0); 112 114 } 113 115 … … 148 150 assertFalse(n1.hasEqualSemanticAttributes(n2)); 149 151 } 152 153 /** 154 * Tests if the size of the keys map is right. 155 * @author Michael Zangl 156 * @param p The primitive (node) to test 157 * @param expectedSize The expected size. 158 * @throws AssertionError on failure. 159 */ 160 private void testKeysSize(OsmPrimitive p, int expectedSize) { 161 assertEquals(expectedSize, p.getKeys().size()); 162 assertEquals(expectedSize, p.keySet().size()); 163 assertEquals(expectedSize, p.getKeys().entrySet().size()); 164 assertEquals(expectedSize, p.getKeys().keySet().size()); 165 assertEquals(expectedSize, p.getNumKeys()); 166 boolean empty = expectedSize == 0; 167 assertEquals(empty, p.getKeys().isEmpty()); 168 assertEquals(empty, p.keySet().isEmpty()); 169 assertEquals(empty, p.getKeys().entrySet().isEmpty()); 170 assertEquals(empty, p.getKeys().keySet().isEmpty()); 171 assertEquals(!empty, p.hasKeys()); 172 } 173 174 /** 175 * Tests all key get methods for that node. 176 * @author Michael Zangl 177 * @param p The primitive (node) 178 * @param key The key to test 179 * @param value The value the key should have. 180 * @throws AssertionError on failure. 181 */ 182 private void testGetKey(OsmPrimitive p, String key, String value) { 183 assertEquals(value != null, p.hasKey(key)); 184 assertEquals(value != null, p.getKeys().containsKey(key)); 185 assertEquals(value != null, p.getKeys().keySet().contains(key)); 186 assertEquals(value, p.get(key)); 187 assertEquals(value, p.getKeys().get(key)); 188 } 189 150 190 }
Note:
See TracChangeset
for help on using the changeset viewer.