Changeset 10443 in josm for trunk/test/unit
- Timestamp:
- 2016-06-20T23:57:32+02:00 (8 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/JOSMFixture.java
r10400 r10443 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 … … 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; … … 132 133 new MainApplication().initialize(); 133 134 } 134 if (Main.map == null) { 135 Main.main.createMapFrame(null, null); 136 } else { 137 for (Layer l: Main.getLayerManager().getLayers()) { 138 Main.getLayerManager().removeLayer(l); 139 } 140 } 135 Main.getLayerManager().resetState(); 136 assertTrue(Main.getLayerManager().getLayers().isEmpty()); 137 assertNull(Main.getLayerManager().getEditLayer()); 138 assertNull(Main.getLayerManager().getActiveLayer()); 141 139 } 142 140 } -
trunk/test/unit/org/openstreetmap/josm/actions/SelectByInternalPointActionTest.java
r10436 r10443 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; … … 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 /** … … 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 /** … … 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)); … … 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 … … 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 … … 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 } -
trunk/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
r10441 r10443 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"); … … 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 */
Note:
See TracChangeset
for help on using the changeset viewer.