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


Ignore:
Timestamp:
2023-07-10T17:07:42+02:00 (17 months ago)
Author:
taylor.smock
Message:

Fix #23049: Informational errors cause validator dialog to occur on upload, even if they are not enabled

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/actions/upload/ValidateUploadHookTest.java

    r17275 r18775  
    22package org.openstreetmap.josm.actions.upload;
    33
     4import static org.junit.jupiter.api.Assertions.assertEquals;
    45import static org.junit.jupiter.api.Assertions.assertTrue;
    56
    6 import org.junit.jupiter.api.extension.RegisterExtension;
    7 import org.junit.jupiter.api.Test;
    8 import org.openstreetmap.josm.data.APIDataSet;
    9 import org.openstreetmap.josm.testutils.JOSMTestRules;
     7import java.util.Collections;
    108
    119import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     10import mockit.Mock;
     11import org.junit.jupiter.api.Test;
     12import org.junit.jupiter.api.extension.RegisterExtension;
     13import org.junit.jupiter.params.ParameterizedTest;
     14import org.junit.jupiter.params.provider.ValueSource;
     15import org.openstreetmap.josm.TestUtils;
     16import org.openstreetmap.josm.data.APIDataSet;
     17import org.openstreetmap.josm.data.Bounds;
     18import org.openstreetmap.josm.data.DataSource;
     19import org.openstreetmap.josm.data.coor.LatLon;
     20import org.openstreetmap.josm.data.osm.DataSet;
     21import org.openstreetmap.josm.data.osm.Node;
     22import org.openstreetmap.josm.data.osm.Way;
     23import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper;
     24import org.openstreetmap.josm.gui.ExtendedDialog;
     25import org.openstreetmap.josm.gui.MainApplication;
     26import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     27import org.openstreetmap.josm.testutils.JOSMTestRules;
     28import org.openstreetmap.josm.testutils.mockers.ExtendedDialogMocker;
    1229
    1330/**
     
    2138    @RegisterExtension
    2239    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    23     public JOSMTestRules test = new JOSMTestRules().fakeAPI().timeout(30000);
     40    public JOSMTestRules test = new JOSMTestRules().main().projection().fakeAPI().timeout(30000);
    2441
    2542    /**
     
    3047        assertTrue(new ValidateUploadHook().checkUpload(new APIDataSet()));
    3148    }
     49
     50    @ParameterizedTest
     51    @ValueSource(booleans = {true, false})
     52    void testUploadOtherErrors(boolean otherEnabled) {
     53        ValidatorPrefHelper.PREF_OTHER_UPLOAD.put(otherEnabled);
     54        final DataSet ds = new DataSet();
     55        final Way building = TestUtils.newWay("building=yes", new Node(new LatLon(33.2287665, -111.8259225)),
     56                new Node(new LatLon(33.2287335, -111.8257513)), new Node(new LatLon(33.2285316, -111.8258086)),
     57                new Node(new LatLon(33.2285696, -111.8259781)));
     58        ds.addPrimitiveRecursive(building);
     59        building.addNode(building.firstNode());
     60        ds.addDataSource(new DataSource(new Bounds(33, -112, 34, -111), ""));
     61        MainApplication.getLayerManager().addLayer(new OsmDataLayer(ds,
     62                "ValidateUploadHookTest#testUploadOtherErrors", null));
     63        final ExtendedDialogMocker mocker =
     64                new ExtendedDialogMocker(Collections.singletonMap("Suspicious data found. Upload anyway?", "Cancel")) {
     65                    @Override
     66                    protected String getString(ExtendedDialog instance) {
     67                        return instance.getTitle();
     68                    }
     69
     70                    @Mock
     71                    public void dispose() {
     72                        // Do nothing
     73                    }
     74                };
     75        new ValidateUploadHook().checkUpload(new APIDataSet(ds));
     76        assertEquals(!otherEnabled, mocker.getInvocationLog().isEmpty());
     77    }
    3278}
Note: See TracChangeset for help on using the changeset viewer.