Changeset 11104 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2016-10-08T15:28:54+02:00 (8 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 1 edited
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/TestUtils.java
r11102 r11104 9 9 import java.io.IOException; 10 10 import java.io.InputStream; 11 import java.lang.reflect.Field; 11 12 import java.util.Arrays; 12 13 import java.util.Collection; … … 164 165 165 166 /** 167 * Returns a private field value. 168 * @param obj object 169 * @param fieldName private field name 170 * @return private field value 171 * @throws ReflectiveOperationException if a reflection operation error occurs 172 */ 173 public static Object getPrivateField(Object obj, String fieldName) throws ReflectiveOperationException { 174 Field f = obj.getClass().getDeclaredField(fieldName); 175 f.setAccessible(true); 176 return f.get(obj); 177 } 178 179 /** 166 180 * Returns an instance of {@link AbstractProgressMonitor} which keeps track of the monitor state, 167 181 * but does not show the progress. -
trunk/test/unit/org/openstreetmap/josm/actions/CreateMultipolygonActionTest.java
r11095 r11104 1 package org.openstreetmap.josm.actions 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.actions; 2 3 3 import org.junit.BeforeClass 4 import org.junit.Test 5 import org.openstreetmap.josm.JOSMFixture 6 import org.openstreetmap.josm.TestUtils 7 import org.openstreetmap.josm.actions.search.SearchAction 8 import org.openstreetmap.josm.actions.search.SearchCompiler 9 import org.openstreetmap.josm.data.osm.Relation 10 import org.openstreetmap.josm.data.osm.Way 11 import org.openstreetmap.josm.io.OsmReader 12 import org.openstreetmap.josm.tools.SubclassFilteredCollection 4 import static org.junit.Assert.assertEquals; 13 5 6 import java.io.FileInputStream; 7 import java.util.Collection; 8 import java.util.Map; 9 import java.util.TreeMap; 10 11 import org.junit.Rule; 12 import org.junit.Test; 13 import org.openstreetmap.josm.TestUtils; 14 import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting; 15 import org.openstreetmap.josm.actions.search.SearchCompiler; 16 import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError; 17 import org.openstreetmap.josm.command.SequenceCommand; 18 import org.openstreetmap.josm.data.osm.DataSet; 19 import org.openstreetmap.josm.data.osm.Relation; 20 import org.openstreetmap.josm.data.osm.RelationMember; 21 import org.openstreetmap.josm.data.osm.Way; 22 import org.openstreetmap.josm.io.OsmReader; 23 import org.openstreetmap.josm.testutils.JOSMTestRules; 24 import org.openstreetmap.josm.tools.Pair; 25 import org.openstreetmap.josm.tools.SubclassFilteredCollection; 26 27 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 28 29 /** 30 * Unit test of {@link CreateMultipolygonAction} 31 */ 14 32 public class CreateMultipolygonActionTest { 15 33 16 @BeforeClass 17 public static void setUp() { 18 JOSMFixture.createUnitTestFixture().init(); 19 } 34 /** 35 * Setup test. 36 */ 37 @Rule 38 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 39 public JOSMTestRules test = new JOSMTestRules().projection(); 20 40 21 static defgetRefToRoleMap(Relation relation) {22 def refToRole = new TreeMap<String, String>()23 for ( i inrelation.getMembers()) {24 refToRole.put(i. member.get("ref"), i.role);41 private static Map<String, String> getRefToRoleMap(Relation relation) { 42 Map<String, String> refToRole = new TreeMap<>(); 43 for (RelationMember i : relation.getMembers()) { 44 refToRole.put(i.getMember().get("ref"), i.getRole()); 25 45 } 26 46 return refToRole; 27 47 } 28 48 29 static def regexpSearch(String search) { 30 def setting = new SearchAction.SearchSetting() 31 setting.text = search 32 setting.regexSearch = true 33 return setting 49 private static SearchSetting regexpSearch(String search) { 50 SearchSetting setting = new SearchSetting(); 51 setting.text = search; 52 setting.regexSearch = true; 53 return setting; 54 } 55 56 @SuppressWarnings("unchecked") 57 private static Pair<SequenceCommand, Relation> createMultipolygonCommand(Collection<Way> ways, String pattern, Relation r) 58 throws ParseError { 59 return CreateMultipolygonAction.createMultipolygonCommand( 60 (Collection<Way>) (Collection<?>) SubclassFilteredCollection.filter(ways, SearchCompiler.compile(regexpSearch(pattern))), r); 34 61 } 35 62 36 63 @Test 37 public void testCreate1() {38 defds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null);39 def mp = CreateMultipolygonAction.createMultipolygonCommand(ds.getWays(), null)40 assert mp.a.getDescriptionText() == "Sequence: Create multipolygon"41 assert getRefToRoleMap(mp.b).toString() == "[1:outer, 1.1:inner, 1.1.1:outer, 1.1.2:outer, 1.2:inner]"64 public void testCreate1() throws Exception { 65 DataSet ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null); 66 Pair<SequenceCommand, Relation> mp = CreateMultipolygonAction.createMultipolygonCommand(ds.getWays(), null); 67 assertEquals("Sequence: Create multipolygon", mp.a.getDescriptionText()); 68 assertEquals("{1=outer, 1.1=inner, 1.1.1=outer, 1.1.2=outer, 1.2=inner}", getRefToRoleMap(mp.b).toString()); 42 69 } 43 70 44 71 @Test 45 public void testCreate2() { 46 def ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null); 47 def ways = SubclassFilteredCollection.filter(ds.getWays(), SearchCompiler.compile("ref=1 OR ref:1.1.")) 48 def mp = CreateMultipolygonAction.createMultipolygonCommand(ways as Collection<Way>, null) 49 assert getRefToRoleMap(mp.b).toString() == "[1:outer, 1.1.1:inner, 1.1.2:inner]" 72 public void testCreate2() throws Exception { 73 DataSet ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null); 74 Pair<SequenceCommand, Relation> mp = createMultipolygonCommand(ds.getWays(), "ref=1 OR ref:1.1.", null); 75 assertEquals("{1=outer, 1.1.1=inner, 1.1.2=inner}", getRefToRoleMap(mp.b).toString()); 50 76 } 51 77 52 78 @Test 53 public void testUpdate1() { 54 def ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null); 55 def ways = SubclassFilteredCollection.filter(ds.getWays(), SearchCompiler.compile(regexpSearch("ref=\".*1\$\""))) 56 def mp = CreateMultipolygonAction.createMultipolygonCommand(ways as Collection<Way>, null) 57 assert mp.b.getMembersCount() == 3 58 assert getRefToRoleMap(mp.b).toString() == "[1:outer, 1.1:inner, 1.1.1:outer]" 59 def ways2 = SubclassFilteredCollection.filter(ds.getWays(), SearchCompiler.compile(regexpSearch("ref=1.2"))) 60 def mp2 = CreateMultipolygonAction.createMultipolygonCommand(ways2 as Collection<Way>, mp.b) 61 assert mp2.b.getMembersCount() == 4 62 assert getRefToRoleMap(mp2.b).toString() == "[1:outer, 1.1:inner, 1.1.1:outer, 1.2:inner]" 79 public void testUpdate1() throws Exception { 80 DataSet ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null); 81 Pair<SequenceCommand, Relation> mp = createMultipolygonCommand(ds.getWays(), "ref=\".*1$\"", null); 82 assertEquals(3, mp.b.getMembersCount()); 83 assertEquals("{1=outer, 1.1=inner, 1.1.1=outer}", getRefToRoleMap(mp.b).toString()); 84 Pair<SequenceCommand, Relation> mp2 = createMultipolygonCommand(ds.getWays(), "ref=1.2", mp.b); 85 assertEquals(4, mp2.b.getMembersCount()); 86 assertEquals("{1=outer, 1.1=inner, 1.1.1=outer, 1.2=inner}", getRefToRoleMap(mp2.b).toString()); 63 87 } 64 88 65 89 @Test 66 public void testUpdate2() { 67 def ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null); 68 def ways = SubclassFilteredCollection.filter(ds.getWays(), SearchCompiler.compile("ref=1 OR ref:1.1.1")) 69 def mp = CreateMultipolygonAction.createMultipolygonCommand(ways as Collection<Way>, null) 70 assert getRefToRoleMap(mp.b).toString() == "[1:outer, 1.1.1:inner]" 71 def ways2 = SubclassFilteredCollection.filter(ds.getWays(), SearchCompiler.compile(regexpSearch("ref=1.1 OR ref=1.2 OR ref=1.1.2"))) 72 def mp2 = CreateMultipolygonAction.createMultipolygonCommand(ways2 as Collection<Way>, mp.b) 73 assert getRefToRoleMap(mp2.b).toString() == "[1:outer, 1.1:inner, 1.1.1:outer, 1.1.2:outer, 1.2:inner]" 90 public void testUpdate2() throws Exception { 91 DataSet ds = OsmReader.parseDataSet(new FileInputStream(TestUtils.getTestDataRoot() + "create_multipolygon.osm"), null); 92 Pair<SequenceCommand, Relation> mp = createMultipolygonCommand(ds.getWays(), "ref=1 OR ref:1.1.1", null); 93 assertEquals("{1=outer, 1.1.1=inner}", getRefToRoleMap(mp.b).toString()); 94 Pair<SequenceCommand, Relation> mp2 = createMultipolygonCommand(ds.getWays(), "ref=1.1 OR ref=1.2 OR ref=1.1.2", mp.b); 95 assertEquals("{1=outer, 1.1=inner, 1.1.1=outer, 1.1.2=outer, 1.2=inner}", getRefToRoleMap(mp2.b).toString()); 74 96 } 75 97 } -
trunk/test/unit/org/openstreetmap/josm/data/osm/ChangesetCacheTest.java
r11095 r11104 2 2 package org.openstreetmap.josm.data.osm; 3 3 4 import static org.junit.Assert.* 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertFalse; 6 import static org.junit.Assert.assertNotNull; 7 import static org.junit.Assert.assertTrue; 5 8 6 import org.junit.Test9 import java.util.List; 7 10 8 class ChangesetCacheTest { 11 import org.junit.Test; 12 import org.openstreetmap.josm.TestUtils; 9 13 14 /** 15 * Unit test of {@link ChangesetCache} 16 */ 17 public class ChangesetCacheTest { 18 19 /** 20 * Unit test of {@link ChangesetCache#ChangesetCache} 21 */ 10 22 @Test 11 23 public void testConstructor() { 12 ChangesetCache cache = ChangesetCache.getInstance() 13 assert cache != null 24 assertNotNull(ChangesetCache.getInstance()); 25 } 26 27 @SuppressWarnings("unchecked") 28 private static List<ChangesetCacheListener> getListeners(ChangesetCache cache) throws ReflectiveOperationException { 29 return (List<ChangesetCacheListener>) TestUtils.getPrivateField(cache, "listeners"); 14 30 } 15 31 16 32 @Test 17 public void testAddAndRemoveListeners() {18 ChangesetCache cache = ChangesetCache.getInstance() 19 cache.clear() 33 public void testAddAndRemoveListeners() throws ReflectiveOperationException { 34 ChangesetCache cache = ChangesetCache.getInstance(); 35 cache.clear(); 20 36 21 37 // should work 22 cache.addChangesetCacheListener null38 cache.addChangesetCacheListener(null); 23 39 24 40 // should work 25 def listener = new ChangesetCacheListener() { 41 ChangesetCacheListener listener = new ChangesetCacheListener() { 42 @Override 26 43 public void changesetCacheUpdated(ChangesetCacheEvent event) {} 27 } 28 cache.addChangesetCacheListener listener44 }; 45 cache.addChangesetCacheListener(listener); 29 46 // adding a second time - should work too 30 cache.addChangesetCacheListener listener31 assert cache.@listeners.size() == 1// ... but only added once47 cache.addChangesetCacheListener(listener); 48 assertEquals(1, getListeners(cache).size()); // ... but only added once 32 49 33 cache.removeChangesetCacheListener null50 cache.removeChangesetCacheListener(null); 34 51 35 cache.removeChangesetCacheListener listener36 assert cache.@listeners.size() == 052 cache.removeChangesetCacheListener(listener); 53 assertTrue(getListeners(cache).isEmpty()); 37 54 } 38 55 39 56 @Test 40 57 public void updateGetRemoveCycle() { 41 ChangesetCache cache = ChangesetCache.getInstance() 42 cache.clear() 58 ChangesetCache cache = ChangesetCache.getInstance(); 59 cache.clear(); 43 60 44 cache.update new Changeset(1)45 assert cache.size() == 146 assert cache.get(1) != null47 assert cache.get(1).id == 148 cache.remove(1) 49 assert cache.size() == 061 cache.update(new Changeset(1)); 62 assertEquals(1, cache.size()); 63 assertNotNull(cache.get(1)); 64 assertEquals(1, cache.get(1).getId()); 65 cache.remove(1); 66 assertEquals(0, cache.size()); 50 67 } 51 68 52 69 @Test 53 70 public void updateTwice() { 54 ChangesetCache cache = ChangesetCache.getInstance() 55 cache.clear() 71 ChangesetCache cache = ChangesetCache.getInstance(); 72 cache.clear(); 56 73 57 Changeset cs = new Changeset(1) 58 cs. incomplete = false59 cs.put "key1", "value1"60 cs. open = true61 cache.update cs74 Changeset cs = new Changeset(1); 75 cs.setIncomplete(false); 76 cs.put("key1", "value1"); 77 cs.setOpen(true); 78 cache.update(cs); 62 79 63 Changeset cs2 = new Changeset(cs) 64 assert cs2 != null65 cs2.put "key2", "value2"66 cs2. open = false67 cache.update(cs2) 80 Changeset cs2 = new Changeset(cs); 81 assertNotNull(cs2); 82 cs2.put("key2", "value2"); 83 cs2.setOpen(false); 84 cache.update(cs2); 68 85 69 assert cache.size() == 170 assert cache.get(1) != null86 assertEquals(1, cache.size()); 87 assertNotNull(cache.get(1)); 71 88 72 cs = cache.get(1) 73 assert cs.get("key1") == "value1" 74 assert cs.get("key2") == "value2" 75 assert !cs.open 76 } 77 78 79 @Test 80 public void contains() { 81 ChangesetCache cache = ChangesetCache.getInstance() 82 cache.@listeners.clear() 83 cache.clear() 84 85 86 Changeset cs = new Changeset(1) 87 cache.update cs 88 89 assert cache.contains(1) 90 assert cache.contains(cs) 91 assert cache.contains(new Changeset(cs)) 92 93 assert ! cache.contains(2) 94 assert ! cache.contains(new Changeset(2)) 95 assert ! cache.contains(null) 89 cs = cache.get(1); 90 assertEquals("value1", cs.get("key1")); 91 assertEquals("value2", cs.get("key2")); 92 assertFalse(cs.isOpen()); 96 93 } 97 94 98 95 @Test 99 public void fireingEventsAddAChangeset(){100 ChangesetCache cache = ChangesetCache.getInstance() 101 cache.clear()102 cache. @listeners.clear()96 public void contains() throws ReflectiveOperationException { 97 ChangesetCache cache = ChangesetCache.getInstance(); 98 getListeners(cache).clear(); 99 cache.clear(); 103 100 104 // should work 105 def listener = new ChangesetCacheListener() { 106 public void changesetCacheUpdated(ChangesetCacheEvent event) { 107 assert event != null 108 assert event.getAddedChangesets().size() == 1 109 assert event.getRemovedChangesets().empty 110 assert event.getUpdatedChangesets().empty 111 assert event.getSource() == cache 112 } 113 } 114 cache.addChangesetCacheListener listener 115 cache.update(new Changeset(1)) 116 cache.removeChangesetCacheListener listener 101 Changeset cs = new Changeset(1); 102 cache.update(cs); 103 104 assertTrue(cache.contains(1)); 105 assertTrue(cache.contains(cs)); 106 assertTrue(cache.contains(new Changeset(cs))); 107 108 assertFalse(cache.contains(2)); 109 assertFalse(cache.contains(new Changeset(2))); 110 assertFalse(cache.contains(null)); 117 111 } 118 112 119 113 @Test 120 public void fireingEvents UpdateChangeset(){121 ChangesetCache cache = ChangesetCache.getInstance() 122 cache.clear() 123 cache.@listeners.clear()114 public void fireingEventsAddAChangeset() throws ReflectiveOperationException { 115 ChangesetCache cache = ChangesetCache.getInstance(); 116 cache.clear(); 117 getListeners(cache).clear(); 124 118 125 119 // should work 126 def listener = new ChangesetCacheListener() { 127 public void changesetCacheUpdated(ChangesetCacheEvent event) { 128 assert event != null 129 assert event.getAddedChangesets().empty 130 assert event.getRemovedChangesets().empty 131 assert event.getUpdatedChangesets().size() == 1 132 assert event.getSource() == cache 133 } 134 } 135 cache.update(new Changeset(1)) 136 137 cache.addChangesetCacheListener listener 138 cache.update(new Changeset(1)) 139 cache.removeChangesetCacheListener listener 120 ChangesetCacheListener listener = new ChangesetCacheListener() { 121 @Override 122 public void changesetCacheUpdated(ChangesetCacheEvent event) { 123 assertNotNull(event); 124 assertEquals(1, event.getAddedChangesets().size()); 125 assertTrue(event.getRemovedChangesets().isEmpty()); 126 assertTrue(event.getUpdatedChangesets().isEmpty()); 127 assertEquals(cache, event.getSource()); 128 } 129 }; 130 cache.addChangesetCacheListener(listener); 131 cache.update(new Changeset(1)); 132 cache.removeChangesetCacheListener(listener); 140 133 } 141 134 142 135 @Test 143 public void fireingEvents RemoveChangeset(){144 ChangesetCache cache = ChangesetCache.getInstance() 145 cache.clear() 146 cache.@listeners.clear()136 public void fireingEventsUpdateChangeset() throws ReflectiveOperationException { 137 ChangesetCache cache = ChangesetCache.getInstance(); 138 cache.clear(); 139 getListeners(cache).clear(); 147 140 148 141 // should work 149 def listener = new ChangesetCacheListener() { 150 public void changesetCacheUpdated(ChangesetCacheEvent event) { 151 assert event != null 152 assert event.getAddedChangesets().empty 153 assert event.getRemovedChangesets().size() == 1 154 assert event.getUpdatedChangesets().empty 155 assert event.getSource() == cache 156 } 157 } 158 cache.update(new Changeset(1)) 142 ChangesetCacheListener listener = new ChangesetCacheListener() { 143 @Override 144 public void changesetCacheUpdated(ChangesetCacheEvent event) { 145 assertNotNull(event); 146 assertTrue(event.getAddedChangesets().isEmpty()); 147 assertTrue(event.getRemovedChangesets().isEmpty()); 148 assertEquals(1, event.getUpdatedChangesets().size()); 149 assertEquals(cache, event.getSource()); 150 } 151 }; 152 cache.update(new Changeset(1)); 159 153 160 cache.addChangesetCacheListener listener 161 cache.remove 1 162 cache.removeChangesetCacheListener listener 154 cache.addChangesetCacheListener(listener); 155 cache.update(new Changeset(1)); 156 cache.removeChangesetCacheListener(listener); 157 } 158 159 @Test 160 public void fireingEventsRemoveChangeset() throws ReflectiveOperationException { 161 ChangesetCache cache = ChangesetCache.getInstance(); 162 cache.clear(); 163 getListeners(cache).clear(); 164 165 // should work 166 ChangesetCacheListener listener = new ChangesetCacheListener() { 167 @Override 168 public void changesetCacheUpdated(ChangesetCacheEvent event) { 169 assertNotNull(event); 170 assertTrue(event.getAddedChangesets().isEmpty()); 171 assertEquals(1, event.getRemovedChangesets().size()); 172 assertTrue(event.getUpdatedChangesets().isEmpty()); 173 assertEquals(cache, event.getSource()); 174 } 175 }; 176 cache.update(new Changeset(1)); 177 178 cache.addChangesetCacheListener(listener); 179 cache.remove(1); 180 cache.removeChangesetCacheListener(listener); 163 181 } 164 182 } -
trunk/test/unit/org/openstreetmap/josm/data/osm/SimplePrimitiveIdTest.java
r11095 r11104 1 package org.openstreetmap.josm.data.osm 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.data.osm; 2 3 3 class SimplePrimitiveIdTest extends GroovyTestCase { 4 import static org.junit.Assert.assertEquals; 4 5 5 void testNode() { 6 assert SimplePrimitiveId.fromString("node/123") == new SimplePrimitiveId(123, OsmPrimitiveType.NODE) 7 assert SimplePrimitiveId.fromString("n123") == new SimplePrimitiveId(123, OsmPrimitiveType.NODE) 8 assert SimplePrimitiveId.fromString("node123") == new SimplePrimitiveId(123, OsmPrimitiveType.NODE) 9 assert SimplePrimitiveId.fromString("n123456789123456789") == new SimplePrimitiveId(123456789123456789, OsmPrimitiveType.NODE) 6 import org.junit.Test; 7 8 /** 9 * Unit tests of {@link SimplePrimitiveId} class. 10 */ 11 public class SimplePrimitiveIdTest { 12 13 /** 14 * Unit test of {@link SimplePrimitiveId#fromString} for nodes. 15 */ 16 @Test 17 public void testFromStringNode() { 18 assertEquals(new SimplePrimitiveId(123, OsmPrimitiveType.NODE), SimplePrimitiveId.fromString("node/123")); 19 assertEquals(new SimplePrimitiveId(123, OsmPrimitiveType.NODE), SimplePrimitiveId.fromString("n123")); 20 assertEquals(new SimplePrimitiveId(123, OsmPrimitiveType.NODE), SimplePrimitiveId.fromString("node123")); 21 assertEquals(new SimplePrimitiveId(123456789123456789L, OsmPrimitiveType.NODE), SimplePrimitiveId.fromString("n123456789123456789")); 10 22 } 11 23 12 void testWay() { 13 assert SimplePrimitiveId.fromString("way/123") == new SimplePrimitiveId(123, OsmPrimitiveType.WAY) 14 assert SimplePrimitiveId.fromString("w123") == new SimplePrimitiveId(123, OsmPrimitiveType.WAY) 15 assert SimplePrimitiveId.fromString("way123") == new SimplePrimitiveId(123, OsmPrimitiveType.WAY) 16 assert SimplePrimitiveId.fromString("w123456789123456789") == new SimplePrimitiveId(123456789123456789, OsmPrimitiveType.WAY) 24 /** 25 * Unit test of {@link SimplePrimitiveId#fromString} for ways. 26 */ 27 @Test 28 public void testFromStringWay() { 29 assertEquals(new SimplePrimitiveId(123, OsmPrimitiveType.WAY), SimplePrimitiveId.fromString("way/123")); 30 assertEquals(new SimplePrimitiveId(123, OsmPrimitiveType.WAY), SimplePrimitiveId.fromString("w123")); 31 assertEquals(new SimplePrimitiveId(123, OsmPrimitiveType.WAY), SimplePrimitiveId.fromString("way123")); 32 assertEquals(new SimplePrimitiveId(123456789123456789L, OsmPrimitiveType.WAY), SimplePrimitiveId.fromString("w123456789123456789")); 17 33 } 18 34 19 void testRelation() { 20 assert SimplePrimitiveId.fromString("relation/123") == new SimplePrimitiveId(123, OsmPrimitiveType.RELATION) 21 assert SimplePrimitiveId.fromString("r123") == new SimplePrimitiveId(123, OsmPrimitiveType.RELATION) 22 assert SimplePrimitiveId.fromString("rel123") == new SimplePrimitiveId(123, OsmPrimitiveType.RELATION) 23 assert SimplePrimitiveId.fromString("relation123") == new SimplePrimitiveId(123, OsmPrimitiveType.RELATION) 35 /** 36 * Unit test of {@link SimplePrimitiveId#fromString} for relations. 37 */ 38 @Test 39 public void testFromStringRelation() { 40 assertEquals(new SimplePrimitiveId(123, OsmPrimitiveType.RELATION), SimplePrimitiveId.fromString("relation/123")); 41 assertEquals(new SimplePrimitiveId(123, OsmPrimitiveType.RELATION), SimplePrimitiveId.fromString("r123")); 42 assertEquals(new SimplePrimitiveId(123, OsmPrimitiveType.RELATION), SimplePrimitiveId.fromString("rel123")); 43 assertEquals(new SimplePrimitiveId(123, OsmPrimitiveType.RELATION), SimplePrimitiveId.fromString("relation123")); 24 44 } 25 45 26 void testBad() { 27 shouldFail { SimplePrimitiveId.fromString("foobar") } 46 /** 47 * Unit test of {@link SimplePrimitiveId#fromString} for invalid input. 48 */ 49 @Test(expected = IllegalArgumentException.class) 50 public void testFromStringBad() { 51 SimplePrimitiveId.fromString("foobar"); 28 52 } 29 53 30 void testFuzzy() { 31 assert SimplePrimitiveId.fuzzyParse("foo relation/123 bar").toString() == "[relation 123]" 32 assert SimplePrimitiveId.fuzzyParse("foo relation/123 and way/345 but also node/789").toString() == "[relation 123, way 345, node 789]" 33 assert SimplePrimitiveId.fuzzyParse("foo relation/123-24 and way/345-346 but also node/789").toString() == "[relation 123, relation 124, way 345, way 346, node 789]" 54 /** 55 * Unit test of {@link SimplePrimitiveId#fuzzyParse}. 56 */ 57 @Test 58 public void testFuzzyParse() { 59 assertEquals("[relation 123]", 60 SimplePrimitiveId.fuzzyParse("foo relation/123 bar").toString()); 61 assertEquals("[relation 123, way 345, node 789]", 62 SimplePrimitiveId.fuzzyParse("foo relation/123 and way/345 but also node/789").toString()); 63 assertEquals("[relation 123, relation 124, way 345, way 346, node 789]", 64 SimplePrimitiveId.fuzzyParse("foo relation/123-24 and way/345-346 but also node/789").toString()); 34 65 } 35 66 36 void testFromCopyAction() { 37 assert SimplePrimitiveId.fromString("node 123") == new SimplePrimitiveId(123, OsmPrimitiveType.NODE) 38 assert SimplePrimitiveId.fromString("way 123") == new SimplePrimitiveId(123, OsmPrimitiveType.WAY) 39 assert SimplePrimitiveId.fromString("relation 123") == new SimplePrimitiveId(123, OsmPrimitiveType.RELATION) 67 @Test 68 public void testFromCopyAction() { 69 assertEquals(new SimplePrimitiveId(123, OsmPrimitiveType.NODE), SimplePrimitiveId.fromString("node 123")); 70 assertEquals(new SimplePrimitiveId(123, OsmPrimitiveType.WAY), SimplePrimitiveId.fromString("way 123")); 71 assertEquals(new SimplePrimitiveId(123, OsmPrimitiveType.RELATION), SimplePrimitiveId.fromString("relation 123")); 40 72 } 41 73 42 void testMultipleIDs() { 43 assert SimplePrimitiveId.multipleFromString("node/234").toString() == "[node 234]" 44 assert SimplePrimitiveId.multipleFromString("node/234-234").toString() == "[node 234]" 45 assert SimplePrimitiveId.multipleFromString("node/2-1").toString() == "[]" 46 assert SimplePrimitiveId.multipleFromString("node/123-124").toString() == "[node 123, node 124]" 47 assert SimplePrimitiveId.multipleFromString("n/123-124").toString() == "[node 123, node 124]" 48 assert SimplePrimitiveId.multipleFromString("node123-126").toString() == "[node 123, node 124, node 125, node 126]" 49 assert SimplePrimitiveId.multipleFromString("way/123-123").toString() == "[way 123]" 50 assert SimplePrimitiveId.multipleFromString("w/123-127").toString() == "[way 123, way 124, way 125, way 126, way 127]" 51 assert SimplePrimitiveId.multipleFromString("way123-125").toString() == "[way 123, way 124, way 125]" 52 assert SimplePrimitiveId.multipleFromString("relation/123-125").toString() == "[relation 123, relation 124, relation 125]" 53 assert SimplePrimitiveId.multipleFromString("r/123-125").toString() == "[relation 123, relation 124, relation 125]" 54 assert SimplePrimitiveId.multipleFromString("relation123-125").toString() == "[relation 123, relation 124, relation 125]" 55 assert SimplePrimitiveId.multipleFromString("node/234-5").toString() == "[node 234, node 235]" 56 assert SimplePrimitiveId.multipleFromString("node/234-35").toString() == "[node 234, node 235]" 57 assert SimplePrimitiveId.multipleFromString("node/234-235").toString() == "[node 234, node 235]" 58 assert SimplePrimitiveId.multipleFromString("node/998-1001").toString() == "[node 998, node 999, node 1000, node 1001]" 59 shouldFail { SimplePrimitiveId.multipleFromString("foo node123 bar") } 74 /** 75 * Unit test of {@link SimplePrimitiveId#multipleFromString}. 76 */ 77 @Test 78 public void testMultipleFromString() { 79 assertEquals("[node 234]", SimplePrimitiveId.multipleFromString("node/234").toString()); 80 assertEquals("[node 234]", SimplePrimitiveId.multipleFromString("node/234-234").toString()); 81 assertEquals("[]", SimplePrimitiveId.multipleFromString("node/2-1").toString()); 82 assertEquals("[node 123, node 124]", SimplePrimitiveId.multipleFromString("node/123-124").toString()); 83 assertEquals("[node 123, node 124]", SimplePrimitiveId.multipleFromString("n/123-124").toString()); 84 assertEquals("[node 123, node 124, node 125, node 126]", SimplePrimitiveId.multipleFromString("node123-126").toString()); 85 assertEquals("[way 123]", SimplePrimitiveId.multipleFromString("way/123-123").toString()); 86 assertEquals("[way 123, way 124, way 125, way 126, way 127]", SimplePrimitiveId.multipleFromString("w/123-127").toString()); 87 assertEquals("[way 123, way 124, way 125]", SimplePrimitiveId.multipleFromString("way123-125").toString()); 88 assertEquals("[relation 123, relation 124, relation 125]", SimplePrimitiveId.multipleFromString("relation/123-125").toString()); 89 assertEquals("[relation 123, relation 124, relation 125]", SimplePrimitiveId.multipleFromString("r/123-125").toString()); 90 assertEquals("[relation 123, relation 124, relation 125]", SimplePrimitiveId.multipleFromString("relation123-125").toString()); 91 assertEquals("[node 234, node 235]", SimplePrimitiveId.multipleFromString("node/234-5").toString()); 92 assertEquals("[node 234, node 235]", SimplePrimitiveId.multipleFromString("node/234-35").toString()); 93 assertEquals("[node 234, node 235]", SimplePrimitiveId.multipleFromString("node/234-235").toString()); 94 assertEquals("[node 998, node 999, node 1000, node 1001]", SimplePrimitiveId.multipleFromString("node/998-1001").toString()); 95 } 96 97 /** 98 * Unit test of {@link SimplePrimitiveId#multipleFromString} for invalid data. 99 */ 100 @Test(expected = IllegalArgumentException.class) 101 public void testMultipleFromStringBad() { 102 SimplePrimitiveId.multipleFromString("foo node123 bar"); 60 103 } 61 104 }
Note:
See TracChangeset
for help on using the changeset viewer.