Changeset 13174 in josm for trunk/test/unit/org/openstreetmap
- Timestamp:
- 2017-11-28T02:52:05+01:00 (7 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/JOSMFixture.java
r13173 r13174 138 138 139 139 if (createGui) { 140 GuiHelper.runInEDTAndWaitWithException(new Runnable() { 141 @Override 142 public void run() { 143 setupGUI(); 144 } 145 }); 140 GuiHelper.runInEDTAndWaitWithException(() -> setupGUI()); 146 141 } 147 142 } -
trunk/test/unit/org/openstreetmap/josm/gui/layer/OsmDataLayerTest.java
r12636 r13174 9 9 import java.io.File; 10 10 11 import org.junit.BeforeClass; 11 import org.junit.Before; 12 import org.junit.Rule; 12 13 import org.junit.Test; 13 import org.openstreetmap.josm.JOSMFixture;14 14 import org.openstreetmap.josm.TestUtils; 15 15 import org.openstreetmap.josm.actions.ExpertToggleAction; … … 22 22 import org.openstreetmap.josm.data.osm.Way; 23 23 import org.openstreetmap.josm.gui.MainApplication; 24 import org.openstreetmap.josm.testutils.JOSMTestRules; 25 26 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 24 27 25 28 /** … … 31 34 * Setup tests 32 35 */ 33 @BeforeClass 34 public static void setUpBeforeClass() { 35 JOSMFixture.createUnitTestFixture().init(true); 36 @Rule 37 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 38 public JOSMTestRules test = new JOSMTestRules().platform().projection().main(); 39 40 private DataSet ds; 41 private OsmDataLayer layer; 42 43 /** 44 * Setup tests 45 */ 46 @Before 47 public void setUp() { 48 ds = new DataSet(); 49 layer = new OsmDataLayer(ds, "", null); 50 MainApplication.getLayerManager().addLayer(layer); 36 51 } 37 52 … … 41 56 @Test 42 57 public void testRecentRelation() { 43 DataSet ds = new DataSet(); 44 OsmDataLayer layer = new OsmDataLayer(ds, "", null); 45 try { 46 MainApplication.getLayerManager().addLayer(layer); 47 int n = OsmDataLayer.PROPERTY_RECENT_RELATIONS_NUMBER.get(); 48 assertTrue(n > 0); 49 for (int i = 0; i < 2*n; i++) { 50 Relation r = new Relation(i, 1); 51 ds.addPrimitive(r); 52 layer.setRecentRelation(r); 58 int n = OsmDataLayer.PROPERTY_RECENT_RELATIONS_NUMBER.get(); 59 assertTrue(n > 0); 60 for (int i = 0; i < 2*n; i++) { 61 Relation r = new Relation(i, 1); 62 ds.addPrimitive(r); 63 layer.setRecentRelation(r); 64 } 65 assertEquals(n, layer.getRecentRelations().size()); 66 for (OsmPrimitive r : ds.allPrimitives()) { 67 if (r instanceof Relation) { 68 layer.removeRecentRelation((Relation) r); 53 69 } 54 assertEquals(n, layer.getRecentRelations().size());55 for (OsmPrimitive r : ds.allPrimitives()) {56 if (r instanceof Relation) {57 layer.removeRecentRelation((Relation) r);58 }59 }60 assertTrue(layer.getRecentRelations().isEmpty());61 } finally {62 MainApplication.getLayerManager().removeLayer(layer);63 70 } 71 assertTrue(layer.getRecentRelations().isEmpty()); 64 72 } 65 73 … … 69 77 @Test 70 78 public void testGetInfoComponent() { 71 DataSet ds = new DataSet();72 OsmDataLayer layer = new OsmDataLayer(ds, "", null);73 79 assertNotNull(layer.getInfoComponent()); 74 80 … … 108 114 @Test 109 115 public void testLayerStateChangeListenerNull() { 110 DataSet ds = new DataSet();111 OsmDataLayer layer = new OsmDataLayer(ds, "", null);112 116 layer.addLayerStateChangeListener(null); 113 117 } … … 118 122 @Test 119 123 public void testGetIcon() { 120 DataSet ds = new DataSet();121 OsmDataLayer layer = new OsmDataLayer(ds, "", null);122 124 assertNotNull(layer.getIcon()); 123 125 layer.setUploadDiscouraged(true); … … 130 132 @Test 131 133 public void testPaint() { 132 DataSet ds = new DataSet(); 133 fillDataSet(ds); 134 OsmDataLayer layer = new OsmDataLayer(ds, "", null); 135 try { 136 MainApplication.getLayerManager().addLayer(layer); 137 assertTrue(layer.getMenuEntries().length > 0); 138 layer.paint(TestUtils.newGraphics(), MainApplication.getMap().mapView, new Bounds(LatLon.ZERO)); 139 } finally { 140 MainApplication.getLayerManager().removeLayer(layer); 141 } 134 fillDataSet(ds); 135 assertNotNull(MainApplication.getMap()); 136 layer.paint(TestUtils.newGraphics(), MainApplication.getMap().mapView, new Bounds(LatLon.ZERO)); 142 137 } 143 138 … … 147 142 @Test 148 143 public void testGetToolTipText() { 149 DataSet ds = new DataSet();150 144 assertEquals("<html>0 nodes<br>0 ways<br>0 relations</html>", new OsmDataLayer(ds, "", null).getToolTipText()); 151 145 fillDataSet(ds); … … 159 153 @Test 160 154 public void testMergeFrom() { 161 DataSet ds = new DataSet(); 162 fillDataSet(ds); 163 OsmDataLayer layer1 = new OsmDataLayer(ds, "", null); 155 fillDataSet(ds); 164 156 OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "", null); 157 MainApplication.getLayerManager().addLayer(layer2); 165 158 assertTrue(layer2.data.allPrimitives().isEmpty()); 166 assertTrue(layer2.isMergable(layer 1));167 layer2.mergeFrom(layer 1);159 assertTrue(layer2.isMergable(layer)); 160 layer2.mergeFrom(layer); 168 161 assertEquals(6, layer2.data.allPrimitives().size()); 169 layer 1.setUploadDiscouraged(true);170 layer2.mergeFrom(layer 1);162 layer.setUploadDiscouraged(true); 163 layer2.mergeFrom(layer); 171 164 assertTrue(layer2.isUploadDiscouraged()); 172 165 } … … 177 170 @Test 178 171 public void testCleanupAfterUpload() { 179 DataSet ds = new DataSet(); 180 fillDataSet(ds); 181 OsmDataLayer layer = new OsmDataLayer(ds, "", null); 172 fillDataSet(ds); 182 173 assertEquals(6, layer.data.allPrimitives().size()); 183 174 layer.cleanupAfterUpload(ds.allPrimitives()); … … 190 181 @Test 191 182 public void testGetMenuEntries() { 192 OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null);193 183 ExpertToggleAction.getInstance().setExpert(true); 194 184 assertEquals(16, layer.getMenuEntries().length); … … 203 193 @Test 204 194 public void testToGpxData() { 205 DataSet ds = new DataSet(); 206 fillDataSet(ds); 207 OsmDataLayer layer = new OsmDataLayer(ds, "", null); 195 fillDataSet(ds); 208 196 assertNotNull(layer.toGpxData()); 209 197 } … … 214 202 @Test 215 203 public void testContainsPoint() { 216 DataSet ds = new DataSet(); 217 fillDataSet(ds); 218 OsmDataLayer layer = new OsmDataLayer(ds, "", null); 204 fillDataSet(ds); 219 205 assertTrue(layer.containsPoint(LatLon.ZERO)); 220 206 } … … 225 211 @Test 226 212 public void testIsModified() { 227 DataSet ds = new DataSet();228 OsmDataLayer layer = new OsmDataLayer(ds, "", null);229 213 assertFalse(layer.isModified()); 230 214 fillDataSet(ds); … … 237 221 @Test 238 222 public void testProjectionChanged() { 239 new OsmDataLayer(new DataSet(), "", null).projectionChanged(null, null);223 layer.projectionChanged(null, null); 240 224 } 241 225 … … 245 229 @Test 246 230 public void testCheckSaveConditions() { 247 DataSet ds = new DataSet();248 OsmDataLayer layer = new OsmDataLayer(ds, "", null);249 231 assertFalse(layer.checkSaveConditions()); 250 232 fillDataSet(ds); -
trunk/test/unit/org/openstreetmap/josm/gui/layer/ValidatorLayerTest.java
r12636 r13174 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;11 import org.openstreetmap.josm.data.osm.DataSet; 12 12 import org.openstreetmap.josm.gui.MainApplication; 13 import org.openstreetmap.josm.testutils.JOSMTestRules; 14 15 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 13 16 14 17 /** … … 20 23 * Setup tests 21 24 */ 22 @BeforeClass 23 public static void setUpBeforeClass() { 24 JOSMFixture.createUnitTestFixture().init(true); 25 } 25 @Rule 26 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 27 public JOSMTestRules test = new JOSMTestRules().platform().projection().main(); 26 28 27 29 /** … … 30 32 @Test 31 33 public void testValidatorLayer() { 32 ValidatorLayer layer = null; 33 try { 34 layer = new ValidatorLayer(); 35 MainApplication.getLayerManager().addLayer(layer); 36 assertFalse(layer.isMergable(null)); 37 assertNotNull(layer.getIcon()); 38 assertEquals("<html>No validation errors</html>", layer.getToolTipText()); 39 assertEquals("<html>No validation errors</html>", layer.getInfoComponent()); 40 assertTrue(layer.getMenuEntries().length > 0); 41 } finally { 42 // Ensure we clean the place before leaving, even if test fails. 43 if (layer != null) { 44 MainApplication.getLayerManager().removeLayer(layer); 45 } 46 } 34 MainApplication.getLayerManager().addLayer(new OsmDataLayer(new DataSet(), "", null)); 35 ValidatorLayer layer = new ValidatorLayer(); 36 MainApplication.getLayerManager().addLayer(layer); 37 assertFalse(layer.isMergable(null)); 38 assertNotNull(layer.getIcon()); 39 assertEquals("<html>No validation errors</html>", layer.getToolTipText()); 40 assertEquals("<html>No validation errors</html>", layer.getInfoComponent()); 41 assertTrue(layer.getMenuEntries().length > 0); 47 42 } 48 43 }
Note:
See TracChangeset
for help on using the changeset viewer.