Changeset 11403 in josm


Ignore:
Timestamp:
2016-12-15T08:13:49+01:00 (3 years ago)
Author:
Don-vip
Message:

replace groovy validator unit tests by java ones

Location:
trunk/test/unit/org/openstreetmap/josm/data/validation/tests
Files:
5 moved

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/ConditionalKeysTest.java

    r11390 r11403  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.data.validation.tests
     2package org.openstreetmap.josm.data.validation.tests;
    33
    4 import org.openstreetmap.josm.JOSMFixture
     4import static org.junit.Assert.assertFalse;
     5import static org.junit.Assert.assertTrue;
     6
     7import org.junit.Before;
     8import org.junit.Test;
     9import org.openstreetmap.josm.JOSMFixture;
    510import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
    611
    7 class ConditionalKeysTest extends GroovyTestCase {
     12/**
     13 * Unit test of {@link ConditionalKeys}.
     14 */
     15public class ConditionalKeysTest {
    816
    9     ConditionalKeys test = new ConditionalKeys()
     17    private final ConditionalKeys test = new ConditionalKeys();
    1018
    11     @Override
    12     void setUp() {
     19    /**
     20     * Setup test
     21     * @throws Exception if an error occurs
     22     */
     23    @Before
     24    public void setUp() throws Exception {
    1325        JOSMFixture.createUnitTestFixture().init();
    14         TaggingPresets.readFromPreferences()
    15         test.initialize()
     26        TaggingPresets.readFromPreferences();
     27        test.initialize();
    1628    }
    1729
    18     void testKeyValid() {
    19         assert test.isKeyValid("maxspeed:conditional")
    20         assert test.isKeyValid("motor_vehicle:conditional")
    21         assert test.isKeyValid("bicycle:conditional")
    22         assert test.isKeyValid("overtaking:hgv:conditional")
    23         assert test.isKeyValid("maxspeed:hgv:backward:conditional")
    24         assert test.isKeyValid("oneway:backward:conditional")
    25         assert test.isKeyValid("fee:conditional")
    26         assert !test.isKeyValid("maxspeed:hgv:conditional:backward")
     30    /**
     31     * Unit test of {@link ConditionalKeys#isKeyValid}.
     32     */
     33    @Test
     34    public void testKeyValid() {
     35        assertTrue(test.isKeyValid("maxspeed:conditional"));
     36        assertTrue(test.isKeyValid("motor_vehicle:conditional"));
     37        assertTrue(test.isKeyValid("bicycle:conditional"));
     38        assertTrue(test.isKeyValid("overtaking:hgv:conditional"));
     39        assertTrue(test.isKeyValid("maxspeed:hgv:backward:conditional"));
     40        assertTrue(test.isKeyValid("oneway:backward:conditional"));
     41        assertTrue(test.isKeyValid("fee:conditional"));
     42        assertFalse(test.isKeyValid("maxspeed:hgv:conditional:backward"));
    2743    }
    2844
    29     void testValueValid() {
    30         assert test.isValueValid("maxspeed:conditional", "120 @ (06:00-19:00)")
    31         assert !test.isValueValid("maxspeed:conditional", " @ (06:00-19:00)")
    32         assert !test.isValueValid("maxspeed:conditional", "120 (06:00-19:00)")
    33         assert !test.isValueValid("maxspeed:conditional", "120 @ ()")
    34         assert !test.isValueValid("maxspeed:conditional", "120 @ ")
    35         assert !test.isValueValid("maxspeed:conditional", "120 @ (06:00/19:00)")
    36         assert test.isValueValid("maxspeed:conditional", "120 @ (06:00-20:00); 100 @ (22:00-06:00)")
    37         assert test.isValueValid("motor_vehicle:conditional", "delivery @ (Mo-Fr 06:00-11:00,17:00-19:00;Sa 03:30-19:00)")
    38         assert test.isValueValid("motor_vehicle:conditional", "no @ (10:00-18:00 AND length>5)")
    39         assert !test.isValueValid("motor_vehicle:conditional", "foo @ (10:00-18:00 AND length>5)")
    40         assert !test.isValueValid("motor_vehicle:conditional", "no @ (10:00until18:00 AND length>5)")
    41         assert test.isValueValid("maxspeed:hgv:conditional", "60 @ (weight>7.5)")
     45    /**
     46     * Unit test of {@link ConditionalKeys#isValueValid}.
     47     */
     48    @Test
     49    public void testValueValid() {
     50        assertTrue(test.isValueValid("maxspeed:conditional", "120 @ (06:00-19:00)"));
     51        assertFalse(test.isValueValid("maxspeed:conditional", " @ (06:00-19:00)"));
     52        assertFalse(test.isValueValid("maxspeed:conditional", "120 (06:00-19:00)"));
     53        assertFalse(test.isValueValid("maxspeed:conditional", "120 @ ()"));
     54        assertFalse(test.isValueValid("maxspeed:conditional", "120 @ "));
     55        assertFalse(test.isValueValid("maxspeed:conditional", "120 @ (06:00/19:00)"));
     56        assertTrue(test.isValueValid("maxspeed:conditional", "120 @ (06:00-20:00); 100 @ (22:00-06:00)"));
     57        assertTrue(test.isValueValid("motor_vehicle:conditional", "delivery @ (Mo-Fr 06:00-11:00,17:00-19:00;Sa 03:30-19:00)"));
     58        assertTrue(test.isValueValid("motor_vehicle:conditional", "no @ (10:00-18:00 AND length>5)"));
     59        assertFalse(test.isValueValid("motor_vehicle:conditional", "foo @ (10:00-18:00 AND length>5)"));
     60        assertFalse(test.isValueValid("motor_vehicle:conditional", "no @ (10:00until18:00 AND length>5)"));
     61        assertTrue(test.isValueValid("maxspeed:hgv:conditional", "60 @ (weight>7.5)"));
    4262    }
    4363}
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/HighwaysTest.java

    r11390 r11403  
    1 // License: GPL. See LICENSE file for details.
    2 package org.openstreetmap.josm.data.validation.tests
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.data.validation.tests;
    33
    4 import org.openstreetmap.josm.JOSMFixture
    5 import org.openstreetmap.josm.data.coor.LatLon
    6 import org.openstreetmap.josm.data.osm.DataSet
    7 import org.openstreetmap.josm.data.osm.Node
    8 import org.openstreetmap.josm.data.osm.Way
     4import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertFalse;
     6import static org.junit.Assert.assertTrue;
    97
    10 class HighwaysTest extends GroovyTestCase {
     8import org.junit.Before;
     9import org.junit.Test;
     10import org.openstreetmap.josm.JOSMFixture;
     11import org.openstreetmap.josm.data.coor.LatLon;
     12import org.openstreetmap.josm.data.osm.DataSet;
     13import org.openstreetmap.josm.data.osm.Node;
     14import org.openstreetmap.josm.data.osm.Way;
     15import org.openstreetmap.josm.data.validation.TestError;
    1116
    12     @Override
    13     void setUp() {
     17/**
     18 * Unit test of {@link HighwaysTest}.
     19 */
     20public class HighwaysTest {
     21
     22    /**
     23     * Setup test.
     24     */
     25    @Before
     26    public void setUp() {
    1427        JOSMFixture.createUnitTestFixture().init();
    1528    }
    1629
    17     public static Way createTestSetting(String highway, String highwayLink) {
    18         def ds = new DataSet()
     30    private static Way createTestSetting(String highway, String highwayLink) {
     31        DataSet ds = new DataSet();
    1932
    20         def n00 = new Node(LatLon.ZERO)
    21         def n10 = new Node(new LatLon(1, 0))
    22         def n20 = new Node(new LatLon(2, 0))
    23         def n01 = new Node(new LatLon(0, 1))
    24         def n11 = new Node(new LatLon(1, 1))
    25         def n21 = new Node(new LatLon(2, 1))
     33        Node n00 = new Node(LatLon.ZERO);
     34        Node n10 = new Node(new LatLon(1, 0));
     35        Node n20 = new Node(new LatLon(2, 0));
     36        Node n01 = new Node(new LatLon(0, 1));
     37        Node n11 = new Node(new LatLon(1, 1));
     38        Node n21 = new Node(new LatLon(2, 1));
    2639
    27         ds.addPrimitive(n00)
    28         ds.addPrimitive(n10)
    29         ds.addPrimitive(n20)
    30         ds.addPrimitive(n01)
    31         ds.addPrimitive(n11)
    32         ds.addPrimitive(n21)
     40        ds.addPrimitive(n00);
     41        ds.addPrimitive(n10);
     42        ds.addPrimitive(n20);
     43        ds.addPrimitive(n01);
     44        ds.addPrimitive(n11);
     45        ds.addPrimitive(n21);
    3346
    34         def major = new Way()
    35         major.addNode(n00)
    36         major.addNode(n10)
    37         major.addNode(n20)
    38         major.put("highway", highway)
    39         def link = new Way()
    40         link.addNode(n10)
    41         link.addNode(n11)
    42         link.put("highway", highwayLink)
    43         def unclassified = new Way()
    44         unclassified.addNode(n01)
    45         unclassified.addNode(n11)
    46         unclassified.addNode(n21)
    47         unclassified.put("highway", "unclassified")
     47        Way major = new Way();
     48        major.addNode(n00);
     49        major.addNode(n10);
     50        major.addNode(n20);
     51        major.put("highway", highway);
     52        Way link = new Way();
     53        link.addNode(n10);
     54        link.addNode(n11);
     55        link.put("highway", highwayLink);
     56        Way unclassified = new Way();
     57        unclassified.addNode(n01);
     58        unclassified.addNode(n11);
     59        unclassified.addNode(n21);
     60        unclassified.put("highway", "unclassified");
    4861
    49         ds.addPrimitive(major)
    50         ds.addPrimitive(link)
    51         ds.addPrimitive(unclassified)
     62        ds.addPrimitive(major);
     63        ds.addPrimitive(link);
     64        ds.addPrimitive(unclassified);
    5265
    53         return link
     66        return link;
    5467    }
    5568
    56     void testCombinations() {
    57         assert Highways.isHighwayLinkOkay(createTestSetting("primary", "primary_link"))
    58         assert Highways.isHighwayLinkOkay(createTestSetting("primary", "primary"))
    59         assert !Highways.isHighwayLinkOkay(createTestSetting("primary", "secondary_link"))
    60         assert !Highways.isHighwayLinkOkay(createTestSetting("secondary", "primary_link"))
    61         assert !Highways.isHighwayLinkOkay(createTestSetting("secondary", "tertiary_link"))
    62         assert Highways.isHighwayLinkOkay(createTestSetting("residential", "residential"))
     69    /**
     70     * Unit test of {@link Highways#isHighwayLinkOkay}.
     71     */
     72    @Test
     73    public void testCombinations() {
     74        assertTrue(Highways.isHighwayLinkOkay(createTestSetting("primary", "primary_link")));
     75        assertTrue(Highways.isHighwayLinkOkay(createTestSetting("primary", "primary")));
     76        assertFalse(Highways.isHighwayLinkOkay(createTestSetting("primary", "secondary_link")));
     77        assertFalse(Highways.isHighwayLinkOkay(createTestSetting("secondary", "primary_link")));
     78        assertFalse(Highways.isHighwayLinkOkay(createTestSetting("secondary", "tertiary_link")));
     79        assertTrue(Highways.isHighwayLinkOkay(createTestSetting("residential", "residential")));
    6380    }
    6481
    65     void testSourceMaxSpeedUnitedKingdom() {
    66         def link = createTestSetting("primary", "primary")
    67         link.put("maxspeed", "60 mph")
    68         link.put("source:maxspeed", "UK:nsl_single")
    69         def test = new Highways()
    70         test.visit(link)
    71         assert test.errors.size() == 1
    72         def error = test.errors.get(0)
    73         assert error.isFixable()
    74         assert error.getFix().executeCommand()
    75         assert "GB:nsl_single".equals(link.get("source:maxspeed"))
     82    /**
     83     * Test source:maxspeed in United Kingdom.
     84     */
     85    @Test
     86    public void testSourceMaxSpeedUnitedKingdom() {
     87        Way link = createTestSetting("primary", "primary");
     88        link.put("maxspeed", "60 mph");
     89        link.put("source:maxspeed", "UK:nsl_single");
     90        Highways test = new Highways();
     91        test.visit(link);
     92        assertEquals(1, test.getErrors().size());
     93        TestError error = test.getErrors().get(0);
     94        assertTrue(error.isFixable());
     95        assertTrue(error.getFix().executeCommand());
     96        assertEquals("GB:nsl_single", link.get("source:maxspeed"));
    7697    }
    7798}
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/LanesTest.java

    r11390 r11403  
    1 package org.openstreetmap.josm.data.validation.tests
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.data.validation.tests;
    23
    3 import org.openstreetmap.josm.JOSMFixture
    4 import org.openstreetmap.josm.data.osm.OsmUtils
     4import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertTrue;
    56
    6 class LanesTest extends GroovyTestCase {
     7import org.junit.Before;
     8import org.junit.Test;
     9import org.openstreetmap.josm.JOSMFixture;
     10import org.openstreetmap.josm.data.osm.OsmUtils;
    711
    8     Lanes lanes = new Lanes()
     12/**
     13 * Unit tests of {@link Lanes}.
     14 */
     15public class LanesTest {
    916
    10     @Override
    11     void setUp() {
    12         JOSMFixture.createUnitTestFixture().init()
    13         lanes.initialize()
    14         lanes.startTest(null)
     17    private final Lanes lanes = new Lanes();
     18
     19    /**
     20     * Setup test.
     21     * @throws Exception if an error occurs
     22     */
     23    @Before
     24    public void setUp() throws Exception {
     25        JOSMFixture.createUnitTestFixture().init();
     26        lanes.initialize();
     27        lanes.startTest(null);
    1528    }
    1629
    17     void testLanesCount() {
    18         assert lanes.getLanesCount("") == 0
    19         assert lanes.getLanesCount("left") == 1
    20         assert lanes.getLanesCount("left|right") == 2
    21         assert lanes.getLanesCount("yes|no|yes") == 3
    22         assert lanes.getLanesCount("yes||") == 3
     30    /**
     31     * Unit test of {@link Lanes#getLanesCount}.
     32     */
     33    @Test
     34    public void testLanesCount() {
     35        assertEquals(0, Lanes.getLanesCount(""));
     36        assertEquals(1, Lanes.getLanesCount("left"));
     37        assertEquals(2, Lanes.getLanesCount("left|right"));
     38        assertEquals(3, Lanes.getLanesCount("yes|no|yes"));
     39        assertEquals(3, Lanes.getLanesCount("yes||"));
    2340    }
    2441
    25     void test1() {
    26         lanes.check(OsmUtils.createPrimitive("way turn:lanes=left|right change:lanes=only_left|not_right|yes"))
    27         assert lanes.errors.get(0).getMessage() == "Number of lane dependent values inconsistent"
     42    @Test
     43    public void test1() {
     44        lanes.check(OsmUtils.createPrimitive("way turn:lanes=left|right change:lanes=only_left|not_right|yes"));
     45        assertEquals("Number of lane dependent values inconsistent", lanes.getErrors().get(0).getMessage());
    2846    }
    2947
    30     void test2() {
    31         lanes.check(OsmUtils.createPrimitive("way width:lanes:forward=1|2|3 psv:lanes:forward=no|designated"))
    32         assert lanes.errors.get(0).getMessage() == "Number of lane dependent values inconsistent in forward direction"
     48    @Test
     49    public void test2() {
     50        lanes.check(OsmUtils.createPrimitive("way width:lanes:forward=1|2|3 psv:lanes:forward=no|designated"));
     51        assertEquals("Number of lane dependent values inconsistent in forward direction", lanes.getErrors().get(0).getMessage());
    3352    }
    3453
    35     void test3() {
    36         lanes.check(OsmUtils.createPrimitive("way change:lanes:forward=yes|no turn:lanes:backward=left|right|left"))
    37         assert lanes.errors.isEmpty()
     54    @Test
     55    public void test3() {
     56        lanes.check(OsmUtils.createPrimitive("way change:lanes:forward=yes|no turn:lanes:backward=left|right|left"));
     57        assertTrue(lanes.getErrors().isEmpty());
    3858    }
    3959
    40     void test4() {
    41         lanes.check(OsmUtils.createPrimitive("way turn:lanes:forward=left|right change:lanes:forward=yes|no|yes width:backward=1|2|3"))
    42         assert lanes.errors.get(0).getMessage() == "Number of lane dependent values inconsistent in forward direction"
     60    @Test
     61    public void test4() {
     62        lanes.check(OsmUtils.createPrimitive("way turn:lanes:forward=left|right change:lanes:forward=yes|no|yes width:backward=1|2|3"));
     63        assertEquals("Number of lane dependent values inconsistent in forward direction", lanes.getErrors().get(0).getMessage());
    4364    }
    4465
    45     void test5() {
    46         lanes.check(OsmUtils.createPrimitive("way lanes:forward=5 turn:lanes:forward=left|right"))
    47         assert lanes.errors.get(0).getMessage() == "Number of lanes:forward greater than *:lanes:forward"
     66    @Test
     67    public void test5() {
     68        lanes.check(OsmUtils.createPrimitive("way lanes:forward=5 turn:lanes:forward=left|right"));
     69        assertEquals("Number of lanes:forward greater than *:lanes:forward", lanes.getErrors().get(0).getMessage());
    4870    }
    4971
    50     void test6() {
    51         lanes.check(OsmUtils.createPrimitive("way lanes:forward=foo|bar turn:lanes:forward=foo+bar"))
    52         assert lanes.errors.isEmpty()
     72    @Test
     73    public void test6() {
     74        lanes.check(OsmUtils.createPrimitive("way lanes:forward=foo|bar turn:lanes:forward=foo+bar"));
     75        assertTrue(lanes.getErrors().isEmpty());
    5376    }
    5477
    55     void test7() {
    56         lanes.check(OsmUtils.createPrimitive("way lanes=3 lanes:forward=3 lanes:backward=7"))
    57         assert lanes.errors.get(0).getMessage() == "Number of lanes:forward+lanes:backward greater than lanes"
     78    @Test
     79    public void test7() {
     80        lanes.check(OsmUtils.createPrimitive("way lanes=3 lanes:forward=3 lanes:backward=7"));
     81        assertEquals("Number of lanes:forward+lanes:backward greater than lanes", lanes.getErrors().get(0).getMessage());
    5882    }
    5983
    60     void test8() {
    61         lanes.check(OsmUtils.createPrimitive("way destination:country:lanes=X|Y;Z|none destination:ref:lanes=xyz|| destination:sign:lanes=none|airport|none"))
    62         assert lanes.errors.isEmpty()
     84    @Test
     85    public void test8() {
     86        lanes.check(OsmUtils.createPrimitive(
     87                "way destination:country:lanes=X|Y;Z|none destination:ref:lanes=xyz|| destination:sign:lanes=none|airport|none"));
     88        assertTrue(lanes.getErrors().isEmpty());
    6389    }
    6490
    65     void test9() {
    66         lanes.check(OsmUtils.createPrimitive("way highway=secondary lanes=2 source:lanes=survey"))
    67         assert lanes.errors.isEmpty()
     91    @Test
     92    public void test9() {
     93        lanes.check(OsmUtils.createPrimitive("way highway=secondary lanes=2 source:lanes=survey"));
     94        assertTrue(lanes.getErrors().isEmpty());
    6895    }
    6996}
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/RelationCheckerTest.java

    r11390 r11403  
    11// License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.data.validation.tests
     2package org.openstreetmap.josm.data.validation.tests;
    33
    4 import static org.openstreetmap.josm.data.osm.OsmUtils.createPrimitive
     4import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertTrue;
     6import static org.openstreetmap.josm.data.osm.OsmUtils.createPrimitive;
    57
    6 import org.openstreetmap.josm.JOSMFixture
    7 import org.openstreetmap.josm.data.osm.Relation
    8 import org.openstreetmap.josm.data.osm.RelationMember
    9 import org.openstreetmap.josm.data.osm.Way
    10 import org.openstreetmap.josm.data.validation.TestError
     8import java.util.List;
     9
     10import org.junit.Before;
     11import org.junit.Test;
     12import org.openstreetmap.josm.JOSMFixture;
     13import org.openstreetmap.josm.data.osm.Relation;
     14import org.openstreetmap.josm.data.osm.RelationMember;
     15import org.openstreetmap.josm.data.osm.Way;
     16import org.openstreetmap.josm.data.validation.TestError;
    1117import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets;
    1218
    13 class RelationCheckerTest extends GroovyTestCase {
     19public class RelationCheckerTest {
    1420
    15     @Override
    16     void setUp() {
     21    /**
     22     * Setup test.
     23     */
     24    @Before
     25    public void setUp() {
    1726        JOSMFixture.createUnitTestFixture().init();
    18         getRelationChecker()
     27        getRelationChecker();
    1928    }
    2029
    21     static def RelationChecker getRelationChecker() {
    22         def checker = new RelationChecker()
    23         TaggingPresets.readFromPreferences()
    24         checker.initialize()
    25         return checker
     30    private static RelationChecker getRelationChecker() {
     31        RelationChecker checker = new RelationChecker();
     32        TaggingPresets.readFromPreferences();
     33        checker.initialize();
     34        return checker;
    2635    }
    2736
    28     static def List<TestError> testRelation(Relation r) {
    29         def checker = getRelationChecker()
    30         checker.visit(r)
    31         return checker.getErrors()
     37    private static List<TestError> testRelation(Relation r) {
     38        RelationChecker checker = getRelationChecker();
     39        checker.visit(r);
     40        return checker.getErrors();
    3241    }
    3342
    34     static def Relation createRelation(String tags) {
    35         return (Relation) createPrimitive("relation "+ tags)
     43    private static Relation createRelation(String tags) {
     44        return (Relation) createPrimitive("relation "+ tags);
    3645    }
    3746
    38     void testUnknownType() {
    39         def errors = testRelation(createRelation("type=foobar"))
    40         assert errors.size() >= 1
    41         assert errors.get(0).getMessage() == "Relation type is unknown"
     47    @Test
     48    public void testUnknownType() {
     49        List<TestError> errors = testRelation(createRelation("type=foobar"));
     50        assertTrue(errors.size() >= 1);
     51        assertEquals("Relation type is unknown", errors.get(0).getMessage());
    4252    }
    4353
    44     void testEmpty() {
    45         def errors = testRelation(createRelation("type=multipolygon"))
    46         assert errors.size() == 1
    47         assert errors.get(0).getMessage() == "Relation is empty"
     54    @Test
     55    public void testEmpty() {
     56        List<TestError> errors = testRelation(createRelation("type=multipolygon"));
     57        assertEquals(1, errors.size());
     58        assertEquals("Relation is empty", errors.get(0).getMessage());
    4859    }
    4960
    50     void testNormal() {
    51         def r = createRelation("type=multipolygon")
    52         r.addMember(new RelationMember("outer", new Way()))
    53         r.addMember(new RelationMember("inner", new Way()))
    54         assert testRelation(r).isEmpty()
     61    @Test
     62    public void testNormal() {
     63        Relation r = createRelation("type=multipolygon");
     64        r.addMember(new RelationMember("outer", new Way()));
     65        r.addMember(new RelationMember("inner", new Way()));
     66        assertTrue(testRelation(r).isEmpty());
    5567    }
    5668
    57     void testOuter2() {
    58         def r = createRelation("type=multipolygon")
    59         r.addMember(new RelationMember("outer", new Way()))
    60         r.addMember(new RelationMember("outer2", new Way()))
     69    @Test
     70    public void testOuter2() {
     71        Relation r = createRelation("type=multipolygon");
     72        r.addMember(new RelationMember("outer", new Way()));
     73        r.addMember(new RelationMember("outer2", new Way()));
    6174
    62         def errors = testRelation(r)
    63         assert errors.size() == 1
    64         assert errors.get(0).getDescription() == "Role outer2 unknown in templates outer/inner"
     75        List<TestError> errors = testRelation(r);
     76        assertEquals(1, errors.size());
     77        assertEquals("Role outer2 unknown in templates outer/inner", errors.get(0).getDescription());
    6578    }
    6679
    67     void testRestrictionViaMissing() {
    68         def r = createRelation("type=restriction")
    69         r.addMember(new RelationMember("from", new Way()))
    70         r.addMember(new RelationMember("to", new Way()))
     80    @Test
     81    public void testRestrictionViaMissing() {
     82        Relation r = createRelation("type=restriction");
     83        r.addMember(new RelationMember("from", new Way()));
     84        r.addMember(new RelationMember("to", new Way()));
    7185
    72         def errors = testRelation(r)
    73         assert errors.size() == 1
    74         assert errors.get(0).getDescription() == "Role via missing"
     86        List<TestError> errors = testRelation(r);
     87        assertEquals(1, errors.size());
     88        assertEquals("Role via missing", errors.get(0).getDescription());
    7589    }
    7690
    77     void testRestrictionViaRelation() {
    78         def r = createRelation("type=restriction")
    79         r.addMember(new RelationMember("from", new Way()))
    80         r.addMember(new RelationMember("to", new Way()))
    81         r.addMember(new RelationMember("via", new Relation()))
     91    @Test
     92    public void testRestrictionViaRelation() {
     93        Relation r = createRelation("type=restriction");
     94        r.addMember(new RelationMember("from", new Way()));
     95        r.addMember(new RelationMember("to", new Way()));
     96        r.addMember(new RelationMember("via", new Relation()));
    8297
    83         def errors = testRelation(r)
    84         assert errors.size() == 1
    85         assert errors.get(0).getDescription() == "Role member type relation does not match accepted list of node/way in template Turn Restriction"
     98        List<TestError> errors = testRelation(r);
     99        assertEquals(1, errors.size());
     100        assertEquals("Role member type relation does not match accepted list of node/way in template Turn Restriction",
     101                errors.get(0).getDescription());
    86102    }
    87103
    88     void testRestrictionTwoFrom() {
    89         def r = createRelation("type=restriction")
    90         r.addMember(new RelationMember("from", new Way()))
    91         r.addMember(new RelationMember("from", new Way()))
    92         r.addMember(new RelationMember("to", new Way()))
    93         r.addMember(new RelationMember("via", new Way()))
     104    @Test
     105    public void testRestrictionTwoFrom() {
     106        Relation r = createRelation("type=restriction");
     107        r.addMember(new RelationMember("from", new Way()));
     108        r.addMember(new RelationMember("from", new Way()));
     109        r.addMember(new RelationMember("to", new Way()));
     110        r.addMember(new RelationMember("via", new Way()));
    94111
    95         def errors = testRelation(r)
    96         assert errors.size() == 1
    97         assert errors.get(0).getDescription() == "Number of from roles too high (2)"
     112        List<TestError> errors = testRelation(r);
     113        assertEquals(1, errors.size());
     114        assertEquals("Number of from roles too high (2)", errors.get(0).getDescription());
    98115    }
    99116
    100     void testRestrictionEmpty() {
    101         def r = createRelation("type=restriction")
    102         r.addMember(new RelationMember("from", new Way()))
    103         r.addMember(new RelationMember("to", new Way()))
    104         r.addMember(new RelationMember("via", new Way()))
    105         r.addMember(new RelationMember("", new Way()))
     117    @Test
     118    public void testRestrictionEmpty() {
     119        Relation r = createRelation("type=restriction");
     120        r.addMember(new RelationMember("from", new Way()));
     121        r.addMember(new RelationMember("to", new Way()));
     122        r.addMember(new RelationMember("via", new Way()));
     123        r.addMember(new RelationMember("", new Way()));
    106124
    107         def errors = testRelation(r)
    108         assert errors.size() == 1
    109         assert errors.get(0).getDescription().startsWith("Empty role type found when expecting one of")
     125        List<TestError> errors = testRelation(r);
     126        assertEquals(1, errors.size());
     127        assertTrue(errors.get(0).getDescription().startsWith("Empty role type found when expecting one of"));
    110128    }
    111129
    112     void testPowerMemberExpression() {
    113         def r = createRelation("type=route route=power")
    114         r.addMember(new RelationMember("", new Way()))
     130    @Test
     131    public void testPowerMemberExpression() {
     132        Relation r = createRelation("type=route route=power");
     133        r.addMember(new RelationMember("", new Way()));
    115134
    116         def errors = testRelation(r)
    117         assert errors.size() == 1
    118         assert errors.get(0).getDescription() == "Role member does not match expression power in template Power Route"
     135        List<TestError> errors = testRelation(r);
     136        assertEquals(1, errors.size());
     137        assertEquals("Role member does not match expression power in template Power Route", errors.get(0).getDescription());
    119138    }
    120139
    121     void testRouteMemberExpression() {
    122         def r = createRelation("type=route route=tram public_transport:version=2")
    123         r.addMember(new RelationMember("", createPrimitive("way railway=tram")))
    124         r.addMember(new RelationMember("stop", createPrimitive("node public_transport=stop_position tram=yes")))
    125         r.addMember(new RelationMember("platform", createPrimitive("node public_transport=platform tram=yes")))
    126         assert testRelation(r).size() == 0
     140    @Test
     141    public void testRouteMemberExpression() {
     142        Relation r = createRelation("type=route route=tram public_transport:version=2");
     143        r.addMember(new RelationMember("", createPrimitive("way railway=tram")));
     144        r.addMember(new RelationMember("stop", createPrimitive("node public_transport=stop_position tram=yes")));
     145        r.addMember(new RelationMember("platform", createPrimitive("node public_transport=platform tram=yes")));
     146        assertTrue(testRelation(r).isEmpty());
    127147
    128         r.addMember(new RelationMember("", createPrimitive("way no-rail-way=yes")))
    129         assert testRelation(r).size() == 1
    130         assert testRelation(r).get(0).getDescription() == "Role member does not match expression railway in template Public Transport Route (Rail)"
     148        r.addMember(new RelationMember("", createPrimitive("way no-rail-way=yes")));
     149        assertEquals(1, testRelation(r).size());
     150        assertEquals("Role member does not match expression railway in template Public Transport Route (Rail)",
     151                testRelation(r).get(0).getDescription());
    131152
    132         r.removeMember(3)
    133         r.addMember(new RelationMember("stop", createPrimitive("way no-rail-way=yes")))
    134         assert testRelation(r).size() == 1
    135         assert testRelation(r).get(0).getDescription() == "Role member type way does not match accepted list of node in template Public Transport Route (Rail)"
     153        r.removeMember(3);
     154        r.addMember(new RelationMember("stop", createPrimitive("way no-rail-way=yes")));
     155        assertEquals(1, testRelation(r).size());
     156        assertEquals("Role member type way does not match accepted list of node in template Public Transport Route (Rail)",
     157                testRelation(r).get(0).getDescription());
    136158
    137         r.removeMember(3)
    138         r.addMember(new RelationMember("stop", createPrimitive("node public_transport=stop_position bus=yes")))
    139         assert testRelation(r).size() == 1
    140         assert testRelation(r).get(0).getDescription() == "Role member does not match expression public_transport=stop_position && (train=yes || subway=yes || monorail=yes || tram=yes || light_rail=yes) in template Public Transport Route (Rail)"
     159        r.removeMember(3);
     160        r.addMember(new RelationMember("stop", createPrimitive("node public_transport=stop_position bus=yes")));
     161        assertEquals(1, testRelation(r).size());
     162        assertEquals("Role member does not match expression public_transport=stop_position && "+
     163                "(train=yes || subway=yes || monorail=yes || tram=yes || light_rail=yes) in template Public Transport Route (Rail)",
     164                testRelation(r).get(0).getDescription());
    141165    }
    142166}
  • trunk/test/unit/org/openstreetmap/josm/data/validation/tests/SimilarNamedWaysTest.java

    r11390 r11403  
    1 // License: GPL. See LICENSE file for details.
    2 package org.openstreetmap.josm.data.validation.tests
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.data.validation.tests;
    33
    4 import static org.junit.Assert.assertEquals
     4import static org.junit.Assert.assertEquals;
     5import static org.junit.Assert.assertFalse;
     6import static org.junit.Assert.assertTrue;
    57
    6 import org.openstreetmap.josm.JOSMFixture
    7 import org.openstreetmap.josm.data.coor.LatLon
    8 import org.openstreetmap.josm.data.osm.DataSet
    9 import org.openstreetmap.josm.data.osm.Node
    10 import org.openstreetmap.josm.data.osm.Way
    11 import org.openstreetmap.josm.data.validation.TestError
     8import java.util.List;
    129
    13 class SimilarNamedWaysTest extends GroovyTestCase {
     10import org.junit.Before;
     11import org.junit.Test;
     12import org.openstreetmap.josm.JOSMFixture;
     13import org.openstreetmap.josm.data.coor.LatLon;
     14import org.openstreetmap.josm.data.osm.DataSet;
     15import org.openstreetmap.josm.data.osm.Node;
     16import org.openstreetmap.josm.data.osm.Way;
     17import org.openstreetmap.josm.data.validation.TestError;
    1418
    15     SimilarNamedWays test = new SimilarNamedWays()
     19/**
     20 * Unit test of {@link SimilarNamedWays}
     21 */
     22public class SimilarNamedWaysTest {
    1623
    17     @Override
    18     void setUp() {
     24    private final SimilarNamedWays test = new SimilarNamedWays();
     25
     26    /**
     27     * Setup test
     28     */
     29    @Before
     30    public void setUp() {
    1931        JOSMFixture.createUnitTestFixture().init();
    2032    }
    2133
    22     public static List<TestError> testWays(String namea, String nameb) {
    23         def ds = new DataSet()
     34    private static List<TestError> testWays(String namea, String nameb) {
     35        DataSet ds = new DataSet();
    2436
    25         def n00 = new Node(LatLon.ZERO)
    26         def n10 = new Node(new LatLon(1, 0))
    27         def n20 = new Node(new LatLon(2, 0))
    28         def n30 = new Node(new LatLon(3, 0))
    29         def n40 = new Node(new LatLon(4, 0))
     37        Node n00 = new Node(LatLon.ZERO);
     38        Node n10 = new Node(new LatLon(1, 0));
     39        Node n20 = new Node(new LatLon(2, 0));
     40        Node n30 = new Node(new LatLon(3, 0));
     41        Node n40 = new Node(new LatLon(4, 0));
    3042
    31         ds.addPrimitive(n00)
    32         ds.addPrimitive(n10)
    33         ds.addPrimitive(n20)
    34         ds.addPrimitive(n30)
    35         ds.addPrimitive(n40)
     43        ds.addPrimitive(n00);
     44        ds.addPrimitive(n10);
     45        ds.addPrimitive(n20);
     46        ds.addPrimitive(n30);
     47        ds.addPrimitive(n40);
    3648
    37         def waya = new Way()
    38         waya.addNode(n00)
    39         waya.addNode(n10)
    40         waya.addNode(n20)
    41         waya.put("name", namea)
    42         def wayb = new Way()
    43         wayb.addNode(n20)
    44         wayb.addNode(n30)
    45         wayb.addNode(n40)
    46         wayb.put("name", nameb)
     49        Way waya = new Way();
     50        waya.addNode(n00);
     51        waya.addNode(n10);
     52        waya.addNode(n20);
     53        waya.put("name", namea);
     54        Way wayb = new Way();
     55        wayb.addNode(n20);
     56        wayb.addNode(n30);
     57        wayb.addNode(n40);
     58        wayb.put("name", nameb);
    4759
    48         ds.addPrimitive(waya)
    49         ds.addPrimitive(wayb)
     60        ds.addPrimitive(waya);
     61        ds.addPrimitive(wayb);
    5062
    51         assert waya.isUsable()
    52         assert wayb.isUsable()
     63        assertTrue(waya.isUsable());
     64        assertTrue(wayb.isUsable());
    5365
    54         def t = new SimilarNamedWays()
    55         t.startTest(null)
    56         t.visit(waya)
    57         t.visit(wayb)
    58         return t.errors
     66        SimilarNamedWays t = new SimilarNamedWays();
     67        t.startTest(null);
     68        t.visit(waya);
     69        t.visit(wayb);
     70        return t.getErrors();
    5971    }
    6072
    61     void testCombinations() {
    62         assert testWays("Church Street", "Water Street").isEmpty()
    63         assert !testWays("Main Street", "Maim Street").isEmpty()
    64         assert !testWays("First Street", "Frist Street").isEmpty()
     73    @Test
     74    public void testCombinations() {
     75        assertTrue(testWays("Church Street", "Water Street").isEmpty());
     76        assertFalse(testWays("Main Street", "Maim Street").isEmpty());
     77        assertFalse(testWays("First Street", "Frist Street").isEmpty());
    6578
    66         assert testWays("1st Street", "2nd Street").isEmpty()
    67         assert testWays("First Avenue", "Second Avenue").isEmpty()
    68         assert testWays("West Main Street", "East Main Street").isEmpty()
    69         assert testWays("A Street", "B Street").isEmpty()
     79        assertTrue(testWays("1st Street", "2nd Street").isEmpty());
     80        assertTrue(testWays("First Avenue", "Second Avenue").isEmpty());
     81        assertTrue(testWays("West Main Street", "East Main Street").isEmpty());
     82        assertTrue(testWays("A Street", "B Street").isEmpty());
    7083    }
    7184
    72     void checkSimilarity(String message, String name1, String name2, boolean expected) {
     85    private void checkSimilarity(String message, String name1, String name2, boolean expected) {
    7386        boolean actual = test.similaryName(name1, name2);
    7487        assertEquals(message, expected, actual);
    7588    }
    7689
    77     void testSimilarNames() {
     90    @Test
     91    public void testSimilarNames() {
    7892        checkSimilarity("same string", "Testname", "Testname", false);
    7993        checkSimilarity("different case", "Testname", "TestName", true);
Note: See TracChangeset for help on using the changeset viewer.