Changeset 18649 in josm for trunk


Ignore:
Timestamp:
2023-02-06T19:39:32+01:00 (20 months ago)
Author:
taylor.smock
Message:

Fix #22712: ignore list doesn't work

This occurred due to OsmValidator#save modifying the list, and expecting
all error codes to be positive.

TestErrorTest now checks one of the tests known to have a negative hashcode.

This also adds some additional JUnit 5 annotations. The additional
annotations are:

  • @LayerManager (cleans up layers after each test run)
    • This is automatically registered for all tests
  • @Projection (sets up the ProjectionRegistry for each test)
Location:
trunk
Files:
5 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java

    r18637 r18649  
    467467                if (tr("Ignore list").equals(description))
    468468                    description = "";
    469                 if (!key.matches("^[0-9]+(_.*|$)")) {
     469                if (!key.matches("^-?[0-9]+(_.*|$)")) {
    470470                    description = key;
    471471                    key = "";
     
    480480                    // single element
    481481                    entry = key + ":" + item;
    482                 } else if (item.matches("^[0-9]+(_.*|)$")) {
     482                } else if (item.matches("^-?[0-9]+(_.*|)$")) {
    483483                    // no element ids
    484484                    entry = item;
  • trunk/test/unit/org/openstreetmap/josm/data/validation/TestErrorTest.java

    r18636 r18649  
    1818import org.junit.jupiter.params.provider.MethodSource;
    1919import org.openstreetmap.josm.TestUtils;
     20import org.openstreetmap.josm.data.coor.LatLon;
     21import org.openstreetmap.josm.data.osm.DataSet;
     22import org.openstreetmap.josm.data.osm.Node;
    2023import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2124import org.openstreetmap.josm.data.validation.tests.InternetTags;
     25import org.openstreetmap.josm.data.validation.tests.UnconnectedWays;
     26import org.openstreetmap.josm.gui.MainApplication;
     27import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2228import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    2329import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     30import org.openstreetmap.josm.testutils.annotations.Projection;
    2431
    2532/**
     
    2734 */
    2835@BasicPreferences
     36@Projection
    2937class TestErrorTest {
    3038    static Stream<Arguments> testCodeCompatibility() {
    3139        return Stream.of(Arguments.of(InternetTags.class, 3301, 1166507262, false, Collections.singletonList(TestUtils.newNode("url=invalid"))),
    32                 Arguments.of(InternetTags.class, 3301, 1166507262, true, Collections.singletonList(TestUtils.newNode("url=invalid"))));
     40                Arguments.of(InternetTags.class, 3301, 1166507262, true, Collections.singletonList(TestUtils.newNode("url=invalid"))),
     41                Arguments.of(UnconnectedWays.UnconnectedHighways.class, 1311, -1765317246, true,
     42                        Arrays.asList(TestUtils.newWay("highway=residential", new Node(LatLon.ZERO), new Node(LatLon.NORTH_POLE)),
     43                                TestUtils.newWay("highway=residential", new Node(LatLon.ZERO), new Node(LatLon.SOUTH_POLE)))),
     44        Arguments.of(UnconnectedWays.UnconnectedHighways.class, 1311, -1765317246, false,
     45                Arrays.asList(TestUtils.newWay("highway=residential", new Node(LatLon.ZERO), new Node(LatLon.NORTH_POLE)),
     46                        TestUtils.newWay("highway=residential", new Node(LatLon.ZERO), new Node(LatLon.SOUTH_POLE)))));
    3347    }
    3448
     
    4761    void testCodeCompatibility(Class<? extends Test> testClass, int originalCode, int expectedCode,
    4862                               boolean switchOver, List<OsmPrimitive> primitiveCollection) throws ReflectiveOperationException {
     63        // Create the data layer and add it to the layer manager -- needed if the test looks for an active dataset
     64        final DataSet ds = new DataSet();
     65        primitiveCollection.forEach(ds::addPrimitiveRecursive);
     66        for (OsmPrimitive primitive : ds.allPrimitives()) {
     67            if (primitive.isNew()) {
     68                primitive.setOsmId(-primitive.getUniqueId(), 1);
     69            }
     70        }
     71        final OsmDataLayer layer = new OsmDataLayer(ds, "testCodeCompatibility", null);
     72        MainApplication.getLayerManager().addLayer(layer);
    4973        // Ensure that this test always works
    5074        TestError.setUpdateErrorCodes(switchOver);
     
    5680        test.endTest();
    5781        assertFalse(test.getErrors().isEmpty());
    58         assertEquals(1, test.getErrors().size());
     82        final int expectedIssues;
     83        if (InternetTags.class.equals(testClass)) {
     84            expectedIssues = 1;
     85        } else if (UnconnectedWays.UnconnectedHighways.class.equals(testClass)) {
     86            expectedIssues = 2;
     87        } else {
     88            expectedIssues = Integer.MIN_VALUE;
     89        }
     90        assertEquals(expectedIssues, test.getErrors().size());
    5991        final TestError testError = test.getErrors().get(0);
    6092        final String ignoreGroup = testError.getIgnoreGroup();
     
    80112            OsmValidator.clearIgnoredErrors();
    81113            OsmValidator.addIgnoredError(ignore);
     114            OsmValidator.saveIgnoredErrors();
    82115            // Add the ignored error
    83116            assertTrue(testError.updateIgnored());
Note: See TracChangeset for help on using the changeset viewer.