Changeset 11104 in josm for trunk


Ignore:
Timestamp:
2016-10-08T15:28:54+02:00 (8 years ago)
Author:
Don-vip
Message:

convert unit tests from Groovy to Java

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  
    99import java.io.IOException;
    1010import java.io.InputStream;
     11import java.lang.reflect.Field;
    1112import java.util.Arrays;
    1213import java.util.Collection;
     
    164165
    165166    /**
     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    /**
    166180     * Returns an instance of {@link AbstractProgressMonitor} which keeps track of the monitor state,
    167181     * 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.
     2package org.openstreetmap.josm.actions;
    23
    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
     4import static org.junit.Assert.assertEquals;
    135
     6import java.io.FileInputStream;
     7import java.util.Collection;
     8import java.util.Map;
     9import java.util.TreeMap;
     10
     11import org.junit.Rule;
     12import org.junit.Test;
     13import org.openstreetmap.josm.TestUtils;
     14import org.openstreetmap.josm.actions.search.SearchAction.SearchSetting;
     15import org.openstreetmap.josm.actions.search.SearchCompiler;
     16import org.openstreetmap.josm.actions.search.SearchCompiler.ParseError;
     17import org.openstreetmap.josm.command.SequenceCommand;
     18import org.openstreetmap.josm.data.osm.DataSet;
     19import org.openstreetmap.josm.data.osm.Relation;
     20import org.openstreetmap.josm.data.osm.RelationMember;
     21import org.openstreetmap.josm.data.osm.Way;
     22import org.openstreetmap.josm.io.OsmReader;
     23import org.openstreetmap.josm.testutils.JOSMTestRules;
     24import org.openstreetmap.josm.tools.Pair;
     25import org.openstreetmap.josm.tools.SubclassFilteredCollection;
     26
     27import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     28
     29/**
     30 * Unit test of {@link CreateMultipolygonAction}
     31 */
    1432public class CreateMultipolygonActionTest {
    1533
    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();
    2040
    21     static def getRefToRoleMap(Relation relation) {
    22         def refToRole = new TreeMap<String, String>()
    23         for (i in relation.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());
    2545        }
    2646        return refToRole;
    2747    }
    2848
    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);
    3461    }
    3562
    3663    @Test
    37     public void testCreate1() {
    38         def ds = 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());
    4269    }
    4370
    4471    @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());
    5076    }
    5177
    5278    @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());
    6387    }
    6488
    6589    @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());
    7496    }
    7597}
  • trunk/test/unit/org/openstreetmap/josm/data/osm/ChangesetCacheTest.java

    r11095 r11104  
    22package org.openstreetmap.josm.data.osm;
    33
    4 import static org.junit.Assert.*
     4import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertFalse;
     6import static org.junit.Assert.assertNotNull;
     7import static org.junit.Assert.assertTrue;
    58
    6 import org.junit.Test
     9import java.util.List;
    710
    8 class ChangesetCacheTest {
     11import org.junit.Test;
     12import org.openstreetmap.josm.TestUtils;
    913
     14/**
     15 * Unit test of {@link ChangesetCache}
     16 */
     17public class ChangesetCacheTest {
     18
     19    /**
     20     * Unit test of {@link ChangesetCache#ChangesetCache}
     21     */
    1022    @Test
    1123    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");
    1430    }
    1531
    1632    @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();
    2036
    2137        // should work
    22         cache.addChangesetCacheListener null
     38        cache.addChangesetCacheListener(null);
    2339
    2440        // should work
    25         def listener = new ChangesetCacheListener() {
     41        ChangesetCacheListener listener = new ChangesetCacheListener() {
     42            @Override
    2643            public void changesetCacheUpdated(ChangesetCacheEvent event) {}
    27         }
    28         cache.addChangesetCacheListener listener
     44        };
     45        cache.addChangesetCacheListener(listener);
    2946        // adding a second time - should work too
    30         cache.addChangesetCacheListener listener
    31         assert cache.@listeners.size() == 1 // ... but only added once
     47        cache.addChangesetCacheListener(listener);
     48        assertEquals(1, getListeners(cache).size()); // ... but only added once
    3249
    33         cache.removeChangesetCacheListener null
     50        cache.removeChangesetCacheListener(null);
    3451
    35         cache.removeChangesetCacheListener listener
    36         assert cache.@listeners.size() == 0
     52        cache.removeChangesetCacheListener(listener);
     53        assertTrue(getListeners(cache).isEmpty());
    3754    }
    3855
    3956    @Test
    4057    public void updateGetRemoveCycle() {
    41         ChangesetCache cache = ChangesetCache.getInstance()
    42         cache.clear()
     58        ChangesetCache cache = ChangesetCache.getInstance();
     59        cache.clear();
    4360
    44         cache.update new Changeset(1)
    45         assert cache.size() == 1
    46         assert cache.get(1) != null
    47         assert cache.get(1).id == 1
    48         cache.remove(1)
    49         assert cache.size() == 0
     61        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());
    5067    }
    5168
    5269    @Test
    5370    public void updateTwice() {
    54         ChangesetCache cache = ChangesetCache.getInstance()
    55         cache.clear()
     71        ChangesetCache cache = ChangesetCache.getInstance();
     72        cache.clear();
    5673
    57         Changeset cs = new Changeset(1)
    58         cs.incomplete = false
    59         cs.put "key1", "value1"
    60         cs.open = true
    61         cache.update cs
     74        Changeset cs = new Changeset(1);
     75        cs.setIncomplete(false);
     76        cs.put("key1", "value1");
     77        cs.setOpen(true);
     78        cache.update(cs);
    6279
    63         Changeset cs2 = new Changeset(cs)
    64         assert cs2 != null
    65         cs2.put "key2", "value2"
    66         cs2.open = false
    67         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);
    6885
    69         assert cache.size() == 1
    70         assert cache.get(1) != null
     86        assertEquals(1, cache.size());
     87        assertNotNull(cache.get(1));
    7188
    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());
    9693    }
    9794
    9895    @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();
    103100
    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));
    117111    }
    118112
    119113    @Test
    120     public void fireingEventsUpdateChangeset() {
    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();
    124118
    125119        // 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);
    140133    }
    141134
    142135    @Test
    143     public void fireingEventsRemoveChangeset() {
    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();
    147140
    148141        // 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));
    159153
    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);
    163181    }
    164182}
  • 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.
     2package org.openstreetmap.josm.data.osm;
    23
    3 class SimplePrimitiveIdTest extends GroovyTestCase {
     4import static org.junit.Assert.assertEquals;
    45
    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)
     6import org.junit.Test;
     7
     8/**
     9 * Unit tests of {@link SimplePrimitiveId} class.
     10 */
     11public 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"));
    1022    }
    1123
    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"));
    1733    }
    1834
    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"));
    2444    }
    2545
    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");
    2852    }
    2953
    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());
    3465    }
    3566
    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"));
    4072    }
    4173
    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");
    60103    }
    61104}
Note: See TracChangeset for help on using the changeset viewer.