Changeset 19011 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2024-03-07T16:08:06+01:00 (10 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/io/SaveLayersDialogTest.java
r18706 r19011 9 9 import java.awt.GraphicsEnvironment; 10 10 import java.io.File; 11 import java.io.FileInputStream; 12 import java.io.IOException; 13 import java.io.InputStream; 11 14 import java.util.Collections; 12 15 import java.util.List; … … 17 20 import javax.swing.JOptionPane; 18 21 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.TestUtils; 26 import org.openstreetmap.josm.data.osm.DataSet; 27 import org.openstreetmap.josm.data.osm.UploadPolicy; 28 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 29 import org.openstreetmap.josm.io.IllegalDataException; 30 import org.openstreetmap.josm.io.OsmReader; 31 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 32 import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker; 33 import org.openstreetmap.josm.testutils.mockers.WindowMocker; 34 19 35 import mockit.Invocation; 20 36 import mockit.Mock; 21 37 import 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;34 38 35 39 /** … … 126 130 * Non-regression test for #22817: No warning when deleting a layer with changes and discourages upload 127 131 * @param policy The upload policy to test 132 * @throws IOException if an error occurs 133 * @throws IllegalDataException if an error occurs 128 134 */ 129 135 @ParameterizedTest 130 136 @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(); 133 142 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); 140 144 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()); 141 149 new WindowMocker(); 142 150 // Needed since the *first call* is to check whether we are in a headless environment … … 144 152 // Needed since we need to mock out the UI 145 153 SaveLayersDialogMock saveLayersDialogMock = new SaveLayersDialogMock(); 146 147 154 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 } 149 162 } 150 163
Note:
See TracChangeset
for help on using the changeset viewer.