Changeset 12633 in josm for trunk/test/unit
- Timestamp:
- 2017-08-24T12:09:39+02:00 (7 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/MainTest.java
r12632 r12633 11 11 import java.net.MalformedURLException; 12 12 import java.net.URL; 13 import java.nio.file.Paths;14 13 import java.util.Collection; 15 import java.util.List;16 14 import java.util.Map; 17 import java.util.concurrent.ExecutionException;18 import java.util.concurrent.Future;19 15 20 16 import javax.swing.UIManager; … … 22 18 import org.junit.Rule; 23 19 import org.junit.Test; 24 import org.openstreetmap.josm.Main.DownloadParamType;25 20 import org.openstreetmap.josm.Main.InitStatusListener; 26 21 import org.openstreetmap.josm.Main.InitializationTask; 27 22 import org.openstreetmap.josm.actions.AboutAction; 28 import org.openstreetmap.josm. data.osm.DataSet;23 import org.openstreetmap.josm.gui.DownloadParamType; 29 24 import org.openstreetmap.josm.gui.MapFrameListener; 30 import org.openstreetmap.josm.gui.ProgramArguments;31 import org.openstreetmap.josm.gui.layer.GpxLayer;32 25 import org.openstreetmap.josm.io.OnlineResource; 33 26 import org.openstreetmap.josm.testutils.JOSMTestRules; 34 import org.openstreetmap.josm.tools.Logging;35 27 import org.openstreetmap.josm.tools.Shortcut; 36 28 … … 105 97 assertEquals(Main.pref.get("laf", Main.platform.getDefaultStyle()), UIManager.getLookAndFeel().getClass().getCanonicalName()); 106 98 assertNotNull(Main.toolbar); 107 }108 109 /**110 * Unit test of {@link Main#postConstructorProcessCmdLine} - empty case.111 */112 @Test113 public void testPostConstructorProcessCmdLineEmpty() {114 // Check the method accepts no arguments115 Main.postConstructorProcessCmdLine(new ProgramArguments(new String[0]));116 }117 118 private static void doTestPostConstructorProcessCmdLine(String download, String downloadGps, boolean gpx) {119 assertNull(Main.getLayerManager().getEditDataSet());120 for (Future<?> f : Main.postConstructorProcessCmdLine(new ProgramArguments(new String[]{121 "--download=" + download,122 "--downloadgps=" + downloadGps,123 "--selection=type: node"}))) {124 try {125 f.get();126 } catch (InterruptedException | ExecutionException e) {127 Logging.error(e);128 }129 }130 DataSet ds = Main.getLayerManager().getEditDataSet();131 assertNotNull(ds);132 assertFalse(ds.getSelected().isEmpty());133 Main.getLayerManager().removeLayer(Main.getLayerManager().getEditLayer());134 if (gpx) {135 List<GpxLayer> gpxLayers = Main.getLayerManager().getLayersOfType(GpxLayer.class);136 assertEquals(1, gpxLayers.size());137 Main.getLayerManager().removeLayer(gpxLayers.iterator().next());138 }139 }140 141 /**142 * Unit test of {@link Main#postConstructorProcessCmdLine} - nominal case with bounds.143 * This test assumes the DEV API contains nodes around 0,0 and GPX tracks around London144 */145 @Test146 public void testPostConstructorProcessCmdLineBounds() {147 doTestPostConstructorProcessCmdLine(148 "0.01,0.01,0.05,0.05",149 "51.35,-0.4,51.60,0.2", true);150 }151 152 /**153 * Unit test of {@link Main#postConstructorProcessCmdLine} - nominal case with http/https URLs.154 * This test assumes the DEV API contains nodes around 0,0 and GPX tracks around London155 */156 @Test157 public void testPostConstructorProcessCmdLineHttpUrl() {158 doTestPostConstructorProcessCmdLine(159 "http://api06.dev.openstreetmap.org/api/0.6/map?bbox=0.01,0.01,0.05,0.05",160 "https://master.apis.dev.openstreetmap.org/api/0.6/trackpoints?bbox=-0.4,51.35,0.2,51.6&page=0", true);161 }162 163 /**164 * Unit test of {@link Main#postConstructorProcessCmdLine} - nominal case with file URLs.165 * @throws MalformedURLException if an error occurs166 */167 @Test168 public void testPostConstructorProcessCmdLineFileUrl() throws MalformedURLException {169 doTestPostConstructorProcessCmdLine(170 Paths.get(TestUtils.getTestDataRoot() + "multipolygon.osm").toUri().toURL().toExternalForm(),171 Paths.get(TestUtils.getTestDataRoot() + "minimal.gpx").toUri().toURL().toExternalForm(), false);172 }173 174 /**175 * Unit test of {@link Main#postConstructorProcessCmdLine} - nominal case with file names.176 * @throws MalformedURLException if an error occurs177 */178 @Test179 public void testPostConstructorProcessCmdLineFilename() throws MalformedURLException {180 doTestPostConstructorProcessCmdLine(181 Paths.get(TestUtils.getTestDataRoot() + "multipolygon.osm").toFile().getAbsolutePath(),182 Paths.get(TestUtils.getTestDataRoot() + "minimal.gpx").toFile().getAbsolutePath(), false);183 }184 185 /**186 * Unit test of {@link DownloadParamType} enum.187 */188 @Test189 public void testEnumDownloadParamType() {190 TestUtils.superficialEnumCodeCoverage(DownloadParamType.class);191 99 } 192 100 -
trunk/test/unit/org/openstreetmap/josm/gui/MainApplicationTest.java
r12632 r12633 3 3 4 4 import static org.junit.Assert.assertEquals; 5 import static org.junit.Assert.assertFalse; 5 6 import static org.junit.Assert.assertNotNull; 6 7 import static org.junit.Assert.assertNull; … … 9 10 import java.io.IOException; 10 11 import java.io.PrintStream; 12 import java.net.MalformedURLException; 11 13 import java.nio.charset.StandardCharsets; 14 import java.nio.file.Paths; 12 15 import java.util.Arrays; 13 16 import java.util.Collection; 17 import java.util.List; 18 import java.util.concurrent.ExecutionException; 19 import java.util.concurrent.Future; 14 20 15 21 import org.junit.Rule; 16 22 import org.junit.Test; 23 import org.openstreetmap.josm.Main; 24 import org.openstreetmap.josm.TestUtils; 17 25 import org.openstreetmap.josm.data.Version; 26 import org.openstreetmap.josm.data.osm.DataSet; 18 27 import org.openstreetmap.josm.gui.SplashScreen.SplashProgressMonitor; 28 import org.openstreetmap.josm.gui.layer.GpxLayer; 19 29 import org.openstreetmap.josm.plugins.PluginHandler; 20 30 import org.openstreetmap.josm.plugins.PluginHandlerTestIT; … … 23 33 import org.openstreetmap.josm.plugins.PluginListParser; 24 34 import org.openstreetmap.josm.testutils.JOSMTestRules; 35 import org.openstreetmap.josm.tools.Logging; 25 36 26 37 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 113 124 ""); 114 125 } 126 127 /** 128 * Unit test of {@link MainApplication#postConstructorProcessCmdLine} - empty case. 129 */ 130 @Test 131 public void testPostConstructorProcessCmdLineEmpty() { 132 // Check the method accepts no arguments 133 MainApplication.postConstructorProcessCmdLine(new ProgramArguments(new String[0])); 134 } 135 136 private static void doTestPostConstructorProcessCmdLine(String download, String downloadGps, boolean gpx) { 137 assertNull(Main.getLayerManager().getEditDataSet()); 138 for (Future<?> f : MainApplication.postConstructorProcessCmdLine(new ProgramArguments(new String[]{ 139 "--download=" + download, 140 "--downloadgps=" + downloadGps, 141 "--selection=type: node"}))) { 142 try { 143 f.get(); 144 } catch (InterruptedException | ExecutionException e) { 145 Logging.error(e); 146 } 147 } 148 DataSet ds = Main.getLayerManager().getEditDataSet(); 149 assertNotNull(ds); 150 assertFalse(ds.getSelected().isEmpty()); 151 Main.getLayerManager().removeLayer(Main.getLayerManager().getEditLayer()); 152 if (gpx) { 153 List<GpxLayer> gpxLayers = Main.getLayerManager().getLayersOfType(GpxLayer.class); 154 assertEquals(1, gpxLayers.size()); 155 Main.getLayerManager().removeLayer(gpxLayers.iterator().next()); 156 } 157 } 158 159 /** 160 * Unit test of {@link MainApplication#postConstructorProcessCmdLine} - nominal case with bounds. 161 * This test assumes the DEV API contains nodes around 0,0 and GPX tracks around London 162 */ 163 @Test 164 public void testPostConstructorProcessCmdLineBounds() { 165 doTestPostConstructorProcessCmdLine( 166 "0.01,0.01,0.05,0.05", 167 "51.35,-0.4,51.60,0.2", true); 168 } 169 170 /** 171 * Unit test of {@link MainApplication#postConstructorProcessCmdLine} - nominal case with http/https URLs. 172 * This test assumes the DEV API contains nodes around 0,0 and GPX tracks around London 173 */ 174 @Test 175 public void testPostConstructorProcessCmdLineHttpUrl() { 176 doTestPostConstructorProcessCmdLine( 177 "http://api06.dev.openstreetmap.org/api/0.6/map?bbox=0.01,0.01,0.05,0.05", 178 "https://master.apis.dev.openstreetmap.org/api/0.6/trackpoints?bbox=-0.4,51.35,0.2,51.6&page=0", true); 179 } 180 181 /** 182 * Unit test of {@link MainApplication#postConstructorProcessCmdLine} - nominal case with file URLs. 183 * @throws MalformedURLException if an error occurs 184 */ 185 @Test 186 public void testPostConstructorProcessCmdLineFileUrl() throws MalformedURLException { 187 doTestPostConstructorProcessCmdLine( 188 Paths.get(TestUtils.getTestDataRoot() + "multipolygon.osm").toUri().toURL().toExternalForm(), 189 Paths.get(TestUtils.getTestDataRoot() + "minimal.gpx").toUri().toURL().toExternalForm(), false); 190 } 191 192 /** 193 * Unit test of {@link MainApplication#postConstructorProcessCmdLine} - nominal case with file names. 194 * @throws MalformedURLException if an error occurs 195 */ 196 @Test 197 public void testPostConstructorProcessCmdLineFilename() throws MalformedURLException { 198 doTestPostConstructorProcessCmdLine( 199 Paths.get(TestUtils.getTestDataRoot() + "multipolygon.osm").toFile().getAbsolutePath(), 200 Paths.get(TestUtils.getTestDataRoot() + "minimal.gpx").toFile().getAbsolutePath(), false); 201 } 202 203 /** 204 * Unit test of {@link DownloadParamType} enum. 205 */ 206 @Test 207 public void testEnumDownloadParamType() { 208 TestUtils.superficialEnumCodeCoverage(DownloadParamType.class); 209 } 115 210 }
Note:
See TracChangeset
for help on using the changeset viewer.