Changeset 18922 in josm for trunk/test/unit/org


Ignore:
Timestamp:
2023-12-20T20:03:45+01:00 (11 months ago)
Author:
taylor.smock
Message:

Fix #23302: Create a preference for address duplicate detection to include buildings and POIs (patch by zyphlar, modified)

Modifications are as follows:

  • Add test case
File:
1 edited

Legend:

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

    r18853 r18922  
    33
    44import static org.junit.jupiter.api.Assertions.assertEquals;
     5import static org.junit.jupiter.api.Assertions.assertInstanceOf;
    56import static org.junit.jupiter.api.Assertions.assertNotNull;
    67import static org.junit.jupiter.api.Assertions.assertNull;
     8import static org.junit.jupiter.api.Assertions.assertTrue;
    79import static org.openstreetmap.josm.data.coor.LatLon.NORTH_POLE;
    810import static org.openstreetmap.josm.data.coor.LatLon.SOUTH_POLE;
     
    1012
    1113import java.util.List;
     14
     15import javax.swing.JCheckBox;
     16import javax.swing.JPanel;
    1217
    1318import org.junit.jupiter.api.Test;
     
    1722import org.openstreetmap.josm.data.osm.Node;
    1823import org.openstreetmap.josm.data.osm.RelationMember;
     24import org.openstreetmap.josm.data.osm.Way;
    1925import org.openstreetmap.josm.data.validation.Severity;
    2026import org.openstreetmap.josm.data.validation.TestError;
     27import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    2128
    2229/**
     
    120127        doTestDuplicateHouseNumber(num1, ZERO, num4, ZERO, null);
    121128    }
     129
     130    /**
     131     * See #23302
     132     */
     133    @Test
     134    void testCheckForDuplicatePOIBuildingAddresses() {
     135        final Addresses test = new Addresses();
     136        final JPanel panel = new JPanel();
     137        final Node poi = TestUtils.newNode("addr:housenumber=1 addr:street=Foo");
     138        final Way building = TestUtils.newWay("addr:housenumber=1 addr:street=Foo building=yes",
     139                TestUtils.newNode(""), TestUtils.newNode(""), TestUtils.newNode(""));
     140        final DataSet ds = new DataSet();
     141        // Ensure that we are checking for building-poi duplicates
     142        test.addGui(panel);
     143        JCheckBox checkboxIncludeBldgPOI = assertInstanceOf(JCheckBox.class, panel.getComponent(panel.getComponentCount() - 1));
     144        checkboxIncludeBldgPOI.setSelected(true);
     145        test.ok();
     146        // Set up the dataset
     147        ds.addPrimitive(poi);
     148        ds.addPrimitiveRecursive(building);
     149        building.addNode(building.firstNode());
     150
     151        // Duplicate addresses with no additional information should always have warnings
     152        test.startTest(NullProgressMonitor.INSTANCE);
     153        test.visit(ds.allPrimitives());
     154        test.endTest();
     155        assertEquals(1, test.getErrors().size());
     156
     157        // Do the first test checking for building-poi duplicates
     158        poi.put("name", "FooBar");
     159        test.startTest(NullProgressMonitor.INSTANCE);
     160        test.visit(ds.allPrimitives());
     161        test.endTest();
     162        assertEquals(1, test.getErrors().size());
     163        assertEquals(Severity.OTHER, test.getErrors().get(0).getSeverity());
     164
     165        // Now check if they have the same name
     166        building.put("name", "FooBar");
     167        test.startTest(NullProgressMonitor.INSTANCE);
     168        test.visit(ds.allPrimitives());
     169        test.endTest();
     170        assertEquals(1, test.getErrors().size());
     171        assertEquals(Severity.WARNING, test.getErrors().get(0).getSeverity());
     172
     173        // Now check if they have a different name
     174        building.put("name", "FooBar2");
     175        test.startTest(NullProgressMonitor.INSTANCE);
     176        test.visit(ds.allPrimitives());
     177        test.endTest();
     178        assertEquals(1, test.getErrors().size());
     179        assertEquals(Severity.OTHER, test.getErrors().get(0).getSeverity());
     180
     181        // Now ensure that it doesn't get errors when disabled
     182        checkboxIncludeBldgPOI.setSelected(false);
     183        test.ok();
     184        test.startTest(NullProgressMonitor.INSTANCE);
     185        test.visit(ds.allPrimitives());
     186        test.endTest();
     187        assertTrue(test.getErrors().isEmpty());
     188    }
    122189}
Note: See TracChangeset for help on using the changeset viewer.