Ticket #12974: patch-fix-12974-2.patch
File patch-fix-12974-2.patch, 8.9 KB (added by , 9 years ago) |
---|
-
test/unit/org/openstreetmap/josm/JOSMFixture.java
diff --git a/test/unit/org/openstreetmap/josm/JOSMFixture.java b/test/unit/org/openstreetmap/josm/JOSMFixture.java index f08ca13..51fb2dc 100644
a b 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm; 3 3 4 import static org.junit.Assert.assertNull; 5 import static org.junit.Assert.assertTrue; 4 6 import static org.junit.Assert.fail; 5 7 6 8 import java.io.File; … … import java.util.Locale; 12 14 13 15 import org.openstreetmap.josm.data.projection.Projections; 14 16 import org.openstreetmap.josm.gui.MainApplication; 15 import org.openstreetmap.josm.gui.layer.Layer;16 17 import org.openstreetmap.josm.gui.preferences.ToolbarPreferences; 17 18 import org.openstreetmap.josm.gui.util.GuiHelper; 18 19 import org.openstreetmap.josm.io.CertificateAmendment; … … public class JOSMFixture { 132 133 if (Main.main == null) { 133 134 new MainApplication().initialize(); 134 135 } 135 if (Main.map == null) { 136 Main.main.createMapFrame(null, null); 137 } else { 138 for (Layer l: Main.getLayerManager().getLayers()) { 139 Main.getLayerManager().removeLayer(l); 140 } 141 } 136 Main.getLayerManager().resetState(); 137 assertTrue(Main.getLayerManager().getLayers().isEmpty()); 138 assertNull(Main.getLayerManager().getEditLayer()); 139 assertNull(Main.getLayerManager().getActiveLayer()); 142 140 } 143 141 } -
test/unit/org/openstreetmap/josm/actions/SelectByInternalPointActionTest.java
diff --git a/test/unit/org/openstreetmap/josm/actions/SelectByInternalPointActionTest.java b/test/unit/org/openstreetmap/josm/actions/SelectByInternalPointActionTest.java index 3ea8298..6e0a1b2 100644
a b import static org.junit.Assert.assertNotNull; 6 6 import static org.junit.Assert.assertNull; 7 7 import static org.junit.Assert.assertTrue; 8 8 9 import org.junit. BeforeClass;9 import org.junit.Rule; 10 10 import org.junit.Test; 11 import org.openstreetmap.josm.JOSMFixture;12 11 import org.openstreetmap.josm.Main; 13 12 import org.openstreetmap.josm.data.coor.EastNorth; 14 13 import org.openstreetmap.josm.data.osm.DataSet; … … import org.openstreetmap.josm.data.osm.RelationMember; 18 17 import org.openstreetmap.josm.data.osm.Way; 19 18 import org.openstreetmap.josm.gui.layer.Layer; 20 19 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 20 import org.openstreetmap.josm.testutils.JOSMTestRules; 21 21 22 22 /** 23 23 * Unit tests for class {@link SelectByInternalPointAction}. … … public final class SelectByInternalPointActionTest { 27 27 /** 28 28 * Setup test. 29 29 */ 30 @BeforeClass 31 public static void setUp() { 32 JOSMFixture.createUnitTestFixture().init(true); 33 } 30 @Rule 31 public JOSMTestRules rules = new JOSMTestRules().preferences().projection(); 34 32 35 33 /** 36 34 * Unit test - no dataset. 37 35 */ 38 36 @Test 39 37 public void testNoDataSet() { 40 while (Main.main.hasEditLayer()) { 41 Main.getLayerManager().removeLayer(Main.getLayerManager().getEditLayer()); 42 } 43 assertNull(JosmAction.getCurrentDataSet()); 38 assertNull(Main.getLayerManager().getEditDataSet()); 44 39 assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(null).size()); 45 40 assertNull(SelectByInternalPointAction.getSmallestSurroundingObject(null)); 46 41 SelectByInternalPointAction.performSelection(null, false, false); … … public final class SelectByInternalPointActionTest { 77 72 */ 78 73 @Test 79 74 public void testGetSurroundingObjects() { 80 Layer layer = initDataSet(); 81 try { 82 assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(null).size()); 83 assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(new EastNorth(0, 0)).size()); 84 assertEquals(1, SelectByInternalPointAction.getSurroundingObjects(new EastNorth(1.5, 1.5)).size()); 85 assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(new EastNorth(3, 3)).size()); 86 } finally { 87 // Ensure we clean the place before leaving, even if test fails. 88 Main.getLayerManager().removeLayer(layer); 89 } 75 initDataSet(); 76 assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(null).size()); 77 assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(new EastNorth(0, 0)).size()); 78 assertEquals(1, SelectByInternalPointAction.getSurroundingObjects(new EastNorth(1.5, 1.5)).size()); 79 assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(new EastNorth(3, 3)).size()); 90 80 } 91 81 92 82 /** … … public final class SelectByInternalPointActionTest { 94 84 */ 95 85 @Test 96 86 public void testGetSmallestSurroundingObject() { 97 Layer layer = initDataSet(); 98 try { 99 assertNull(SelectByInternalPointAction.getSmallestSurroundingObject(null)); 100 assertNotNull(SelectByInternalPointAction.getSmallestSurroundingObject(new EastNorth(1.5, 1.5))); 101 } finally { 102 // Ensure we clean the place before leaving, even if test fails. 103 Main.getLayerManager().removeLayer(layer); 104 } 87 initDataSet(); 88 assertNull(SelectByInternalPointAction.getSmallestSurroundingObject(null)); 89 assertNotNull(SelectByInternalPointAction.getSmallestSurroundingObject(new EastNorth(1.5, 1.5))); 105 90 } 106 91 107 92 /** … … public final class SelectByInternalPointActionTest { 109 94 */ 110 95 @Test 111 96 public void testPerformSelection() { 112 Layer layer = initDataSet(); 113 try { 114 DataSet ds = JosmAction.getCurrentDataSet(); 97 initDataSet(); 98 DataSet ds = Main.getLayerManager().getEditDataSet(); 115 99 116 assertEquals(0, ds.getSelected().size()); 117 SelectByInternalPointAction.performSelection(null, false, false); 118 assertEquals(0, ds.getSelected().size()); 119 SelectByInternalPointAction.performSelection(new EastNorth(0, 0), false, false); 120 assertEquals(0, ds.getSelected().size()); 121 SelectByInternalPointAction.performSelection(new EastNorth(1.5, 1.5), false, false); 122 assertEquals(1, ds.getSelected().size()); 123 ds.clearSelection(); 124 ds.addSelected(ds.getNodes()); 125 assertEquals(4, ds.getSelected().size()); 126 SelectByInternalPointAction.performSelection(new EastNorth(1.5, 1.5), true, false); 127 assertEquals(5, ds.getSelected().size()); 128 SelectByInternalPointAction.performSelection(new EastNorth(1.5, 1.5), false, true); 129 assertEquals(4, ds.getSelected().size()); 130 } finally { 131 // Ensure we clean the place before leaving, even if test fails. 132 Main.getLayerManager().removeLayer(layer); 133 } 100 assertEquals(0, ds.getSelected().size()); 101 SelectByInternalPointAction.performSelection(null, false, false); 102 assertEquals(0, ds.getSelected().size()); 103 SelectByInternalPointAction.performSelection(new EastNorth(0, 0), false, false); 104 assertEquals(0, ds.getSelected().size()); 105 SelectByInternalPointAction.performSelection(new EastNorth(1.5, 1.5), false, false); 106 assertEquals(1, ds.getSelected().size()); 107 ds.clearSelection(); 108 ds.addSelected(ds.getNodes()); 109 assertEquals(4, ds.getSelected().size()); 110 SelectByInternalPointAction.performSelection(new EastNorth(1.5, 1.5), true, false); 111 assertEquals(5, ds.getSelected().size()); 112 SelectByInternalPointAction.performSelection(new EastNorth(1.5, 1.5), false, true); 113 assertEquals(4, ds.getSelected().size()); 134 114 } 135 115 } -
test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
diff --git a/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java b/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java index 39dae30..5a49b02 100644
a b public class JOSMTestRules implements TestRule { 156 156 * @throws InitializationError If an error occured while creating the required environment. 157 157 */ 158 158 protected void before() throws InitializationError { 159 cleanUpFromJosmFixture(); 160 159 161 // Tests are running headless by default. 160 162 System.setProperty("java.awt.headless", "true"); 161 163 … … public class JOSMTestRules implements TestRule { 211 213 } 212 214 213 215 /** 216 * Clean up what test not using these test rules may have broken. 217 */ 218 private void cleanUpFromJosmFixture() { 219 Main.getLayerManager().resetState(); 220 Main.pref = null; 221 Main.platform = null; 222 Main.pref.put("osm-server.url", "invalid-server"); 223 System.gc(); 224 } 225 226 /** 214 227 * Clean up after running a test 215 228 */ 216 229 protected void after() {