Changeset 13174 in josm


Ignore:
Timestamp:
2017-11-28T02:52:05+01:00 (3 weeks ago)
Author:
Don-vip
Message:

see #15310 - fix unit tests, warnings

Location:
trunk
Files:
9 edited

Legend:

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

    r13173 r13174  
    1010import java.util.Objects;
    1111
    12 import org.openstreetmap.josm.Main;
    1312import org.openstreetmap.josm.data.coor.EastNorth;
    1413import org.openstreetmap.josm.data.coor.LatLon;
  • trunk/src/org/openstreetmap/josm/data/StructUtils.java

    r13173 r13174  
    197197     * @return an object of class T, initialized as described above
    198198     */
    199     @SuppressWarnings("deprecation")
    200199    public static <T> T deserializeStruct(Map<String, String> hash, Class<T> klass) {
    201200        T struct = null;
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r13173 r13174  
    181181 * @author imi
    182182 */
    183 @SuppressWarnings("deprecation")
    184183public class MainApplication extends Main {
    185184
     
    472471     * Should set {@link #menu} and {@link #mainPanel}
    473472     */
    474     @SuppressWarnings("deprecation")
    475473    protected void initializeMainWindow() {
    476474        if (mainFrame != null) {
     
    572570     * @since 12636 (as a replacement to {@code Main.getLayerManager()})
    573571     */
    574     @SuppressWarnings("deprecation")
    575572    public static MainLayerManager getLayerManager() {
    576573        return layerManager;
     
    625622     * @since 12630 (as a replacement to {@code Main.isDisplayingMapView()})
    626623     */
    627     @SuppressWarnings("deprecation")
    628624    public static boolean isDisplayingMapView() {
    629625        return map != null && map.mapView != null;
     
    663659     * @since 12639 (as a replacement to {@code Main.addAndFireMapFrameListener})
    664660     */
    665     @SuppressWarnings("deprecation")
    666661    public static boolean addAndFireMapFrameListener(MapFrameListener listener) {
    667662        return mainPanel != null && mainPanel.addAndFireMapFrameListener(listener);
     
    675670     * @since 12639 (as a replacement to {@code Main.addMapFrameListener})
    676671     */
    677     @SuppressWarnings("deprecation")
    678672    public static boolean addMapFrameListener(MapFrameListener listener) {
    679673        return mainPanel != null && mainPanel.addMapFrameListener(listener);
     
    686680     * @since 12639 (as a replacement to {@code Main.removeMapFrameListener})
    687681     */
    688     @SuppressWarnings("deprecation")
    689682    public static boolean removeMapFrameListener(MapFrameListener listener) {
    690683        return mainPanel != null && mainPanel.removeMapFrameListener(listener);
     
    696689     * @since 12639 (as a replacement to {@code Main.registerActionShortcut})
    697690     */
    698     @SuppressWarnings("deprecation")
    699691    public static void registerActionShortcut(JosmAction action) {
    700692        registerActionShortcut(action, action.getShortcut());
     
    707699     * @since 12639 (as a replacement to {@code Main.registerActionShortcut})
    708700     */
    709     @SuppressWarnings("deprecation")
    710701    public static void registerActionShortcut(Action action, Shortcut shortcut) {
    711702        KeyStroke keyStroke = shortcut.getKeyStroke();
     
    728719     * @since 12639 (as a replacement to {@code Main.unregisterShortcut})
    729720     */
    730     @SuppressWarnings("deprecation")
    731721    public static void unregisterShortcut(Shortcut shortcut) {
    732722        contentPanePrivate.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).remove(shortcut.getKeyStroke());
     
    738728     * @since 12639 (as a replacement to {@code Main.unregisterActionShortcut})
    739729     */
    740     @SuppressWarnings("deprecation")
    741730    public static void unregisterActionShortcut(JosmAction action) {
    742731        unregisterActionShortcut(action, action.getShortcut());
     
    749738     * @since 12639 (as a replacement to {@code Main.unregisterActionShortcut})
    750739     */
    751     @SuppressWarnings("deprecation")
    752740    public static void unregisterActionShortcut(Action action, Shortcut shortcut) {
    753741        unregisterShortcut(shortcut);
     
    761749     * @since 12639 (as a replacement to {@code Main.getRegisteredActionShortcut})
    762750     */
    763     @SuppressWarnings("deprecation")
    764751    public static Action getRegisteredActionShortcut(Shortcut shortcut) {
    765752        KeyStroke keyStroke = shortcut.getKeyStroke();
     
    845832     * @param argArray Command-line arguments
    846833     */
    847     @SuppressWarnings("deprecation")
    848834    public static void main(final String[] argArray) {
    849835        I18n.init();
  • trunk/src/org/openstreetmap/josm/gui/MainPanel.java

    r13173 r13174  
    4444     * @param showMap If the map should be displayed.
    4545     */
    46     @SuppressWarnings("deprecation")
    4746    protected synchronized void updateContent(boolean showMap) {
    4847        GuiHelper.assertCallFromEdt();
     
    8483    }
    8584
    86     @SuppressWarnings("deprecation")
    8785    private MapFrame createNewMapFrame() {
    8886        MapFrame mapFrame = new MapFrame(null);
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletingComboBox.java

    r13173 r13174  
    245245     */
    246246    @Override
    247     @SuppressWarnings("deprecation")
    248247    public void configureEditor(ComboBoxEditor cbEditor, Object item) {
    249248        if (item == null) {
     
    262261     */
    263262    @Override
    264     @SuppressWarnings("deprecation")
    265263    public void setSelectedItem(Object item) {
    266264        if (item == null) {
  • trunk/src/org/openstreetmap/josm/gui/util/AdvancedKeyPressDetector.java

    r13173 r13174  
    147147
    148148    @Override
    149     @SuppressWarnings("deprecation")
    150149    public void eventDispatched(AWTEvent e) {
    151150        if (!(e instanceof KeyEvent)) {
  • trunk/test/unit/org/openstreetmap/josm/JOSMFixture.java

    r13173 r13174  
    138138
    139139        if (createGui) {
    140             GuiHelper.runInEDTAndWaitWithException(new Runnable() {
    141                 @Override
    142                 public void run() {
    143                     setupGUI();
    144                 }
    145             });
     140            GuiHelper.runInEDTAndWaitWithException(() -> setupGUI());
    146141        }
    147142    }
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/OsmDataLayerTest.java

    r12636 r13174  
    99import java.io.File;
    1010
    11 import org.junit.BeforeClass;
     11import org.junit.Before;
     12import org.junit.Rule;
    1213import org.junit.Test;
    13 import org.openstreetmap.josm.JOSMFixture;
    1414import org.openstreetmap.josm.TestUtils;
    1515import org.openstreetmap.josm.actions.ExpertToggleAction;
     
    2222import org.openstreetmap.josm.data.osm.Way;
    2323import org.openstreetmap.josm.gui.MainApplication;
     24import org.openstreetmap.josm.testutils.JOSMTestRules;
     25
     26import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2427
    2528/**
     
    3134     * Setup tests
    3235     */
    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);
    3651    }
    3752
     
    4156    @Test
    4257    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);
    5369            }
    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);
    6370        }
     71        assertTrue(layer.getRecentRelations().isEmpty());
    6472    }
    6573
     
    6977    @Test
    7078    public void testGetInfoComponent() {
    71         DataSet ds = new DataSet();
    72         OsmDataLayer layer = new OsmDataLayer(ds, "", null);
    7379        assertNotNull(layer.getInfoComponent());
    7480
     
    108114    @Test
    109115    public void testLayerStateChangeListenerNull() {
    110         DataSet ds = new DataSet();
    111         OsmDataLayer layer = new OsmDataLayer(ds, "", null);
    112116        layer.addLayerStateChangeListener(null);
    113117    }
     
    118122    @Test
    119123    public void testGetIcon() {
    120         DataSet ds = new DataSet();
    121         OsmDataLayer layer = new OsmDataLayer(ds, "", null);
    122124        assertNotNull(layer.getIcon());
    123125        layer.setUploadDiscouraged(true);
     
    130132    @Test
    131133    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));
    142137    }
    143138
     
    147142    @Test
    148143    public void testGetToolTipText() {
    149         DataSet ds = new DataSet();
    150144        assertEquals("<html>0 nodes<br>0 ways<br>0 relations</html>", new OsmDataLayer(ds, "", null).getToolTipText());
    151145        fillDataSet(ds);
     
    159153    @Test
    160154    public void testMergeFrom() {
    161         DataSet ds = new DataSet();
    162         fillDataSet(ds);
    163         OsmDataLayer layer1 = new OsmDataLayer(ds, "", null);
     155        fillDataSet(ds);
    164156        OsmDataLayer layer2 = new OsmDataLayer(new DataSet(), "", null);
     157        MainApplication.getLayerManager().addLayer(layer2);
    165158        assertTrue(layer2.data.allPrimitives().isEmpty());
    166         assertTrue(layer2.isMergable(layer1));
    167         layer2.mergeFrom(layer1);
     159        assertTrue(layer2.isMergable(layer));
     160        layer2.mergeFrom(layer);
    168161        assertEquals(6, layer2.data.allPrimitives().size());
    169         layer1.setUploadDiscouraged(true);
    170         layer2.mergeFrom(layer1);
     162        layer.setUploadDiscouraged(true);
     163        layer2.mergeFrom(layer);
    171164        assertTrue(layer2.isUploadDiscouraged());
    172165    }
     
    177170    @Test
    178171    public void testCleanupAfterUpload() {
    179         DataSet ds = new DataSet();
    180         fillDataSet(ds);
    181         OsmDataLayer layer = new OsmDataLayer(ds, "", null);
     172        fillDataSet(ds);
    182173        assertEquals(6, layer.data.allPrimitives().size());
    183174        layer.cleanupAfterUpload(ds.allPrimitives());
     
    190181    @Test
    191182    public void testGetMenuEntries() {
    192         OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null);
    193183        ExpertToggleAction.getInstance().setExpert(true);
    194184        assertEquals(16, layer.getMenuEntries().length);
     
    203193    @Test
    204194    public void testToGpxData() {
    205         DataSet ds = new DataSet();
    206         fillDataSet(ds);
    207         OsmDataLayer layer = new OsmDataLayer(ds, "", null);
     195        fillDataSet(ds);
    208196        assertNotNull(layer.toGpxData());
    209197    }
     
    214202    @Test
    215203    public void testContainsPoint() {
    216         DataSet ds = new DataSet();
    217         fillDataSet(ds);
    218         OsmDataLayer layer = new OsmDataLayer(ds, "", null);
     204        fillDataSet(ds);
    219205        assertTrue(layer.containsPoint(LatLon.ZERO));
    220206    }
     
    225211    @Test
    226212    public void testIsModified() {
    227         DataSet ds = new DataSet();
    228         OsmDataLayer layer = new OsmDataLayer(ds, "", null);
    229213        assertFalse(layer.isModified());
    230214        fillDataSet(ds);
     
    237221    @Test
    238222    public void testProjectionChanged() {
    239         new OsmDataLayer(new DataSet(), "", null).projectionChanged(null, null);
     223        layer.projectionChanged(null, null);
    240224    }
    241225
     
    245229    @Test
    246230    public void testCheckSaveConditions() {
    247         DataSet ds = new DataSet();
    248         OsmDataLayer layer = new OsmDataLayer(ds, "", null);
    249231        assertFalse(layer.checkSaveConditions());
    250232        fillDataSet(ds);
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/ValidatorLayerTest.java

    r12636 r13174  
    77import static org.junit.Assert.assertTrue;
    88
    9 import org.junit.BeforeClass;
     9import org.junit.Rule;
    1010import org.junit.Test;
    11 import org.openstreetmap.josm.JOSMFixture;
     11import org.openstreetmap.josm.data.osm.DataSet;
    1212import org.openstreetmap.josm.gui.MainApplication;
     13import org.openstreetmap.josm.testutils.JOSMTestRules;
     14
     15import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1316
    1417/**
     
    2023     * Setup tests
    2124     */
    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();
    2628
    2729    /**
     
    3032    @Test
    3133    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);
    4742    }
    4843}
Note: See TracChangeset for help on using the changeset viewer.