Changeset 11988 in josm


Ignore:
Timestamp:
2017-04-23T21:49:05+02:00 (22 months ago)
Author:
Don-vip
Message:

improve unit test for Main.postConstructorProcessCmdLine

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/Main.java

    r11986 r11988  
    10021002         */
    10031003        List<Future<?>> downloadGps(String param) {
    1004             JOptionPane.showMessageDialog(
    1005                     Main.parent,
    1006                     tr("Parameter \"downloadgps\" does not accept file names or file URLs"),
    1007                     tr("Warning"),
    1008                     JOptionPane.WARNING_MESSAGE
    1009             );
     1004            if (!GraphicsEnvironment.isHeadless()) {
     1005                JOptionPane.showMessageDialog(
     1006                        Main.parent,
     1007                        tr("Parameter \"downloadgps\" does not accept file names or file URLs"),
     1008                        tr("Warning"),
     1009                        JOptionPane.WARNING_MESSAGE
     1010                );
     1011            }
    10101012            return Collections.emptyList();
    10111013        }
  • trunk/test/unit/org/openstreetmap/josm/MainTest.java

    r11986 r11988  
    88import static org.junit.Assert.assertTrue;
    99
     10import java.net.MalformedURLException;
     11import java.nio.file.Paths;
    1012import java.util.Collection;
    1113import java.util.List;
     
    9698    }
    9799
    98     /**
    99      * Unit test of {@link Main#postConstructorProcessCmdLine} - nominal cases.
    100      * This test assumes the DEV API contains nodes around 0,0 and GPX tracks around London
    101      */
    102     @Test
    103     public void testPostConstructorProcessCmdLineNominal() {
     100    private static void doTestPostConstructorProcessCmdLine(String download, String downloadGps, boolean gpx) {
    104101        assertNull(Main.getLayerManager().getEditDataSet());
    105102        Main.postConstructorProcessCmdLine(new ProgramArguments(new String[]{
    106                 "--download=0.01,0.01,0.05,0.05",
    107                 "--downloadgps=51.35,-0.4,51.60,0.2",
     103                "--download=" + download,
     104                "--downloadgps=" + downloadGps,
    108105                "--selection=type: node"}));
    109106        DataSet ds = Main.getLayerManager().getEditDataSet();
     
    111108        assertFalse(ds.getSelected().isEmpty());
    112109        Main.getLayerManager().removeLayer(Main.getLayerManager().getEditLayer());
    113         List<GpxLayer> gpxLayers = Main.getLayerManager().getLayersOfType(GpxLayer.class);
    114         assertEquals(1, gpxLayers.size());
    115         Main.getLayerManager().removeLayer(gpxLayers.iterator().next());
     110        if (gpx) {
     111            List<GpxLayer> gpxLayers = Main.getLayerManager().getLayersOfType(GpxLayer.class);
     112            assertEquals(1, gpxLayers.size());
     113            Main.getLayerManager().removeLayer(gpxLayers.iterator().next());
     114        }
     115    }
     116
     117    /**
     118     * Unit test of {@link Main#postConstructorProcessCmdLine} - nominal case with bounds.
     119     * This test assumes the DEV API contains nodes around 0,0 and GPX tracks around London
     120     */
     121    @Test
     122    public void testPostConstructorProcessCmdLineBounds() {
     123        doTestPostConstructorProcessCmdLine(
     124                "0.01,0.01,0.05,0.05",
     125                "51.35,-0.4,51.60,0.2", true);
     126    }
     127
     128    /**
     129     * Unit test of {@link Main#postConstructorProcessCmdLine} - nominal case with http/https URLs.
     130     * This test assumes the DEV API contains nodes around 0,0 and GPX tracks around London
     131     */
     132    @Test
     133    public void testPostConstructorProcessCmdLineHttpUrl() {
     134        doTestPostConstructorProcessCmdLine(
     135                "http://api06.dev.openstreetmap.org/api/0.6/map?bbox=0.01,0.01,0.05,0.05",
     136                "https://master.apis.dev.openstreetmap.org/api/0.6/trackpoints?bbox=-0.4,51.35,0.2,51.6&page=0", true);
     137    }
     138
     139    /**
     140     * Unit test of {@link Main#postConstructorProcessCmdLine} - nominal case with file URLs.
     141     * @throws MalformedURLException if an error occurs
     142     */
     143    @Test
     144    public void testPostConstructorProcessCmdLineFileUrl() throws MalformedURLException {
     145        doTestPostConstructorProcessCmdLine(
     146                Paths.get(TestUtils.getTestDataRoot() + "multipolygon.osm").toUri().toURL().toExternalForm(),
     147                Paths.get(TestUtils.getTestDataRoot() + "minimal.gpx").toUri().toURL().toExternalForm(), false);
     148    }
     149
     150    /**
     151     * Unit test of {@link Main#postConstructorProcessCmdLine} - nominal case with file names.
     152     * @throws MalformedURLException if an error occurs
     153     */
     154    @Test
     155    public void testPostConstructorProcessCmdLineFilename() throws MalformedURLException {
     156        doTestPostConstructorProcessCmdLine(
     157                Paths.get(TestUtils.getTestDataRoot() + "multipolygon.osm").toFile().getAbsolutePath(),
     158                Paths.get(TestUtils.getTestDataRoot() + "minimal.gpx").toFile().getAbsolutePath(), false);
    116159    }
    117160
Note: See TracChangeset for help on using the changeset viewer.