Ignore:
Timestamp:
2024-03-07T16:08:06+01:00 (10 months ago)
Author:
GerdP
Message:

fix #23509: Test-Failure because of r18994,r18996
The patch changes the failing test so that it

  • doesn't use a new file but reads from an existing one so that the result doesn't depend on that part
  • tests more methods to show the differences between DataSet.requiresUploadToServer() and OsmDataLayer.requiresUploadToServer()
  • tests the effect of the upload policy on the SaveLayersDialog
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/io/SaveLayersDialogTest.java

    r18706 r19011  
    99import java.awt.GraphicsEnvironment;
    1010import java.io.File;
     11import java.io.FileInputStream;
     12import java.io.IOException;
     13import java.io.InputStream;
    1114import java.util.Collections;
    1215import java.util.List;
     
    1720import javax.swing.JOptionPane;
    1821
     22import org.junit.jupiter.api.Test;
     23import org.junit.jupiter.params.ParameterizedTest;
     24import org.junit.jupiter.params.provider.EnumSource;
     25import org.openstreetmap.josm.TestUtils;
     26import org.openstreetmap.josm.data.osm.DataSet;
     27import org.openstreetmap.josm.data.osm.UploadPolicy;
     28import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     29import org.openstreetmap.josm.io.IllegalDataException;
     30import org.openstreetmap.josm.io.OsmReader;
     31import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
     32import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;
     33import org.openstreetmap.josm.testutils.mockers.WindowMocker;
     34
    1935import mockit.Invocation;
    2036import mockit.Mock;
    2137import mockit.MockUp;
    22 import org.junit.jupiter.api.Test;
    23 import org.junit.jupiter.params.ParameterizedTest;
    24 import org.junit.jupiter.params.provider.EnumSource;
    25 import org.openstreetmap.josm.command.AddPrimitivesCommand;
    26 import org.openstreetmap.josm.data.coor.LatLon;
    27 import org.openstreetmap.josm.data.osm.DataSet;
    28 import org.openstreetmap.josm.data.osm.Node;
    29 import org.openstreetmap.josm.data.osm.UploadPolicy;
    30 import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    31 import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
    32 import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker;
    33 import org.openstreetmap.josm.testutils.mockers.WindowMocker;
    3438
    3539/**
     
    126130     * Non-regression test for #22817: No warning when deleting a layer with changes and discourages upload
    127131     * @param policy The upload policy to test
     132     * @throws IOException if an error occurs
     133     * @throws IllegalDataException if an error occurs
    128134     */
    129135    @ParameterizedTest
    130136    @EnumSource(value = UploadPolicy.class)
    131     void testNonRegression22817(UploadPolicy policy) {
    132         final OsmDataLayer osmDataLayer = new OsmDataLayer(new DataSet(), null, null);
     137    void testNonRegression22817(UploadPolicy policy) throws IOException, IllegalDataException {
     138        File file = new File(TestUtils.getRegressionDataFile(22817, "data.osm"));
     139        InputStream is = new FileInputStream(file);
     140        final OsmDataLayer osmDataLayer = new OsmDataLayer(OsmReader.parseDataSet(is, null), null, null);
     141        osmDataLayer.onPostLoadFromFile();
    133142        osmDataLayer.getDataSet().setUploadPolicy(policy);
    134         // BLOCKED files don't have a way to become blocked via the UI, so they must be loaded from disk.
    135         if (policy == UploadPolicy.BLOCKED) {
    136             osmDataLayer.setAssociatedFile(new File("/dev/null"));
    137         }
    138         new AddPrimitivesCommand(Collections.singletonList(new Node(LatLon.ZERO).save()), Collections.emptyList(), osmDataLayer.getDataSet())
    139                 .executeCommand();
     143        osmDataLayer.setAssociatedFile(file);
    140144        assertTrue(osmDataLayer.getDataSet().isModified());
     145        assertFalse(osmDataLayer.requiresSaveToFile());
     146        assertTrue(osmDataLayer.getDataSet().requiresUploadToServer());
     147        assertEquals(policy != UploadPolicy.BLOCKED, osmDataLayer.requiresUploadToServer());
     148        assertEquals(policy != UploadPolicy.BLOCKED, osmDataLayer.isUploadable());
    141149        new WindowMocker();
    142150        // Needed since the *first call* is to check whether we are in a headless environment
     
    144152        // Needed since we need to mock out the UI
    145153        SaveLayersDialogMock saveLayersDialogMock = new SaveLayersDialogMock();
    146 
    147154        assertTrue(SaveLayersDialog.saveUnsavedModifications(Collections.singleton(osmDataLayer), SaveLayersDialog.Reason.DELETE));
    148         assertEquals(1, saveLayersDialogMock.getUserActionCalled, "The user should have been asked for an action on the layer");
     155        int res = saveLayersDialogMock.getUserActionCalled;
     156        if (policy == UploadPolicy.NORMAL) {
     157            assertEquals(1, res, "The user should have been asked for an action on the layer");
     158        } else {
     159            assertEquals(0, res, "The user should not have been asked for an action on the layer");
     160
     161        }
    149162    }
    150163
Note: See TracChangeset for help on using the changeset viewer.