Changeset 18706 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/io/SaveLayersDialog.java
r18466 r18706 82 82 } 83 83 84 private enum UserAction { 84 /** 85 * The action a user decided to take with respect to an operation 86 */ 87 enum UserAction { 85 88 /** save/upload layers was successful, proceed with operation */ 86 89 PROCEED, … … 113 116 if (!GraphicsEnvironment.isHeadless()) { 114 117 SaveLayersDialog dialog = new SaveLayersDialog(MainApplication.getMainFrame()); 115 List<AbstractModifiableLayer> layersWithUn modifiedChanges = new ArrayList<>();118 List<AbstractModifiableLayer> layersWithUnsavedChanges = new ArrayList<>(); 116 119 for (Layer l: selectedLayers) { 117 120 if (!(l instanceof AbstractModifiableLayer)) { … … 122 125 ((!odl.isSavable() && !odl.isUploadable()) || 123 126 odl.requiresSaveToFile() || 124 (odl.requiresUploadToServer() && !odl.isUploadDiscouraged()))) {125 layersWithUn modifiedChanges.add(odl);127 odl.requiresUploadToServer())) { 128 layersWithUnsavedChanges.add(odl); 126 129 } 127 130 } 128 131 dialog.prepareForSavingAndUpdatingLayers(reason); 129 if (!layersWithUn modifiedChanges.isEmpty()) {130 dialog.getModel().populate(layersWithUn modifiedChanges);132 if (!layersWithUnsavedChanges.isEmpty()) { 133 dialog.getModel().populate(layersWithUnsavedChanges); 131 134 dialog.setVisible(true); 132 135 switch(dialog.getUserAction()) { -
trunk/test/unit/org/openstreetmap/josm/gui/io/SaveLayersDialogTest.java
r17275 r18706 6 6 import static org.junit.jupiter.api.Assertions.assertTrue; 7 7 8 import java.awt.Component; 9 import java.awt.GraphicsEnvironment; 10 import java.io.File; 8 11 import java.util.Collections; 9 12 import java.util.List; 13 10 14 import javax.swing.JComponent; 11 15 import javax.swing.JLabel; … … 13 17 import javax.swing.JOptionPane; 14 18 15 import org.junit.jupiter.api.extension.RegisterExtension; 19 import mockit.Invocation; 20 import mockit.Mock; 21 import mockit.MockUp; 16 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; 17 27 import org.openstreetmap.josm.data.osm.DataSet; 28 import org.openstreetmap.josm.data.osm.Node; 29 import org.openstreetmap.josm.data.osm.UploadPolicy; 18 30 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 19 import org.openstreetmap.josm.testutils. JOSMTestRules;31 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 20 32 import org.openstreetmap.josm.testutils.mockers.JOptionPaneSimpleMocker; 21 22 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 33 import org.openstreetmap.josm.testutils.mockers.WindowMocker; 23 34 24 35 /** 25 36 * Unit tests of {@link SaveLayersDialog} class. 26 37 */ 38 @BasicPreferences 27 39 class SaveLayersDialogTest { 28 29 /**30 * Setup tests31 */32 @RegisterExtension33 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")34 public JOSMTestRules test = new JOSMTestRules();35 36 40 /** 37 41 * Test of {@link SaveLayersDialog#confirmSaveLayerInfosOK}. … … 118 122 assertTrue(SaveLayersDialog.confirmSaveLayerInfosOK(new SaveLayersModel())); 119 123 } 124 125 /** 126 * Non-regression test for #22817: No warning when deleting a layer with changes and discourages upload 127 * @param policy The upload policy to test 128 */ 129 @ParameterizedTest 130 @EnumSource(value = UploadPolicy.class) 131 void testNonRegression22817(UploadPolicy policy) { 132 final OsmDataLayer osmDataLayer = new OsmDataLayer(new DataSet(), null, null); 133 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(); 140 assertTrue(osmDataLayer.getDataSet().isModified()); 141 new WindowMocker(); 142 // Needed since the *first call* is to check whether we are in a headless environment 143 new GraphicsEnvironmentMock(); 144 // Needed since we need to mock out the UI 145 SaveLayersDialogMock saveLayersDialogMock = new SaveLayersDialogMock(); 146 147 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"); 149 } 150 151 private static class GraphicsEnvironmentMock extends MockUp<GraphicsEnvironment> { 152 @Mock 153 public static boolean isHeadless(Invocation invocation) { 154 return false; 155 } 156 } 157 158 private static class SaveLayersDialogMock extends MockUp<SaveLayersDialog> { 159 private final SaveLayersModel model = new SaveLayersModel(); 160 private int getUserActionCalled = 0; 161 @Mock 162 public void $init(Component parent) { 163 // Do nothing 164 } 165 166 @Mock 167 public void prepareForSavingAndUpdatingLayers(final SaveLayersDialog.Reason reason) { 168 // Do nothing 169 } 170 171 @Mock 172 public SaveLayersModel getModel() { 173 return this.model; 174 } 175 176 @Mock 177 public void setVisible(boolean b) { 178 // Do nothing 179 } 180 181 @Mock 182 public SaveLayersDialog.UserAction getUserAction() { 183 this.getUserActionCalled++; 184 return SaveLayersDialog.UserAction.PROCEED; 185 } 186 187 @Mock 188 public void closeDialog() { 189 // Do nothing 190 } 191 } 120 192 }
Note:
See TracChangeset
for help on using the changeset viewer.