Changeset 9661 in josm


Ignore:
Timestamp:
2016-01-28T09:29:14+01:00 (9 years ago)
Author:
Don-vip
Message:

fix/cleanup unit tests

Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/actions/RefreshAction.java

    r9659 r9661  
    1414import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    1515import org.openstreetmap.josm.gui.HelpAwareOptionPane.ButtonSpec;
    16 import org.openstreetmap.josm.gui.dialogs.relation.GenericRelationEditor;
     16import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
    1717import org.openstreetmap.josm.gui.dialogs.relation.MemberTable;
    1818import org.openstreetmap.josm.gui.dialogs.relation.MemberTableModel;
    19 import org.openstreetmap.josm.gui.dialogs.relation.IRelationEditor;
    2019import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2120import org.openstreetmap.josm.gui.layer.OsmDataLayer.CommandQueueListener;
     
    4746        putValue(SMALL_ICON, ImageProvider.get("dialogs/refresh"));
    4847        putValue(NAME, tr("Refresh"));
    49         getEditor().getRootPane().getActionMap().put("refresh", this);
    50         getEditor().getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sc.getKeyStroke(), "refresh");
     48        if (editor instanceof JComponent) {
     49            ((JComponent) editor).getRootPane().getActionMap().put("refresh", this);
     50            ((JComponent) editor).getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(sc.getKeyStroke(), "refresh");
     51        }
    5152        Main.main.undoRedo.addCommandQueueListener(this);
    5253        updateEnabledState();
    53     }
    54 
    55     private GenericRelationEditor getEditor() {
    56         return (GenericRelationEditor) editor;
    5754    }
    5855
     
    7067        if (isEditorDirty() && confirmDiscardDirtyData() != 0)
    7168            return;
    72         getEditor().reloadDataFromRelation();
     69        editor.reloadDataFromRelation();
    7370    }
    7471
  • trunk/test/unit/org/openstreetmap/josm/actions/AlignInLineActionTest.java

    r8857 r9661  
    6767        } finally {
    6868            // Ensure we clean the place before leaving, even if test fails.
    69             Main.map.mapView.removeLayer(layer);
     69            Main.main.removeLayer(layer);
    7070        }
    7171
     
    106106        } finally {
    107107            // Ensure we clean the place before leaving, even if test fails.
    108             Main.map.mapView.removeLayer(layer);
     108            Main.main.removeLayer(layer);
    109109        }
    110110
     
    149149        } finally {
    150150            // Ensure we clean the place before leaving, even if test fails.
    151             Main.map.mapView.removeLayer(layer);
     151            Main.main.removeLayer(layer);
    152152        }
    153153
  • trunk/test/unit/org/openstreetmap/josm/actions/CreateCircleActionTest.java

    r8876 r9661  
    9797        } finally {
    9898            // Ensure we clean the place before leaving, even if test fails.
    99             Main.map.mapView.removeLayer(layer);
     99            Main.main.removeLayer(layer);
    100100        }
    101101
     
    175175        } finally {
    176176            // Ensure we clean the place before leaving, even if test fails.
    177             Main.map.mapView.removeLayer(layer);
     177            Main.main.removeLayer(layer);
    178178        }
    179179
  • trunk/test/unit/org/openstreetmap/josm/actions/SelectByInternalPointActionTest.java

    r9594 r9661  
    7979    public void testGetSurroundingObjects() {
    8080        Layer layer = initDataSet();
    81         assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(null).size());
    82         assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(new EastNorth(0, 0)).size());
    83         assertEquals(1, SelectByInternalPointAction.getSurroundingObjects(new EastNorth(1.5, 1.5)).size());
    84         assertEquals(0, SelectByInternalPointAction.getSurroundingObjects(new EastNorth(3, 3)).size());
    85         Main.main.removeLayer(layer);
     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.main.removeLayer(layer);
     89        }
    8690    }
    8791
     
    9296    public void testGetSmallestSurroundingObject() {
    9397        Layer layer = initDataSet();
    94         assertNull(SelectByInternalPointAction.getSmallestSurroundingObject(null));
    95         assertNotNull(SelectByInternalPointAction.getSmallestSurroundingObject(new EastNorth(1.5, 1.5)));
    96         Main.main.removeLayer(layer);
     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.main.removeLayer(layer);
     104        }
    97105    }
    98106
     
    103111    public void testPerformSelection() {
    104112        Layer layer = initDataSet();
    105         DataSet ds = JosmAction.getCurrentDataSet();
     113        try {
     114            DataSet ds = JosmAction.getCurrentDataSet();
    106115
    107         assertEquals(0, ds.getSelected().size());
    108         SelectByInternalPointAction.performSelection(null, false, false);
    109         assertEquals(0, ds.getSelected().size());
    110         SelectByInternalPointAction.performSelection(new EastNorth(0, 0), false, false);
    111         assertEquals(0, ds.getSelected().size());
    112         SelectByInternalPointAction.performSelection(new EastNorth(1.5, 1.5), false, false);
    113         assertEquals(1, ds.getSelected().size());
    114         ds.clearSelection();
    115         ds.addSelected(ds.getNodes());
    116         assertEquals(4, ds.getSelected().size());
    117         SelectByInternalPointAction.performSelection(new EastNorth(1.5, 1.5), true, false);
    118         assertEquals(5, ds.getSelected().size());
    119         SelectByInternalPointAction.performSelection(new EastNorth(1.5, 1.5), false, true);
    120         assertEquals(4, ds.getSelected().size());
    121 
    122         Main.main.removeLayer(layer);
     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.main.removeLayer(layer);
     133        }
    123134    }
    124135}
  • trunk/test/unit/org/openstreetmap/josm/actions/SplitWayActionTest.java

    r8965 r9661  
    8484        } finally {
    8585            // Ensure we clean the place before leaving, even if test fails.
    86             Main.map.mapView.removeLayer(layer);
     86            Main.main.removeLayer(layer);
    8787        }
    8888
  • trunk/test/unit/org/openstreetmap/josm/actions/UnJoinNodeWayActionTest.java

    r8857 r9661  
    7878        } finally {
    7979            // Ensure we clean the place before leaving, even if test fails.
    80             Main.map.mapView.removeLayer(layer);
     80            Main.main.removeLayer(layer);
    8181        }
    8282
  • trunk/test/unit/org/openstreetmap/josm/actions/mapmode/DrawActionTest.java

    r8949 r9661  
    6868
    6969        Main.main.addLayer(layer);
    70         assertTrue(Main.map.selectDrawTool(false));
     70        try {
     71            assertTrue(Main.map.selectDrawTool(false));
    7172
    72         Main.map.mapModeDraw.mouseReleased(new MouseEvent(
    73                 Main.map,
    74                 MouseEvent.MOUSE_RELEASED,
    75                 2000,
    76                 InputEvent.BUTTON1_MASK,
    77                 50, 0,
    78                 2, false));
     73            Main.map.mapModeDraw.mouseReleased(new MouseEvent(
     74                    Main.map,
     75                    MouseEvent.MOUSE_RELEASED,
     76                    2000,
     77                    InputEvent.BUTTON1_MASK,
     78                    50, 0,
     79                    2, false));
    7980
    80         JList<OsmPrimitive> lstPrimitives = new JList<>();
    81         OsmPrimitivRenderer renderer = new OsmPrimitivRenderer();
     81            JList<OsmPrimitive> lstPrimitives = new JList<>();
     82            OsmPrimitivRenderer renderer = new OsmPrimitivRenderer();
    8283
    83         assertEquals(3, w.getNodesCount());
    84         Collection<Node> sel = dataSet.getSelectedNodes();
    85         assertEquals(1, sel.size());
     84            assertEquals(3, w.getNodesCount());
     85            Collection<Node> sel = dataSet.getSelectedNodes();
     86            assertEquals(1, sel.size());
    8687
    87         Node n3 = sel.iterator().next();
     88            Node n3 = sel.iterator().next();
    8889
    89         assertNotNull(renderer.getListCellRendererComponent(lstPrimitives, n3, 0, false, false));
     90            assertNotNull(renderer.getListCellRendererComponent(lstPrimitives, n3, 0, false, false));
    9091
    91         Main.main.undoRedo.undo();
     92            Main.main.undoRedo.undo();
    9293
    93         assertEquals(2, w.getNodesCount());
    94         assertTrue(dataSet.getSelectedNodes().isEmpty());
     94            assertEquals(2, w.getNodesCount());
     95            assertTrue(dataSet.getSelectedNodes().isEmpty());
    9596
    96         assertNotNull(renderer.getListCellRendererComponent(lstPrimitives, n3, 0, false, false));
     97            assertNotNull(renderer.getListCellRendererComponent(lstPrimitives, n3, 0, false, false));
     98        } finally {
     99            // Ensure we clean the place before leaving, even if test fails.
     100            Main.main.removeLayer(layer);
     101        }
    97102    }
    98103}
  • trunk/test/unit/org/openstreetmap/josm/actions/mapmode/SelectActionTest.java

    r9205 r9661  
    102102        Main.pref = new PreferencesMock();
    103103        Main.main.addLayer(layer);
    104         SelectAction action = new SelectActionMock(Main.map, dataSet, layer);
    105         nodesMerged = false;
     104        try {
     105            SelectAction action = new SelectActionMock(Main.map, dataSet, layer);
     106            nodesMerged = false;
    106107
    107         action.setEnabled(true);
    108         action.putValue("active", true);
     108            action.setEnabled(true);
     109            action.putValue("active", true);
    109110
    110         MouseEvent event;
    111         event = new MouseEvent(Main.map,
    112                                MouseEvent.MOUSE_PRESSED,
    113                                0,
    114                                InputEvent.BUTTON1_MASK | InputEvent.CTRL_MASK,
    115                                100, 0,
    116                                1,
    117                                false);
    118         action.mousePressed(event);
    119         event = new MouseEvent(Main.map,
    120                                MouseEvent.MOUSE_DRAGGED,
    121                                1000,
    122                                InputEvent.BUTTON1_MASK | InputEvent.CTRL_MASK,
    123                                50, 0,
    124                                1,
    125                                false);
    126         action.mouseDragged(event);
    127         event = new MouseEvent(Main.map,
    128                                MouseEvent.MOUSE_RELEASED,
    129                                2000,
    130                                InputEvent.BUTTON1_MASK | InputEvent.CTRL_MASK,
    131                                5, 0,
    132                                1,
    133                                false);
    134         action.mouseReleased(event);
     111            MouseEvent event;
     112            event = new MouseEvent(Main.map,
     113                                   MouseEvent.MOUSE_PRESSED,
     114                                   0,
     115                                   InputEvent.BUTTON1_MASK | InputEvent.CTRL_MASK,
     116                                   100, 0,
     117                                   1,
     118                                   false);
     119            action.mousePressed(event);
     120            event = new MouseEvent(Main.map,
     121                                   MouseEvent.MOUSE_DRAGGED,
     122                                   1000,
     123                                   InputEvent.BUTTON1_MASK | InputEvent.CTRL_MASK,
     124                                   50, 0,
     125                                   1,
     126                                   false);
     127            action.mouseDragged(event);
     128            event = new MouseEvent(Main.map,
     129                                   MouseEvent.MOUSE_RELEASED,
     130                                   2000,
     131                                   InputEvent.BUTTON1_MASK | InputEvent.CTRL_MASK,
     132                                   5, 0,
     133                                   1,
     134                                   false);
     135            action.mouseReleased(event);
    135136
    136         // As result of test, we must find a 2 nodes way, from EN(0, 0) to EN(100, 0)
    137         assertTrue("Nodes are not merged", nodesMerged);
    138         assertSame(String.format("Expect exactly one way, found %d\n", dataSet.getWays().size()),
    139                    dataSet.getWays().size(), 1);
    140         Way rw = dataSet.getWays().iterator().next();
    141         assertFalse("Way shouldn't be deleted\n", rw.isDeleted());
    142         assertSame(String.format("Way shouldn't have 2 nodes, %d found\n", w.getNodesCount()),
    143                    rw.getNodesCount(), 2);
    144         Node r1 = rw.firstNode();
    145         Node r2 = rw.lastNode();
    146         if (r1.getEastNorth().east() > r2.getEastNorth().east()) {
    147             Node tmp = r1;
    148             r1 = r2;
    149             r2 = tmp;
     137            // As result of test, we must find a 2 nodes way, from EN(0, 0) to EN(100, 0)
     138            assertTrue("Nodes are not merged", nodesMerged);
     139            assertSame(String.format("Expect exactly one way, found %d\n", dataSet.getWays().size()),
     140                       dataSet.getWays().size(), 1);
     141            Way rw = dataSet.getWays().iterator().next();
     142            assertFalse("Way shouldn't be deleted\n", rw.isDeleted());
     143            assertSame(String.format("Way shouldn't have 2 nodes, %d found\n", w.getNodesCount()),
     144                       rw.getNodesCount(), 2);
     145            Node r1 = rw.firstNode();
     146            Node r2 = rw.lastNode();
     147            if (r1.getEastNorth().east() > r2.getEastNorth().east()) {
     148                Node tmp = r1;
     149                r1 = r2;
     150                r2 = tmp;
     151            }
     152            assertSame(String.format("East should be 0, found %f\n", r1.getEastNorth().east()),
     153                       Double.compare(r1.getEastNorth().east(), 0), 0);
     154            assertSame(String.format("East should be 100, found %f\n", r2.getEastNorth().east()),
     155                       Double.compare(r2.getEastNorth().east(), 100), 0);
     156        } finally {
     157            // Ensure we clean the place before leaving, even if test fails.
     158            Main.main.removeLayer(layer);
    150159        }
    151         assertSame(String.format("East should be 0, found %f\n", r1.getEastNorth().east()),
    152                    Double.compare(r1.getEastNorth().east(), 0), 0);
    153         assertSame(String.format("East should be 100, found %f\n", r2.getEastNorth().east()),
    154                    Double.compare(r2.getEastNorth().east(), 100), 0);
    155160    }
    156161}
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/TMSLayerTest.java

    r9436 r9661  
    5050    private static void test(ImageryType expected, TMSLayer layer) {
    5151        Main.main.addLayer(layer);
    52         assertEquals(expected, layer.getInfo().getImageryType());
     52        try {
     53            assertEquals(expected, layer.getInfo().getImageryType());
     54        } finally {
     55            // Ensure we clean the place before leaving, even if test fails.
     56            Main.main.removeLayer(layer);
     57        }
    5358    }
    5459
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/WMSLayerTest.java

    r9436 r9661  
    3131        WMSLayer wms = new WMSLayer(new ImageryInfo("test wms", "http://localhost"));
    3232        Main.main.addLayer(wms);
    33         assertEquals(ImageryType.WMS, wms.getInfo().getImageryType());
     33        try {
     34            assertEquals(ImageryType.WMS, wms.getInfo().getImageryType());
     35        } finally {
     36            // Ensure we clean the place before leaving, even if test fails.
     37            Main.main.removeLayer(wms);
     38        }
    3439    }
    3540}
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayerTest.java

    r9660 r9661  
    4242            assertTrue(reader.parse(true));
    4343            GpxLayer gpxLayer = new GpxLayer(reader.getGpxData());
    44             Main.main.addLayer(gpxLayer);
    45             assertEquals(1, Main.map.mapView.getNumLayers());
    46             new Loader(
    47                     Collections.singleton(new File(TestUtils.getRegressionDataFile(12255, "G0016941.JPG"))),
    48                     gpxLayer).run();
    49             assertEquals(2, Main.map.mapView.getNumLayers());
    50             GeoImageLayer layer = Main.map.mapView.getLayersOfType(GeoImageLayer.class).iterator().next();
    51             assertEquals(gpxLayer, layer.getGpxLayer());
    52             List<ImageEntry> images = layer.getImages();
    53             assertEquals(1, images.size());
    54             assertEquals("<html>1 image loaded. 0 were found to be GPS tagged.</html>", layer.getInfoComponent());
    55             assertEquals("<html>1 image loaded. 0 were found to be GPS tagged.</html>", layer.getToolTipText());
     44            try {
     45                Main.main.addLayer(gpxLayer);
     46                assertEquals(1, Main.map.mapView.getNumLayers());
     47                new Loader(
     48                        Collections.singleton(new File(TestUtils.getRegressionDataFile(12255, "G0016941.JPG"))),
     49                        gpxLayer).run();
     50                assertEquals(2, Main.map.mapView.getNumLayers());
     51                GeoImageLayer layer = Main.map.mapView.getLayersOfType(GeoImageLayer.class).iterator().next();
     52                try {
     53                    assertEquals(gpxLayer, layer.getGpxLayer());
     54                    List<ImageEntry> images = layer.getImages();
     55                    assertEquals(1, images.size());
     56                    assertEquals("<html>1 image loaded. 0 were found to be GPS tagged.</html>", layer.getInfoComponent());
     57                    assertEquals("<html>1 image loaded. 0 were found to be GPS tagged.</html>", layer.getToolTipText());
     58                } finally {
     59                    // Ensure we clean the place before leaving, even if test fails.
     60                    Main.map.mapView.removeLayer(layer);
     61                }
     62            } finally {
     63                // Ensure we clean the place before leaving, even if test fails.
     64                Main.main.removeLayer(gpxLayer);
     65            }
    5666        }
    5767    }
Note: See TracChangeset for help on using the changeset viewer.