Ticket #13037: patch-test-do-not-call-map-repaint.patch

File patch-test-do-not-call-map-repaint.patch, 72.5 KB (added by michael2402, 8 years ago)
  • src/org/openstreetmap/josm/actions/AddNodeAction.java

    diff --git a/src/org/openstreetmap/josm/actions/AddNodeAction.java b/src/org/openstreetmap/josm/actions/AddNodeAction.java
    index 29373b9..5cc050f 100644
    a b public final class AddNodeAction extends JosmAction {  
    6565        // add the node
    6666        Main.main.undoRedo.add(new AddCommand(nnew));
    6767        getLayerManager().getEditDataSet().setSelected(nnew);
    68         if (Main.map.mapView.getRealBounds().contains(nnew.getCoor())) {
    69             Main.map.mapView.repaint();
    70         } else {
    71             AutoScaleAction.zoomTo(Collections.<OsmPrimitive>singleton(nnew));
     68        if (Main.map.mapView != null) {
     69            if (Main.map.mapView.getRealBounds().contains(nnew.getCoor())) {
     70                Main.map.mapView.repaint();
     71            } else {
     72                AutoScaleAction.zoomTo(Collections.<OsmPrimitive>singleton(nnew));
     73            }
    7274        }
    7375    }
    7476
  • src/org/openstreetmap/josm/actions/AlignInCircleAction.java

    diff --git a/src/org/openstreetmap/josm/actions/AlignInCircleAction.java b/src/org/openstreetmap/josm/actions/AlignInCircleAction.java
    index 192dd8e..a0a1302 100644
    a b public final class AlignInCircleAction extends JosmAction {  
    283283        }
    284284
    285285        Main.main.undoRedo.add(new SequenceCommand(tr("Align Nodes in Circle"), cmds));
    286         Main.map.repaint();
    287286    }
    288287
    289288    /**
  • src/org/openstreetmap/josm/actions/AlignInLineAction.java

    diff --git a/src/org/openstreetmap/josm/actions/AlignInLineAction.java b/src/org/openstreetmap/josm/actions/AlignInLineAction.java
    index 4c30ea4..daa848d 100644
    a b public final class AlignInLineAction extends JosmAction {  
    204204
    205205            // Do it!
    206206            Main.main.undoRedo.add(cmd);
    207             Main.map.repaint();
    208207
    209208        } catch (InvalidSelection except) {
    210209            Main.debug(except);
  • src/org/openstreetmap/josm/actions/CreateCircleAction.java

    diff --git a/src/org/openstreetmap/josm/actions/CreateCircleAction.java b/src/org/openstreetmap/josm/actions/CreateCircleAction.java
    index 91d5bfc..2978476 100644
    a b public final class CreateCircleAction extends JosmAction {  
    240240        }
    241241
    242242        Main.main.undoRedo.add(new SequenceCommand(tr("Create Circle"), cmds));
    243         Main.map.repaint();
    244243    }
    245244
    246245    /**
  • src/org/openstreetmap/josm/actions/DistributeAction.java

    diff --git a/src/org/openstreetmap/josm/actions/DistributeAction.java b/src/org/openstreetmap/josm/actions/DistributeAction.java
    index aca100d..10945d7 100644
    a b public final class DistributeAction extends JosmAction {  
    9797
    9898        // Do it!
    9999        Main.main.undoRedo.add(new SequenceCommand(tr("Distribute Nodes"), cmds));
    100         Main.map.repaint();
    101100    }
    102101
    103102    /**
  • src/org/openstreetmap/josm/actions/ImageryAdjustAction.java

    diff --git a/src/org/openstreetmap/josm/actions/ImageryAdjustAction.java b/src/org/openstreetmap/josm/actions/ImageryAdjustAction.java
    index d444d45..a35cac3 100644
    a b public class ImageryAdjustAction extends MapMode implements AWTEventListener {  
    136136                Main.debug(getClass().getName()+" consuming event "+kev);
    137137            }
    138138            kev.consume();
    139             Main.map.repaint();
    140139        }
    141140    }
    142141
    public class ImageryAdjustAction extends MapMode implements AWTEventListener {  
    163162        if (offsetDialog != null) {
    164163            offsetDialog.updateOffset();
    165164        }
    166         Main.map.repaint();
    167165        prevEastNorth = eastNorth;
    168166    }
    169167
  • src/org/openstreetmap/josm/actions/JoinNodeWayAction.java

    diff --git a/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java b/src/org/openstreetmap/josm/actions/JoinNodeWayAction.java
    index 5a0bcfd..ab3d135 100644
    a b public class JoinNodeWayAction extends JosmAction {  
    159159
    160160        if (cmds.isEmpty()) return;
    161161        Main.main.undoRedo.add(new SequenceCommand(getValue(NAME).toString(), cmds));
    162         Main.map.repaint();
    163162    }
    164163
    165164    private static SortedSet<Integer> pruneSuccs(Collection<Integer> is) {
  • src/org/openstreetmap/josm/actions/MirrorAction.java

    diff --git a/src/org/openstreetmap/josm/actions/MirrorAction.java b/src/org/openstreetmap/josm/actions/MirrorAction.java
    index 36e4a8c..379afbd 100644
    a b public final class MirrorAction extends JosmAction {  
    8080        }
    8181
    8282        Main.main.undoRedo.add(new SequenceCommand(tr("Mirror"), cmds));
    83         Main.map.repaint();
    8483    }
    8584
    8685    @Override
  • src/org/openstreetmap/josm/actions/OrthogonalizeAction.java

    diff --git a/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java b/src/org/openstreetmap/josm/actions/OrthogonalizeAction.java
    index 9afb758..973c492 100644
    a b public final class OrthogonalizeAction extends JosmAction {  
    112112                }
    113113                if (!commands.isEmpty()) {
    114114                    Main.main.undoRedo.add(new SequenceCommand(tr("Orthogonalize / Undo"), commands));
    115                     Main.map.repaint();
    116115                } else {
    117116                    throw new InvalidUserInputException("Commands are empty");
    118117                }
    public final class OrthogonalizeAction extends JosmAction {  
    152151        try {
    153152            final SequenceCommand command = orthogonalize(sel);
    154153            Main.main.undoRedo.add(new SequenceCommand(tr("Orthogonalize"), command));
    155             Main.map.repaint();
    156154        } catch (InvalidUserInputException ex) {
    157155            Main.debug(ex);
    158156            String msg;
  • src/org/openstreetmap/josm/actions/ReverseWayAction.java

    diff --git a/src/org/openstreetmap/josm/actions/ReverseWayAction.java b/src/org/openstreetmap/josm/actions/ReverseWayAction.java
    index 531a58f..831bcc3 100644
    a b public final class ReverseWayAction extends JosmAction {  
    102102            propertiesUpdated |= !revResult.getTagCorrectionCommands().isEmpty();
    103103        }
    104104        Main.main.undoRedo.add(new SequenceCommand(tr("Reverse ways"), c));
     105        // FIXME: This should be handled by undoRedo.
    105106        if (propertiesUpdated) {
    106107            ds.fireSelectionChanged();
    107108        }
    108         Main.map.repaint();
    109109    }
    110110
    111111    /**
  • src/org/openstreetmap/josm/actions/SimplifyWayAction.java

    diff --git a/src/org/openstreetmap/josm/actions/SimplifyWayAction.java b/src/org/openstreetmap/josm/actions/SimplifyWayAction.java
    index 076967c..8a979c3 100644
    a b public class SimplifyWayAction extends JosmAction {  
    123123        } finally {
    124124            ds.endUpdate();
    125125        }
    126         Main.map.repaint();
    127126    }
    128127
    129128    /**
  • src/org/openstreetmap/josm/actions/UnJoinNodeWayAction.java

    diff --git a/src/org/openstreetmap/josm/actions/UnJoinNodeWayAction.java b/src/org/openstreetmap/josm/actions/UnJoinNodeWayAction.java
    index 494c3f5..0e52890 100644
    a b public class UnJoinNodeWayAction extends JosmAction {  
    9090
    9191        // I'm sure there's a better way to handle this
    9292        Main.main.undoRedo.add(new RemoveNodesCommand(selectedWay, selectedNodes));
    93         Main.map.repaint();
    9493    }
    9594
    9695    /**
  • src/org/openstreetmap/josm/actions/downloadtasks/DownloadReferrersTask.java

    diff --git a/src/org/openstreetmap/josm/actions/downloadtasks/DownloadReferrersTask.java b/src/org/openstreetmap/josm/actions/downloadtasks/DownloadReferrersTask.java
    index 3807238..41114c4 100644
    a b public class DownloadReferrersTask extends PleaseWaitRunnable {  
    121121                    @Override
    122122                    public void run() {
    123123                        targetLayer.onPostDownloadFromServer();
    124                         if (Main.map != null)
    125                             Main.map.mapView.repaint();
    126124                    }
    127125                }
    128126        );
  • src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java

    diff --git a/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java b/src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java
    index dedbb84..05d267e 100644
    a b public class DeleteAction extends MapMode implements ModifierListener {  
    133133     * @param e Action event
    134134     */
    135135    public static void doActionPerformed(ActionEvent e) {
    136         if (!Main.map.mapView.isActiveLayerDrawable())
     136        MainLayerManager lm = Main.getLayerManager();
     137        OsmDataLayer editLayer = lm.getEditLayer();
     138        if (editLayer == null) {
    137139            return;
     140        }
     141
    138142        boolean ctrl = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;
    139143        boolean alt = (e.getModifiers() & (ActionEvent.ALT_MASK | InputEvent.ALT_GRAPH_MASK)) != 0;
    140144
    141         MainLayerManager lm = Main.getLayerManager();
    142145        Command c;
    143146        if (ctrl) {
    144             c = DeleteCommand.deleteWithReferences(lm.getEditLayer(), lm.getEditDataSet().getSelected());
     147            c = DeleteCommand.deleteWithReferences(editLayer, lm.getEditDataSet().getSelected());
    145148        } else {
    146             c = DeleteCommand.delete(lm.getEditLayer(), lm.getEditDataSet().getSelected(), !alt /* also delete nodes in way */);
     149            c = DeleteCommand.delete(editLayer, lm.getEditDataSet().getSelected(), !alt /* also delete nodes in way */);
    147150        }
    148151        // if c is null, an error occurred or the user aborted. Don't do anything in that case.
    149152        if (c != null) {
    150153            Main.main.undoRedo.add(c);
     154            //FIXME: This should not be required, DeleteCommand should update the selection, otherwise undo/redo won't work.
    151155            lm.getEditDataSet().setSelected();
    152             Main.map.repaint();
    153156        }
    154157    }
    155158
    public class DeleteAction extends MapMode implements ModifierListener {  
    212215
    213216    private void repaintIfRequired(Set<OsmPrimitive> newHighlights, WaySegment newHighlightedWaySegment) {
    214217        boolean needsRepaint = false;
    215         DataSet ds = getLayerManager().getEditDataSet();
     218        OsmDataLayer editLayer = getLayerManager().getEditLayer();
    216219
    217220        if (newHighlightedWaySegment == null && oldHighlightedWaySegment != null) {
    218             if (ds != null) {
    219                 ds.clearHighlightedWaySegments();
     221            if (editLayer != null) {
     222                editLayer.data.clearHighlightedWaySegments();
    220223                needsRepaint = true;
    221224            }
    222225            oldHighlightedWaySegment = null;
    223226        } else if (newHighlightedWaySegment != null && !newHighlightedWaySegment.equals(oldHighlightedWaySegment)) {
    224             if (ds != null) {
    225                 ds.setHighlightedWaySegments(Collections.singleton(newHighlightedWaySegment));
     227            if (editLayer != null) {
     228                editLayer.data.setHighlightedWaySegments(Collections.singleton(newHighlightedWaySegment));
    226229                needsRepaint = true;
    227230            }
    228231            oldHighlightedWaySegment = newHighlightedWaySegment;
    229232        }
    230233        needsRepaint |= highlightHelper.highlightOnly(newHighlights);
    231         if (needsRepaint) {
    232             Main.map.mapView.repaint();
     234        if (needsRepaint && editLayer != null) {
     235            editLayer.invalidate();
    233236        }
    234237    }
    235238
  • src/org/openstreetmap/josm/actions/mapmode/DrawAction.java

    diff --git a/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java b/src/org/openstreetmap/josm/actions/mapmode/DrawAction.java
    index 3226fe9..fba4f5f 100644
    a b public class DrawAction extends MapMode implements MapViewPaintable, SelectionCh  
    184184            return false;
    185185
    186186        // update selection to reflect which way being modified
    187         DataSet currentDataSet = getLayerManager().getEditDataSet();
    188         if (getCurrentBaseNode() != null && currentDataSet != null && !currentDataSet.selectionEmpty()) {
     187        OsmDataLayer editLayer = getLayerManager().getEditLayer();
     188        if (getCurrentBaseNode() != null && editLayer != null && !editLayer.data.selectionEmpty()) {
     189            DataSet currentDataSet = editLayer.data;
    189190            Way continueFrom = getWayForNode(getCurrentBaseNode());
    190191            if (alt && continueFrom != null && (!getCurrentBaseNode().isSelected() || continueFrom.isSelected())) {
    191192                addRemoveSelection(currentDataSet, getCurrentBaseNode(), continueFrom);
    public class DrawAction extends MapMode implements MapViewPaintable, SelectionCh  
    196197            }
    197198        }
    198199
    199         if (needsRepaint) {
    200             Main.map.mapView.repaint();
     200        if (needsRepaint && editLayer != null) {
     201            editLayer.invalidate();
    201202        }
    202203        return needsRepaint;
    203204    }
    public class DrawAction extends MapMode implements MapViewPaintable, SelectionCh  
    916917     */
    917918    @Override
    918919    public void mouseExited(MouseEvent e) {
    919         if (!Main.map.mapView.isActiveLayerDrawable())
     920        OsmDataLayer editLayer = Main.getLayerManager().getEditLayer();
     921        if (editLayer == null) {
    920922            return;
     923        }
    921924        mousePos = e.getPoint();
    922925        snapHelper.noSnapNow();
    923926        boolean repaintIssued = removeHighlighting();
    924927        // force repaint in case snapHelper needs one. If removeHighlighting
    925928        // caused one already, don’t do it again.
    926929        if (!repaintIssued) {
    927             Main.map.mapView.repaint();
     930            editLayer.invalidate();
    928931        }
    929932    }
    930933
  • src/org/openstreetmap/josm/command/AddCommand.java

    diff --git a/src/org/openstreetmap/josm/command/AddCommand.java b/src/org/openstreetmap/josm/command/AddCommand.java
    index f22603b..0ed62bb 100644
    a b public class AddCommand extends Command {  
    5858
    5959    @Override
    6060    public boolean executeCommand() {
    61         getLayer().data.addPrimitive(osm);
     61        getAffectedDataSet().addPrimitive(osm);
    6262        osm.setModified(true);
    6363        checkNodeStyles(osm);
    6464        return true;
    public class AddCommand extends Command {  
    6666
    6767    @Override
    6868    public void undoCommand() {
    69         getLayer().data.removePrimitive(osm);
     69        getAffectedDataSet().removePrimitive(osm);
    7070        checkNodeStyles(osm);
    7171    }
    7272
  • src/org/openstreetmap/josm/command/AddPrimitivesCommand.java

    diff --git a/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java b/src/org/openstreetmap/josm/command/AddPrimitivesCommand.java
    index 1c43060..c3a9ab7 100644
    a b public class AddPrimitivesCommand extends Command {  
    7777            primitivesToSelect = new ArrayList<>(toSelect.size());
    7878
    7979            for (PrimitiveData pd : data) {
    80                 OsmPrimitive primitive = getLayer().data.getPrimitiveById(pd);
     80                OsmPrimitive primitive = getAffectedDataSet().getPrimitiveById(pd);
    8181                boolean created = primitive == null;
    8282                if (created) {
    8383                    primitive = pd.getType().newInstance(pd.getUniqueId(), true);
    public class AddPrimitivesCommand extends Command {  
    8686                    primitive.load(pd);
    8787                }
    8888                if (created) {
    89                     getLayer().data.addPrimitive(primitive);
     89                    getAffectedDataSet().addPrimitive(primitive);
    9090                }
    9191                newPrimitives.add(primitive);
    9292                if (toSelect.contains(pd)) {
    public class AddPrimitivesCommand extends Command {  
    114114    }
    115115
    116116    @Override public void undoCommand() {
    117         DataSet ds = getLayer().data;
     117        DataSet ds = getAffectedDataSet();
    118118
    119119        if (createdPrimitives == null) {
    120120            createdPrimitives = new ArrayList<>(data.size());
    public class AddPrimitivesCommand extends Command {  
    166166
    167167        Collection<OsmPrimitive> prims = new HashSet<>();
    168168        for (PrimitiveData d : data) {
    169             OsmPrimitive osm = getLayer().data.getPrimitiveById(d);
     169            OsmPrimitive osm = getAffectedDataSet().getPrimitiveById(d);
    170170            if (osm == null)
    171171                throw new RuntimeException();
    172172            prims.add(osm);
  • src/org/openstreetmap/josm/command/Command.java

    diff --git a/src/org/openstreetmap/josm/command/Command.java b/src/org/openstreetmap/josm/command/Command.java
    index e6e3bfc..fadce1a 100644
    a b import javax.swing.JPanel;  
    1616import org.openstreetmap.josm.Main;
    1717import org.openstreetmap.josm.data.coor.EastNorth;
    1818import org.openstreetmap.josm.data.coor.LatLon;
     19import org.openstreetmap.josm.data.osm.DataSet;
    1920import org.openstreetmap.josm.data.osm.Node;
    2021import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2122import org.openstreetmap.josm.data.osm.PrimitiveData;
    public abstract class Command extends PseudoCommand {  
    212213    }
    213214
    214215    /**
     216     * Gets the data set this command affects.
     217     * @return The data set. May be <code>null</code> if no layer was set and no edit layer was found.
     218     * @since xxx
     219     */
     220    public DataSet getAffectedDataSet() {
     221        return layer == null ? null : layer.data;
     222    }
     223
     224    /**
    215225     * Fill in the changed data this command operates on.
    216226     * Add to the lists, don't clear them.
    217227     *
  • src/org/openstreetmap/josm/command/conflict/WayNodesConflictResolverCommand.java

    diff --git a/src/org/openstreetmap/josm/command/conflict/WayNodesConflictResolverCommand.java b/src/org/openstreetmap/josm/command/conflict/WayNodesConflictResolverCommand.java
    index f94b18d..5d2e85b 100644
    a b public class WayNodesConflictResolverCommand extends ConflictResolveCommand {  
    5858        // replace the list of nodes of 'my' way by the list of merged nodes
    5959        //
    6060        for (Node n:mergedNodeList) {
    61             if (!getLayer().data.getNodes().contains(n)) {
     61            if (!getAffectedDataSet().getNodes().contains(n)) {
    6262                Main.warn(tr("Main dataset does not include node {0}", n.toString()));
    6363            }
    6464        }
  • src/org/openstreetmap/josm/data/UndoRedoHandler.java

    diff --git a/src/org/openstreetmap/josm/data/UndoRedoHandler.java b/src/org/openstreetmap/josm/data/UndoRedoHandler.java
    index bb39aae..6f77728 100644
    a b public class UndoRedoHandler implements LayerChangeListener {  
    7373     * @param c The command to execute. Must not be {@code null}.
    7474     */
    7575    public synchronized void add(final Command c) {
    76         DataSet ds = Main.getLayerManager().getEditDataSet();
    77         Collection<? extends OsmPrimitive> oldSelection = ds.getSelected();
     76        DataSet ds = c.getAffectedDataSet();
     77        if (ds == null) {
     78            // old, legacy behaviour
     79            ds = Main.getLayerManager().getEditDataSet();
     80        }
     81        Collection<? extends OsmPrimitive> oldSelection = null;
     82        if (ds != null) {
     83            oldSelection = ds.getSelected();
     84        }
    7885        addNoRedraw(c);
    7986        afterAdd();
    8087
    8188        // the command may have changed the selection so tell the listeners about the current situation
    82         fireIfSelectionChanged(ds, oldSelection);
     89        if (ds != null) {
     90            fireIfSelectionChanged(ds, oldSelection);
     91        }
    8392    }
    8493
    8594    /**
  • src/org/openstreetmap/josm/data/gpx/GpxData.java

    diff --git a/src/org/openstreetmap/josm/data/gpx/GpxData.java b/src/org/openstreetmap/josm/data/gpx/GpxData.java
    index 2d01218..da6d631 100644
    a b public class GpxData extends WithAttributes implements Data {  
    202202                } else {
    203203                    if (pnt.compareTo(earliest) < 0) {
    204204                        earliest = pnt;
    205                     } else {
     205                    } else if (pnt.compareTo(latest) > 0) {
    206206                        latest = pnt;
    207207                    }
    208208                }
  • src/org/openstreetmap/josm/data/gpx/WayPoint.java

    diff --git a/src/org/openstreetmap/josm/data/gpx/WayPoint.java b/src/org/openstreetmap/josm/data/gpx/WayPoint.java
    index 510f90f..7b85ee5 100644
    a b import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider;  
    1818public class WayPoint extends WithAttributes implements Comparable<WayPoint>, TemplateEngineDataProvider {
    1919
    2020    /**
    21      * The seconds (not milliseconds!) since 1970-01-01.
     21     * The seconds (not milliseconds!) since 1970-01-01 00:00 UTC
    2222     */
    2323    public double time;
    2424    public Color customColoring;
  • src/org/openstreetmap/josm/gui/MainApplication.java

    diff --git a/src/org/openstreetmap/josm/gui/MainApplication.java b/src/org/openstreetmap/josm/gui/MainApplication.java
    index 2d562c8..4abcbe5 100644
    a b public class MainApplication extends Main {  
    100100
    101101    @Override
    102102    protected void initializeMainWindow() {
     103        mainPanel.reAddListeners();
    103104        if (mainFrame != null) {
    104105            mainFrame.initialize();
    105106
    public class MainApplication extends Main {  
    409410                !args.containsKey(Option.NO_MAXIMIZE) && Main.pref.getBoolean("gui.maximized", false));
    410411        final MainFrame mainFrame = new MainFrame(contentPanePrivate, mainPanel, geometry);
    411412        Main.parent = mainFrame;
    412         mainPanel.reAddListeners();
    413413
    414414        if (args.containsKey(Option.LOAD_PREFERENCES)) {
    415415            CustomConfigurator.XMLCommandProcessor config = new CustomConfigurator.XMLCommandProcessor(Main.pref);
  • src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java b/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
    index c7b9ade..22c2589 100644
    a b public class LayerListDialog extends ToggleDialog {  
    175175     * Creates a layer list and attach it to the given mapView.
    176176     * @param layerManager The layer manager this list is for
    177177     */
    178     private LayerListDialog(MainLayerManager layerManager) {
     178    public LayerListDialog(MainLayerManager layerManager) {
    179179        super(tr("Layers"), "layerlist", tr("Open a list of all loaded layers."),
    180180                Shortcut.registerShortcut("subwindow:layers", tr("Toggle: {0}", tr("Layers")), KeyEvent.VK_L,
    181181                        Shortcut.ALT_SHIFT), 100, true);
  • src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java b/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
    index 04eea4b..cc9997a 100644
    a b public class ToggleDialog extends JPanel implements ShowHideButtonListener, Help  
    256256        Main.redirectToMainContentPane(this);
    257257        Main.pref.addPreferenceChangeListener(this);
    258258
     259        registerInWindowMenu();
     260    }
     261
     262    /**
     263     * Registers this dialog in the window menu. Called in the constructor.
     264     */
     265    protected void registerInWindowMenu() {
    259266        windowMenuItem = MainMenu.addWithCheckbox(Main.main.menu.windowMenu,
    260267                (JosmAction) getToggleAction(),
    261268                MainMenu.WINDOW_MENU_GROUP.TOGGLE_DIALOG);
  • src/org/openstreetmap/josm/gui/layer/ImageryLayer.java

    diff --git a/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java b/src/org/openstreetmap/josm/gui/layer/ImageryLayer.java
    index be0bcd5..4a6d290 100644
    a b public abstract class ImageryLayer extends Layer {  
    116116        return dy;
    117117    }
    118118
     119    /**
     120     * Sets the displacement offset of this layer. The layer is automatically invalidated.
     121     * @param dx The x offset
     122     * @param dy The y offset
     123     */
    119124    public void setOffset(double dx, double dy) {
    120125        this.dx = dx;
    121126        this.dy = dy;
     127        invalidate();
    122128    }
    123129
    124130    public void displace(double dx, double dy) {
  • src/org/openstreetmap/josm/gui/layer/LayerManager.java

    diff --git a/src/org/openstreetmap/josm/gui/layer/LayerManager.java b/src/org/openstreetmap/josm/gui/layer/LayerManager.java
    index 352df56..e7ee59e 100644
    a b import java.util.Collections;  
    66import java.util.List;
    77import java.util.concurrent.CopyOnWriteArrayList;
    88
     9import org.openstreetmap.josm.Main;
    910import org.openstreetmap.josm.gui.util.GuiHelper;
    1011import org.openstreetmap.josm.tools.Utils;
    1112import org.openstreetmap.josm.tools.bugreport.BugReport;
    public class LayerManager {  
    174175        checkPosition(position);
    175176        insertLayerAt(layer, position);
    176177        fireLayerAdded(layer);
    177         layer.hookUpMapView(); // needs to be after fireLayerAdded
     178        if (Main.map != null) {
     179            layer.hookUpMapView(); // needs to be after fireLayerAdded
     180        }
    178181    }
    179182
    180183    /**
  • src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java

    diff --git a/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java b/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
    index 747df2b..6bcfb13 100644
    a b public class OsmDataLayer extends AbstractModifiableLayer implements Listener, S  
    877877    public void onPostLoadFromFile() {
    878878        setRequiresSaveToFile(false);
    879879        setRequiresUploadToServer(isModified());
     880        invalidate();
    880881    }
    881882
    882883    /**
    public class OsmDataLayer extends AbstractModifiableLayer implements Listener, S  
    885886    public void onPostDownloadFromServer() {
    886887        setRequiresSaveToFile(true);
    887888        setRequiresUploadToServer(isModified());
     889        invalidate();
    888890    }
    889891
    890892    @Override
  • test/unit/org/openstreetmap/josm/JOSMFixture.java

    diff --git a/test/unit/org/openstreetmap/josm/JOSMFixture.java b/test/unit/org/openstreetmap/josm/JOSMFixture.java
    index 51fb2dc..b8f3d28 100644
    a b import java.nio.file.Paths;  
    1111import java.security.GeneralSecurityException;
    1212import java.text.MessageFormat;
    1313import java.util.Locale;
     14import java.util.TimeZone;
    1415
    1516import org.openstreetmap.josm.data.projection.Projections;
    1617import org.openstreetmap.josm.gui.MainApplication;
     18import org.openstreetmap.josm.gui.layer.LayerManagerTest.TestLayer;
    1719import org.openstreetmap.josm.gui.preferences.ToolbarPreferences;
    1820import org.openstreetmap.josm.gui.util.GuiHelper;
    1921import org.openstreetmap.josm.io.CertificateAmendment;
    public class JOSMFixture {  
    8789            }
    8890        }
    8991        System.setProperty("josm.home", josmHome);
     92        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
    9093        Main.initApplicationPreferences();
    9194        Main.pref.enableSaveOnPut(false);
    9295        I18n.init();
    public class JOSMFixture {  
    9598        // call the really early hook before we anything else
    9699        Main.platform.preStartupHook();
    97100
     101        Main.logLevel = 3;
    98102        Main.pref.init(false);
    99103        Main.pref.put("osm-server.url", "http://api06.dev.openstreetmap.org/api");
    100104        I18n.set(Main.pref.get("language", "en"));
    public class JOSMFixture {  
    127131    }
    128132
    129133    private void setupGUI() {
     134        Main.getLayerManager().resetState();
     135        assertTrue(Main.getLayerManager().getLayers().isEmpty());
     136        assertNull(Main.getLayerManager().getEditLayer());
     137        assertNull(Main.getLayerManager().getActiveLayer());
     138
    130139        if (Main.toolbar == null) {
    131140            Main.toolbar = new ToolbarPreferences();
    132141        }
    133142        if (Main.main == null) {
    134143            new MainApplication().initialize();
    135144        }
    136         Main.getLayerManager().resetState();
    137         assertTrue(Main.getLayerManager().getLayers().isEmpty());
    138         assertNull(Main.getLayerManager().getEditLayer());
    139         assertNull(Main.getLayerManager().getActiveLayer());
     145        // Add a test layer to the layer manager to get the MapFrame
     146        Main.getLayerManager().addLayer(new TestLayer());
    140147    }
    141148}
  • test/unit/org/openstreetmap/josm/data/AutosaveTaskTest.java

    diff --git a/test/unit/org/openstreetmap/josm/data/AutosaveTaskTest.java b/test/unit/org/openstreetmap/josm/data/AutosaveTaskTest.java
    index 28faf26..ce6b72c 100644
    a b public class AutosaveTaskTest {  
    9191        cal.set(Calendar.MILLISECOND, 456);
    9292        Date fixed = cal.getTime();
    9393
    94         for (int i = 0; i <= AutosaveTask.PROP_INDEX_LIMIT.get() + 1; i++) {
     94        AutosaveTask.PROP_INDEX_LIMIT.put(5);
     95        for (int i = 0; i <= AutosaveTask.PROP_INDEX_LIMIT.get() + 2; i++) {
    9596            // Only retry 2 indexes to avoid 1000*1000 disk operations
    9697            File f = task.getNewLayerFile(info, fixed, Math.max(0, i - 2));
    9798            if (i > AutosaveTask.PROP_INDEX_LIMIT.get()) {
  • test/unit/org/openstreetmap/josm/data/PreferencesTest.groovy

    diff --git a/test/unit/org/openstreetmap/josm/data/PreferencesTest.groovy b/test/unit/org/openstreetmap/josm/data/PreferencesTest.groovy
    index 7046cec..dcccb2e 100644
    a b class PreferencesTest extends GroovyTestCase {  
    3636            "  <tag key='jdk.Arrays.useLegacyMergeSort' value='false'/>%n" +
    3737            "  <tag key='language' value='en'/>%n" +
    3838            "  <tag key='osm-server.url' value='http://api06.dev.openstreetmap.org/api'/>%n" +
    39             "  <tag key='osm-server.username' value='josm_test'/>%n" +
    40             "</preferences>%n", Version.getInstance().getVersion())
     39            "  <tag key='osm-server.username' value='%s'/>%n" +
     40            "</preferences>%n", Version.getInstance().getVersion(), Main.pref.get("osm-server.username"))
    4141    }
    4242}
  • test/unit/org/openstreetmap/josm/data/validation/tests/OpeningHourTestTest.java

    diff --git a/test/unit/org/openstreetmap/josm/data/validation/tests/OpeningHourTestTest.java b/test/unit/org/openstreetmap/josm/data/validation/tests/OpeningHourTestTest.java
    index 0ccfab7..1b97917 100644
    a b import java.util.List;  
    1616import java.util.Set;
    1717
    1818import org.junit.Before;
     19import org.junit.Rule;
    1920import org.junit.Test;
    20 import org.openstreetmap.josm.JOSMFixture;
    2121import org.openstreetmap.josm.data.osm.Tag;
    2222import org.openstreetmap.josm.data.validation.Severity;
    2323import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset;
    2424import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem;
    2525import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetReader;
    2626import org.openstreetmap.josm.gui.tagging.presets.items.KeyedItem;
     27import org.openstreetmap.josm.testutils.JOSMTestRules;
     28
     29import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2730
    2831/**
    2932 * JUnit Test of "Opening hours" validation test.
     33 * @see OpeningHourTest
    3034 */
    3135public class OpeningHourTestTest {
     36    /**
     37     * We need prefs for this. We check strings so we need i18n.
     38     */
     39    @Rule
     40    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     41    public JOSMTestRules test = new JOSMTestRules().preferences().i18n();
    3242
    33     private static final OpeningHourTest OPENING_HOUR_TEST = new OpeningHourTest();
     43    private OpeningHourTest openingHourTest;
    3444
    3545    /**
    3646     * Setup test.
    public class OpeningHourTestTest {  
    3848     */
    3949    @Before
    4050    public void setUp() throws Exception {
    41         JOSMFixture.createUnitTestFixture().init();
    42         OPENING_HOUR_TEST.initialize();
     51        openingHourTest = new OpeningHourTest();
     52        openingHourTest.initialize();
    4353    }
    4454
    4555    /**
    public class OpeningHourTestTest {  
    4959    public void testCheckOpeningHourSyntax1() {
    5060        final String key = "opening_hours";
    5161        // frequently used tags according to https://taginfo.openstreetmap.org/keys/opening_hours#values
    52         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "24/7"), isEmpty());
    53         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 08:30-20:00"), isEmpty());
    54         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr sunrise-sunset"), isEmpty());
    55         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "09:00-21:00"), isEmpty());
    56         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su-Th sunset-24:00,04:00-sunrise; Fr-Sa sunset-sunrise"), isEmpty());
    57         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise"), hasSize(1));
    58         assertEquals(Severity.OTHER, OPENING_HOUR_TEST.checkOpeningHourSyntax(
     62        assertThat(openingHourTest.checkOpeningHourSyntax(key, "24/7"), isEmpty());
     63        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 08:30-20:00"), isEmpty());
     64        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr sunrise-sunset"), isEmpty());
     65        assertThat(openingHourTest.checkOpeningHourSyntax(key, "09:00-21:00"), isEmpty());
     66        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Su-Th sunset-24:00,04:00-sunrise; Fr-Sa sunset-sunrise"), isEmpty());
     67        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise"), hasSize(1));
     68        assertEquals(Severity.OTHER, openingHourTest.checkOpeningHourSyntax(
    5969                key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise").get(0).getSeverity());
    60         assertEquals("Su-Th sunset-24:00,04:00-sunrise; Fr-Sa sunset-sunrise", OPENING_HOUR_TEST.checkOpeningHourSyntax(
     70        assertEquals("Su-Th sunset-24:00,04:00-sunrise; Fr-Sa sunset-sunrise", openingHourTest.checkOpeningHourSyntax(
    6171                key, "Su-Th sunset-24:00, 04:00-sunrise; Fr-Sa sunset-sunrise").get(0).getPrettifiedValue());
    6272    }
    6373
    6474    @Test
    6575    public void testI18n() {
    66         assertTrue(OPENING_HOUR_TEST.checkOpeningHourSyntax("opening_hours", ".", OpeningHourTest.CheckMode.POINTS_IN_TIME, false, "de")
     76        assertTrue(openingHourTest.checkOpeningHourSyntax("opening_hours", ".", OpeningHourTest.CheckMode.POINTS_IN_TIME, false, "de")
    6777                .get(0).toString().contains("Unerwartetes Zeichen"));
    68         assertFalse(OPENING_HOUR_TEST.checkOpeningHourSyntax("opening_hours", ".", OpeningHourTest.CheckMode.POINTS_IN_TIME, false, "en")
     78        assertFalse(openingHourTest.checkOpeningHourSyntax("opening_hours", ".", OpeningHourTest.CheckMode.POINTS_IN_TIME, false, "en")
    6979                .get(0).toString().contains("Unerwartetes Zeichen"));
    7080    }
    7181
    public class OpeningHourTestTest {  
    7585    @Test
    7686    public void testCheckOpeningHourSyntax2() {
    7787        final String key = "opening_hours";
    78         final List<OpeningHourTest.OpeningHoursTestError> errors = OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Tue");
     88        final List<OpeningHourTest.OpeningHoursTestError> errors = openingHourTest.checkOpeningHourSyntax(key, "Mo-Tue");
    7989        assertThat(errors, hasSize(2));
    8090        assertEquals(key + " - Mo-Tue <--- (Please use the abbreviation \"Tu\" for \"tue\".)", errors.get(0).getMessage());
    8191        assertEquals(Severity.WARNING, errors.get(0).getSeverity());
    public class OpeningHourTestTest {  
    91101    @Test
    92102    public void testCheckOpeningHourSyntax3() {
    93103        final String key = "opening_hours";
    94         final List<OpeningHourTest.OpeningHoursTestError> errors = OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Sa-Su 10.00-20.00");
     104        final List<OpeningHourTest.OpeningHoursTestError> errors = openingHourTest.checkOpeningHourSyntax(key, "Sa-Su 10.00-20.00");
    95105        assertThat(errors, hasSize(2));
    96106        assertEquals(key + " - Sa-Su 10. <--- (Please use \":\" as hour/minute-separator)", errors.get(0).getMessage());
    97107        assertEquals(Severity.WARNING, errors.get(0).getSeverity());
    public class OpeningHourTestTest {  
    105115     */
    106116    @Test
    107117    public void testCheckOpeningHourSyntax4() {
    108         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(null, null), isEmpty());
    109         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(null, ""), isEmpty());
    110         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(null, " "), isEmpty());
     118        assertThat(openingHourTest.checkOpeningHourSyntax(null, null), isEmpty());
     119        assertThat(openingHourTest.checkOpeningHourSyntax(null, ""), isEmpty());
     120        assertThat(openingHourTest.checkOpeningHourSyntax(null, " "), isEmpty());
    111121    }
    112122
    113123    /**
    public class OpeningHourTestTest {  
    116126    @Test
    117127    public void testCheckOpeningHourSyntax5() {
    118128        final String key = "opening_hours";
    119         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "badtext"), hasSize(1));
     129        assertThat(openingHourTest.checkOpeningHourSyntax(key, "badtext"), hasSize(1));
    120130        assertEquals(key + " - ba <--- (Unexpected token: \"b\" Invalid/unsupported syntax.)",
    121                 OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "badtext").get(0).getMessage());
    122         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m"), hasSize(1));
     131                openingHourTest.checkOpeningHourSyntax(key, "badtext").get(0).getMessage());
     132        assertThat(openingHourTest.checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m"), hasSize(1));
    123133        assertEquals(key + " - 5.00 p <--- (hyphen (-) or open end (+) in time range expected. "
    124134                + "For working with points in time, the mode for opening_hours.js has to be altered. Maybe wrong tag?)",
    125                 OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m").get(0).getMessage());
     135                openingHourTest.checkOpeningHourSyntax(key, "5.00 p.m-11.00 p.m").get(0).getMessage());
    126136    }
    127137
    128138    /**
    public class OpeningHourTestTest {  
    131141    @Test
    132142    public void testCheckOpeningHourSyntax6() {
    133143        final String key = "opening_hours";
    134         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "PH open \"always open on public holidays\""), isEmpty());
     144        assertThat(openingHourTest.checkOpeningHourSyntax(key, "PH open \"always open on public holidays\""), isEmpty());
    135145    }
    136146
    137147    /**
    public class OpeningHourTestTest {  
    140150    @Test
    141151    public void testCheckOpeningHourSyntax7() {
    142152        final String key = "opening_hours";
    143         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "9:00-18:00"), hasSize(1));
    144         assertEquals(Severity.OTHER, OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "9:00-18:00").get(0).getSeverity());
    145         assertEquals("09:00-18:00", OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "9:00-18:00").get(0).getPrettifiedValue());
     153        assertThat(openingHourTest.checkOpeningHourSyntax(key, "9:00-18:00"), hasSize(1));
     154        assertEquals(Severity.OTHER, openingHourTest.checkOpeningHourSyntax(key, "9:00-18:00").get(0).getSeverity());
     155        assertEquals("09:00-18:00", openingHourTest.checkOpeningHourSyntax(key, "9:00-18:00").get(0).getPrettifiedValue());
    146156    }
    147157
    148158    /**
    public class OpeningHourTestTest {  
    151161    @Test
    152162    public void testCheckOpeningHourSyntaxTicket9367() {
    153163        final String key = "opening_hours";
    154         assertEquals(Severity.WARNING, OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getSeverity());
     164        assertEquals(Severity.WARNING, openingHourTest.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getSeverity());
    155165        assertEquals(key + " - Mo,Tu 04-17 <--- (Time range without minutes specified. "
    156166                + "Not very explicit! Please use this syntax instead \"04:00-17:00\".)",
    157                 OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getMessage());
    158         assertEquals("Mo,Tu 04:00-17:00", OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getPrettifiedValue());
     167                openingHourTest.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getMessage());
     168        assertEquals("Mo,Tu 04:00-17:00", openingHourTest.checkOpeningHourSyntax(key, "Mo,Tu 04-17").get(0).getPrettifiedValue());
    159169    }
    160170
    161171    /**
    public class OpeningHourTestTest {  
    165175    public void testCheckServiceTimeSyntax1() {
    166176        final String key = "service_times";
    167177        // frequently used tags according to https://taginfo.openstreetmap.org/keys/service_times#values
    168         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su 10:00", OpeningHourTest.CheckMode.BOTH), isEmpty());
    169         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "automatic", OpeningHourTest.CheckMode.BOTH), not(isEmpty()));
    170         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Sa 09:00-18:00", OpeningHourTest.CheckMode.BOTH), isEmpty());
    171         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Su 09:30; We 19:30", OpeningHourTest.CheckMode.BOTH), isEmpty());
    172         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00",
     178        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Su 10:00", OpeningHourTest.CheckMode.BOTH), isEmpty());
     179        assertThat(openingHourTest.checkOpeningHourSyntax(key, "automatic", OpeningHourTest.CheckMode.BOTH), not(isEmpty()));
     180        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Mo-Sa 09:00-18:00", OpeningHourTest.CheckMode.BOTH), isEmpty());
     181        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Su 09:30; We 19:30", OpeningHourTest.CheckMode.BOTH), isEmpty());
     182        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00",
    173183                OpeningHourTest.CheckMode.BOTH), isEmpty());
    174         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00",
     184        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00",
    175185                OpeningHourTest.CheckMode.BOTH), hasSize(1));
    176186        assertEquals("Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00",
    177                 OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00",
     187                openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00",
    178188                OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue());
    179189        assertEquals("Mo-Fr 00:00-00:30,04:00-00:30; Sa,Su,PH 00:00-24:00",
    180                 OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00",
     190                openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 0:00-0:30,4:00-00:30; Sa,Su,PH 0:00-24:00",
    181191                OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue());
    182192    }
    183193
    public class OpeningHourTestTest {  
    188198    public void testCheckCollectionTimeSyntax1() {
    189199        final String key = "collection_times";
    190200        // frequently used tags according to https://taginfo.openstreetmap.org/keys/collection_times#values
    191         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Sa 09:00", OpeningHourTest.CheckMode.BOTH), isEmpty());
    192         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "fixme", OpeningHourTest.CheckMode.BOTH), not(isEmpty()));
    193         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "daily", OpeningHourTest.CheckMode.BOTH), not(isEmpty()));
    194         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30,17:45,19:00; Sa 15:00; Su 11:00",
     201        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Mo-Sa 09:00", OpeningHourTest.CheckMode.BOTH), isEmpty());
     202        assertThat(openingHourTest.checkOpeningHourSyntax(key, "fixme", OpeningHourTest.CheckMode.BOTH), not(isEmpty()));
     203        assertThat(openingHourTest.checkOpeningHourSyntax(key, "daily", OpeningHourTest.CheckMode.BOTH), not(isEmpty()));
     204        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 13:30,17:45,19:00; Sa 15:00; Su 11:00",
    195205                OpeningHourTest.CheckMode.BOTH), isEmpty());
    196         assertThat(OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00",
     206        assertThat(openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00",
    197207                OpeningHourTest.CheckMode.BOTH), hasSize(1));
    198208        assertEquals(Severity.OTHER,
    199                 OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00",
     209                openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00",
    200210                OpeningHourTest.CheckMode.BOTH).get(0).getSeverity());
    201211        assertEquals("Mo-Fr 13:30,17:45,19:00; Sa 15:00; Su 11:00",
    202                 OPENING_HOUR_TEST.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00",
     212                openingHourTest.checkOpeningHourSyntax(key, "Mo-Fr 13:30, 17:45, 19:00; Sa 15:00; Su 11:00",
    203213                OpeningHourTest.CheckMode.BOTH).get(0).getPrettifiedValue());
    204214    }
    205215
    public class OpeningHourTestTest {  
    221231            }
    222232        }
    223233        for (final Tag t : values) {
    224             final List<OpeningHourTest.OpeningHoursTestError> errors = OPENING_HOUR_TEST.checkOpeningHourSyntax(t.getKey(), t.getValue());
     234            final List<OpeningHourTest.OpeningHoursTestError> errors = openingHourTest.checkOpeningHourSyntax(t.getKey(), t.getValue());
    225235            assertThat(t + " is valid", errors, isEmpty());
    226236        }
    227237    }
  • test/unit/org/openstreetmap/josm/gui/dialogs/layer/LayerVisibilityActionTest.java

    diff --git a/test/unit/org/openstreetmap/josm/gui/dialogs/layer/LayerVisibilityActionTest.java b/test/unit/org/openstreetmap/josm/gui/dialogs/layer/LayerVisibilityActionTest.java
    index 8f94ad6..36ff653 100644
    a b import static org.junit.Assert.assertEquals;  
    55import static org.junit.Assert.assertFalse;
    66import static org.junit.Assert.assertTrue;
    77
    8 import org.junit.BeforeClass;
     8import org.junit.Rule;
    99import org.junit.Test;
    10 import org.openstreetmap.josm.JOSMFixture;
    1110import org.openstreetmap.josm.Main;
    1211import org.openstreetmap.josm.gui.dialogs.LayerListDialog;
    1312import org.openstreetmap.josm.gui.dialogs.LayerListDialog.LayerListModel;
    1413import org.openstreetmap.josm.gui.layer.TMSLayer;
    1514import org.openstreetmap.josm.gui.layer.TMSLayerTest;
     15import org.openstreetmap.josm.testutils.JOSMTestRules;
     16
     17import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1618
    1719/**
    1820 * Unit tests of {@link LayerVisibilityAction} class.
    1921 */
    2022public class LayerVisibilityActionTest {
    21 
    2223    /**
    23      * Setup tests
     24     * TMS layer needs prefs. Platform for LayerListDialog shortcuts.
    2425     */
    25     @BeforeClass
    26     public static void setUpBeforeClass() {
    27         JOSMFixture.createUnitTestFixture().init(true);
    28     }
     26    @Rule
     27    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     28    public JOSMTestRules test = new JOSMTestRules().preferences().projection().platform();
    2929
    3030    /**
    3131     * Unit test of {@link LayerVisibilityAction} class.
    public class LayerVisibilityActionTest {  
    3333    @Test
    3434    public void testLayerVisibilityAction() {
    3535        TMSLayer layer = TMSLayerTest.createTmsLayer();
    36         try {
    37             LayerListModel model = LayerListDialog.getInstance().getModel();
    38             LayerVisibilityAction action = new LayerVisibilityAction(model);
    39             action.updateEnabledState();
    40             assertFalse(action.isEnabled());
    41 
    42             Main.getLayerManager().addLayer(layer);
    43             action.updateEnabledState();
    44             assertTrue(action.isEnabled());
    45             assertTrue(action.supportLayers(model.getSelectedLayers()));
     36        LayerListModel model = new LayerListDialog(Main.getLayerManager()) {
     37            @Override
     38            protected void registerInWindowMenu() {
     39                // ignore
     40            }
     41        }.getModel();
     42        LayerVisibilityAction action = new LayerVisibilityAction(model);
     43        action.updateEnabledState();
     44        assertFalse(action.isEnabled());
    4645
    47             // now check values
    48             action.updateValues();
    49             assertEquals(1.0, action.opacitySlider.getRealValue(), 1e-15);
    50             assertEquals("OpacitySlider [getRealValue()=1.0]", action.opacitySlider.toString());
     46        Main.getLayerManager().addLayer(layer);
     47        model.setSelectedLayer(layer);
     48        action.updateEnabledState();
     49        assertTrue(action.isEnabled());
     50        assertTrue(action.supportLayers(model.getSelectedLayers()));
    5151
    52             action.opacitySlider.setRealValue(.5);
    53             action.updateValues();
     52        // now check values
     53        action.updateValues();
     54        assertEquals(1.0, action.opacitySlider.getRealValue(), 1e-15);
     55        assertEquals("OpacitySlider [getRealValue()=1.0]", action.opacitySlider.toString());
    5456
    55             assertEquals(0.5, action.opacitySlider.getRealValue(), 1e-15);
    56             assertEquals("OpacitySlider [getRealValue()=0.5]", action.opacitySlider.toString());
     57        action.opacitySlider.setRealValue(.5);
     58        action.updateValues();
    5759
    58             action.setVisibleFlag(false);
    59             action.updateValues();
    60             assertFalse(layer.isVisible());
     60        assertEquals(0.5, action.opacitySlider.getRealValue(), 1e-15);
     61        assertEquals("OpacitySlider [getRealValue()=0.5]", action.opacitySlider.toString());
    6162
    62             action.setVisibleFlag(true);
    63             action.updateValues();
    64             assertTrue(layer.isVisible());
     63        action.setVisibleFlag(false);
     64        action.updateValues();
     65        assertFalse(layer.isVisible());
    6566
    66             // layer stays visible during adjust
    67             action.opacitySlider.setValueIsAdjusting(true);
    68             action.opacitySlider.setRealValue(0);
    69             assertEquals(0, layer.getOpacity(), 1e-15);
    70             layer.setOpacity(.1); // to make layer.isVisible work
    71             assertTrue(layer.isVisible());
    72             layer.setOpacity(0);
     67        action.setVisibleFlag(true);
     68        action.updateValues();
     69        assertTrue(layer.isVisible());
    7370
    74             action.opacitySlider.setValueIsAdjusting(false);
    75             action.opacitySlider.setRealValue(0);
    76             assertEquals(0, layer.getOpacity(), 1e-15);
    77             layer.setOpacity(.1); // to make layer.isVisible work
    78             assertFalse(layer.isVisible());
    79             layer.setOpacity(0);
    80             action.updateValues();
     71        // layer stays visible during adjust
     72        action.opacitySlider.setValueIsAdjusting(true);
     73        action.opacitySlider.setRealValue(0);
     74        assertEquals(0, layer.getOpacity(), 1e-15);
     75        layer.setOpacity(.1); // to make layer.isVisible work
     76        assertTrue(layer.isVisible());
     77        layer.setOpacity(0);
    8178
    82             // Opacity reset when it was 0 and user set layer to visible.
    83             action.setVisibleFlag(true);
    84             action.updateValues();
    85             assertEquals(1.0, action.opacitySlider.getRealValue(), 1e-15);
    86             assertEquals(1.0, layer.getOpacity(), 1e-15);
     79        action.opacitySlider.setValueIsAdjusting(false);
     80        action.opacitySlider.setRealValue(0);
     81        assertEquals(0, layer.getOpacity(), 1e-15);
     82        layer.setOpacity(.1); // to make layer.isVisible work
     83        assertFalse(layer.isVisible());
     84        layer.setOpacity(0);
     85        action.updateValues();
    8786
    88         } finally {
    89             Main.getLayerManager().removeLayer(layer);
    90         }
     87        // Opacity reset when it was 0 and user set layer to visible.
     88        action.setVisibleFlag(true);
     89        action.updateValues();
     90        assertEquals(1.0, action.opacitySlider.getRealValue(), 1e-15);
     91        assertEquals(1.0, layer.getOpacity(), 1e-15);
    9192    }
    9293}
  • test/unit/org/openstreetmap/josm/gui/layer/GpxLayerTest.java

    diff --git a/test/unit/org/openstreetmap/josm/gui/layer/GpxLayerTest.java b/test/unit/org/openstreetmap/josm/gui/layer/GpxLayerTest.java
    index 4f7b522..1d8acb0 100644
    a b import java.io.IOException;  
    1010import java.util.ArrayList;
    1111import java.util.Collection;
    1212import java.util.HashMap;
     13import java.util.TimeZone;
    1314
    1415import javax.swing.JScrollPane;
    1516
    public class GpxLayerTest {  
    170171        assertEquals("", GpxLayer.getTimespanForTrack(
    171172                new ImmutableGpxTrack(new ArrayList<Collection<WayPoint>>(), new HashMap<String, Object>())));
    172173
     174        assertEquals("1/3/16 11:59 AM - 12:00 PM (0:00)", GpxLayer.getTimespanForTrack(getMinimalGpxData().tracks.iterator().next()));
     175
     176        TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
    173177        assertEquals("1/3/16 12:59 PM - 1:00 PM (0:00)", GpxLayer.getTimespanForTrack(getMinimalGpxData().tracks.iterator().next()));
    174178    }
    175179
  • test/unit/org/openstreetmap/josm/gui/layer/LayerManagerTest.java

    diff --git a/test/unit/org/openstreetmap/josm/gui/layer/LayerManagerTest.java b/test/unit/org/openstreetmap/josm/gui/layer/LayerManagerTest.java
    index 96c8be9..505b48b 100644
    a b import static org.junit.Assert.assertSame;  
    1010import static org.junit.Assert.assertTrue;
    1111import static org.junit.Assert.fail;
    1212
     13import java.awt.Component;
     14import java.awt.Graphics;
    1315import java.awt.Graphics2D;
    1416import java.lang.reflect.InvocationTargetException;
    1517import java.util.ArrayList;
    import org.openstreetmap.josm.tools.bugreport.ReportedException;  
    4042 */
    4143public class LayerManagerTest {
    4244
    43     protected static class AbstractTestLayer extends Layer {
    44         protected AbstractTestLayer() {
     45    /**
     46     * This is a layer that can be used in tests. It does not do anything and provides a simple, fake implementation.
     47     * @author Michael Zangl
     48     * @since xxx
     49     */
     50    public static class TestLayer extends Layer {
     51        /**
     52         * Create a new test layer.
     53         */
     54        public TestLayer() {
    4555            super("Test Layer");
    4656        }
    4757
    public class LayerManagerTest {  
    6979
    7080        @Override
    7181        public Action[] getMenuEntries() {
    72             return null;
     82            return new Action[0];
    7383        }
    7484
    7585        @Override
    public class LayerManagerTest {  
    7989
    8090        @Override
    8191        public Icon getIcon() {
    82             return null;
     92            return new Icon() {
     93                @Override
     94                public void paintIcon(Component c, Graphics g, int x, int y) {
     95                    // nop
     96                }
     97
     98                @Override
     99                public int getIconWidth() {
     100                    return 10;
     101                }
     102
     103                @Override
     104                public int getIconHeight() {
     105                    return 10;
     106                }
     107            };
    83108        }
    84109
    85110        @Override
    public class LayerManagerTest {  
    88113        }
    89114    }
    90115
    91     protected static class AbstractTestLayer2 extends AbstractTestLayer {}
     116    protected static class TestLayer2 extends TestLayer {}
    92117
    93118    /**
    94119     * Intercepts the events for easier testing.
    public class LayerManagerTest {  
    146171     */
    147172    @Test
    148173    public void testAddLayer() {
    149         Layer layer1 = new AbstractTestLayer() {
     174        Layer layer1 = new TestLayer() {
    150175            @Override
    151176            public LayerPositionStrategy getDefaultLayerPosition() {
    152177                return LayerPositionStrategy.IN_FRONT;
    public class LayerManagerTest {  
    157182                return true;
    158183            }
    159184        };
    160         Layer layer2 = new AbstractTestLayer() {
     185        Layer layer2 = new TestLayer() {
    161186            @Override
    162187            public LayerPositionStrategy getDefaultLayerPosition() {
    163188                return LayerPositionStrategy.IN_FRONT;
    164189            }
    165190        };
    166         Layer layer3 = new AbstractTestLayer() {
     191        Layer layer3 = new TestLayer() {
    167192            @Override
    168193            public LayerPositionStrategy getDefaultLayerPosition() {
    169194                return LayerPositionStrategy.BEFORE_FIRST_BACKGROUND_LAYER;
    public class LayerManagerTest {  
    178203        assertEquals(layerManager.getLayers(), Arrays.asList(layer2, layer3, layer1));
    179204
    180205        // event
    181         AbstractTestLayer layer4 = new AbstractTestLayer();
     206        TestLayer layer4 = new TestLayer();
    182207        CapturingLayerChangeListener l = new CapturingLayerChangeListener();
    183208        layerManager.addLayerChangeListener(l);
    184209        layerManager.addLayer(layer4);
    public class LayerManagerTest {  
    197222        thrown.expectCause(any(InvocationTargetException.class));
    198223        thrown.expectRootCause(any(IllegalArgumentException.class));
    199224
    200         AbstractTestLayer layer1 = new AbstractTestLayer();
     225        TestLayer layer1 = new TestLayer();
    201226        layerManager.addLayer(layer1);
    202227        layerManager.addLayer(layer1);
    203228    }
    public class LayerManagerTest {  
    211236        thrown.expectCause(any(InvocationTargetException.class));
    212237        thrown.expectRootCause(any(IndexOutOfBoundsException.class));
    213238
    214         AbstractTestLayer layer1 = new AbstractTestLayer() {
     239        TestLayer layer1 = new TestLayer() {
    215240            @Override
    216241            public LayerPositionStrategy getDefaultLayerPosition() {
    217242                return new LayerPositionStrategy() {
    public class LayerManagerTest {  
    230255     */
    231256    @Test
    232257    public void testRemoveLayer() {
    233         AbstractTestLayer layer1 = new AbstractTestLayer();
    234         AbstractTestLayer layer2 = new AbstractTestLayer();
     258        TestLayer layer1 = new TestLayer();
     259        TestLayer layer2 = new TestLayer();
    235260        layerManager.addLayer(layer1);
    236261        layerManager.addLayer(layer2);
    237262        assertEquals(layerManager.getLayers(), Arrays.asList(layer1, layer2));
    public class LayerManagerTest {  
    251276     */
    252277    @Test
    253278    public void testMoveLayer() {
    254         AbstractTestLayer layer1 = new AbstractTestLayer();
    255         AbstractTestLayer layer2 = new AbstractTestLayer();
     279        TestLayer layer1 = new TestLayer();
     280        TestLayer layer2 = new TestLayer();
    256281        layerManager.addLayer(layer1);
    257282        layerManager.addLayer(layer2);
    258283        assertEquals(layerManager.getLayers(), Arrays.asList(layer1, layer2));
    public class LayerManagerTest {  
    283308        thrown.expectCause(any(InvocationTargetException.class));
    284309        thrown.expectRootCause(any(IndexOutOfBoundsException.class));
    285310
    286         AbstractTestLayer layer1 = new AbstractTestLayer();
    287         AbstractTestLayer layer2 = new AbstractTestLayer();
     311        TestLayer layer1 = new TestLayer();
     312        TestLayer layer2 = new TestLayer();
    288313        layerManager.addLayer(layer1);
    289314        layerManager.addLayer(layer2);
    290315        layerManager.moveLayer(layer2, 2);
    public class LayerManagerTest {  
    299324        thrown.expectCause(any(InvocationTargetException.class));
    300325        thrown.expectRootCause(any(IllegalArgumentException.class));
    301326
    302         AbstractTestLayer layer1 = new AbstractTestLayer();
    303         AbstractTestLayer layer2 = new AbstractTestLayer();
     327        TestLayer layer1 = new TestLayer();
     328        TestLayer layer2 = new TestLayer();
    304329        layerManager.addLayer(layer1);
    305330        layerManager.moveLayer(layer2, 0);
    306331    }
    public class LayerManagerTest {  
    311336    @Test(expected = UnsupportedOperationException.class)
    312337    public void testGetLayers() {
    313338        // list should be immutable
    314         AbstractTestLayer layer1 = new AbstractTestLayer();
    315         AbstractTestLayer layer2 = new AbstractTestLayer();
     339        TestLayer layer1 = new TestLayer();
     340        TestLayer layer2 = new TestLayer();
    316341        layerManager.addLayer(layer1);
    317342        layerManager.addLayer(layer2);
    318343        layerManager.getLayers().remove(0);
    public class LayerManagerTest {  
    323348     */
    324349    @Test
    325350    public void testGetLayersOfType() {
    326         AbstractTestLayer2 layer1 = new AbstractTestLayer2();
    327         AbstractTestLayer2 layer2 = new AbstractTestLayer2();
     351        TestLayer2 layer1 = new TestLayer2();
     352        TestLayer2 layer2 = new TestLayer2();
    328353        layerManager.addLayer(layer1);
    329         layerManager.addLayer(new AbstractTestLayer());
     354        layerManager.addLayer(new TestLayer());
    330355        layerManager.addLayer(layer2);
    331356
    332         assertEquals(layerManager.getLayersOfType(AbstractTestLayer2.class), Arrays.asList(layer1, layer2));
     357        assertEquals(layerManager.getLayersOfType(TestLayer2.class), Arrays.asList(layer1, layer2));
    333358    }
    334359
    335360    /**
    public class LayerManagerTest {  
    337362     */
    338363    @Test
    339364    public void testContainsLayer() {
    340         AbstractTestLayer layer = new AbstractTestLayer();
     365        TestLayer layer = new TestLayer();
    341366        layerManager.addLayer(layer);
    342         layerManager.addLayer(new AbstractTestLayer());
     367        layerManager.addLayer(new TestLayer());
    343368
    344369        assertTrue(layerManager.containsLayer(layer));
    345         assertFalse(layerManager.containsLayer(new AbstractTestLayer()));
     370        assertFalse(layerManager.containsLayer(new TestLayer()));
    346371    }
    347372
    348373    /**
    public class LayerManagerTest {  
    373398    @Test
    374399    public void testAddLayerChangeListenerFire() {
    375400        final ArrayList<Layer> fired = new ArrayList<>();
    376         AbstractTestLayer layer1 = new AbstractTestLayer();
    377         AbstractTestLayer layer2 = new AbstractTestLayer();
     401        TestLayer layer1 = new TestLayer();
     402        TestLayer layer2 = new TestLayer();
    378403        layerManager.addLayer(layer1);
    379404        layerManager.addLayer(layer2);
    380405        layerManager.addLayerChangeListener(new LayerChangeListener() {
    public class LayerManagerTest {  
    404429    public void testRemoveLayerChangeListener() {
    405430        CapturingLayerChangeListener l = new CapturingLayerChangeListener();
    406431        layerManager.addLayerChangeListener(l);
    407         layerManager.addLayer(new AbstractTestLayer());
     432        layerManager.addLayer(new TestLayer());
    408433        layerManager.removeLayerChangeListener(l);
    409         layerManager.addLayer(new AbstractTestLayer());
     434        layerManager.addLayer(new TestLayer());
    410435        // threw exception when fired twice.
    411436        assertNotNull(l.layerAdded);
    412437        assertNull(l.layerRemoved);
    public class LayerManagerTest {  
    428453    @Test
    429454    public void testRemoveLayerChangeListenerFire() {
    430455        final ArrayList<Layer> fired = new ArrayList<>();
    431         AbstractTestLayer layer1 = new AbstractTestLayer();
    432         AbstractTestLayer layer2 = new AbstractTestLayer();
     456        TestLayer layer1 = new TestLayer();
     457        TestLayer layer2 = new TestLayer();
    433458        layerManager.addLayer(layer1);
    434459        layerManager.addLayer(layer2);
    435460        LayerChangeListener listener = new LayerChangeListener() {
  • test/unit/org/openstreetmap/josm/gui/layer/MainLayerManagerTest.java

    diff --git a/test/unit/org/openstreetmap/josm/gui/layer/MainLayerManagerTest.java b/test/unit/org/openstreetmap/josm/gui/layer/MainLayerManagerTest.java
    index afc1c2e..c1ee42f 100644
    a b public class MainLayerManagerTest extends LayerManagerTest {  
    6767
    6868    @Test
    6969    public void testAddLayerSetsActiveLayer() {
    70         AbstractTestLayer layer1 = new AbstractTestLayer();
     70        TestLayer layer1 = new TestLayer();
    7171        AbstractTestOsmLayer layer2 = new AbstractTestOsmLayer();
    72         AbstractTestLayer layer3 = new AbstractTestLayer();
     72        TestLayer layer3 = new TestLayer();
    7373        assertNull(layerManagerWithActive.getActiveLayer());
    7474        assertNull(layerManagerWithActive.getEditLayer());
    7575        layerManagerWithActive.addLayer(layer1);
    public class MainLayerManagerTest extends LayerManagerTest {  
    8585
    8686    @Test
    8787    public void testRemoveLayerUnsetsActiveLayer() {
    88         AbstractTestLayer layer1 = new AbstractTestLayer();
     88        TestLayer layer1 = new TestLayer();
    8989        AbstractTestOsmLayer layer2 = new AbstractTestOsmLayer();
    90         AbstractTestLayer layer3 = new AbstractTestLayer();
     90        TestLayer layer3 = new TestLayer();
    9191        AbstractTestOsmLayer layer4 = new AbstractTestOsmLayer();
    9292        layerManagerWithActive.addLayer(layer1);
    9393        layerManagerWithActive.addLayer(layer2);
    public class MainLayerManagerTest extends LayerManagerTest {  
    115115     */
    116116    @Test
    117117    public void testAddActiveLayerChangeListener() {
    118         AbstractTestLayer layer1 = new AbstractTestLayer();
     118        TestLayer layer1 = new TestLayer();
    119119        AbstractTestOsmLayer layer2 = new AbstractTestOsmLayer();
    120120        layerManagerWithActive.addLayer(layer1);
    121121        layerManagerWithActive.addLayer(layer2);
    public class MainLayerManagerTest extends LayerManagerTest {  
    153153     */
    154154    @Test
    155155    public void testRemoveActiveLayerChangeListener() {
    156         AbstractTestLayer layer1 = new AbstractTestLayer();
     156        TestLayer layer1 = new TestLayer();
    157157        AbstractTestOsmLayer layer2 = new AbstractTestOsmLayer();
    158158        layerManagerWithActive.addLayer(layer1);
    159159        layerManagerWithActive.addLayer(layer2);
    public class MainLayerManagerTest extends LayerManagerTest {  
    181181     */
    182182    @Test
    183183    public void testSetGetActiveLayer() {
    184         AbstractTestLayer layer1 = new AbstractTestLayer();
    185         AbstractTestLayer layer2 = new AbstractTestLayer();
     184        TestLayer layer1 = new TestLayer();
     185        TestLayer layer2 = new TestLayer();
    186186        layerManagerWithActive.addLayer(layer1);
    187187        layerManagerWithActive.addLayer(layer2);
    188188
    public class MainLayerManagerTest extends LayerManagerTest {  
    199199    @Test
    200200    public void testGetEditDataSet() {
    201201        assertNull(layerManagerWithActive.getEditDataSet());
    202         AbstractTestLayer layer0 = new AbstractTestLayer();
     202        TestLayer layer0 = new TestLayer();
    203203        layerManagerWithActive.addLayer(layer0);
    204204        assertNull(layerManagerWithActive.getEditDataSet());
    205205
    public class MainLayerManagerTest extends LayerManagerTest {  
    222222    public void testGetVisibleLayersInZOrder() {
    223223        AbstractTestOsmLayer layer1 = new AbstractTestOsmLayer();
    224224        AbstractTestOsmLayer layer2 = new AbstractTestOsmLayer();
    225         AbstractTestLayer layer3 = new AbstractTestLayer();
     225        TestLayer layer3 = new TestLayer();
    226226        layer3.setVisible(false);
    227227        AbstractTestOsmLayer layer4 = new AbstractTestOsmLayer();
    228         AbstractTestLayer layer5 = new AbstractTestLayer();
     228        TestLayer layer5 = new TestLayer();
    229229        AbstractTestOsmLayer layer6 = new AbstractTestOsmLayer();
    230230        AbstractTestOsmLayer layer7 = new AbstractTestOsmLayer();
    231231        layerManagerWithActive.addLayer(layer1);
  • test/unit/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayerTest.java

    diff --git a/test/unit/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayerTest.java b/test/unit/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayerTest.java
    index a893981..eb90cac 100644
    a b import java.io.InputStream;  
    99import java.util.Collections;
    1010import java.util.List;
    1111
    12 import org.junit.BeforeClass;
     12import org.junit.Rule;
    1313import org.junit.Test;
    14 import org.openstreetmap.josm.JOSMFixture;
    1514import org.openstreetmap.josm.Main;
    1615import org.openstreetmap.josm.TestUtils;
    1716import org.openstreetmap.josm.gui.layer.GpxLayer;
    1817import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer.Loader;
    1918import org.openstreetmap.josm.io.GpxReader;
     19import org.openstreetmap.josm.testutils.JOSMTestRules;
     20
     21import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2022
    2123/**
    2224 * Unit tests of {@link GeoImageLayer} class.
    2325 */
    2426public class GeoImageLayerTest {
    25 
    2627    /**
    27      * Setup test.
     28     * We need prefs for this.
    2829     */
    29     @BeforeClass
    30     public static void setUpBeforeClass() {
    31         JOSMFixture.createUnitTestFixture().init(true);
    32     }
     30    @Rule
     31    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     32    public JOSMTestRules test = new JOSMTestRules().preferences();
     33
    3334
    3435    /**
    3536     * Unit test of {@link Loader} class.
    public class GeoImageLayerTest {  
    4142            GpxReader reader = new GpxReader(in);
    4243            assertTrue(reader.parse(true));
    4344            GpxLayer gpxLayer = new GpxLayer(reader.getGpxData());
    44             try {
    45                 Main.getLayerManager().addLayer(gpxLayer);
    46                 assertEquals(1, Main.getLayerManager().getLayers().size());
    47                 new Loader(
    48                         Collections.singleton(new File(TestUtils.getRegressionDataFile(12255, "G0016941.JPG"))),
    49                         gpxLayer).run();
    50                 assertEquals(2, Main.getLayerManager().getLayers().size());
    51                 GeoImageLayer layer = Main.getLayerManager().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.getLayerManager().removeLayer(layer);
    61                 }
    62             } finally {
    63                 // Ensure we clean the place before leaving, even if test fails.
    64                 Main.getLayerManager().removeLayer(gpxLayer);
    65             }
     45            Main.getLayerManager().addLayer(gpxLayer);
     46            assertEquals(1, Main.getLayerManager().getLayers().size());
     47            new Loader(
     48                    Collections.singleton(new File(TestUtils.getRegressionDataFile(12255, "G0016941.JPG"))),
     49                    gpxLayer).run();
     50            assertEquals(2, Main.getLayerManager().getLayers().size());
     51            GeoImageLayer layer = Main.getLayerManager().getLayersOfType(GeoImageLayer.class).iterator().next();
     52            assertEquals(gpxLayer, layer.getGpxLayer());
     53            List<ImageEntry> images = layer.getImages();
     54            assertEquals(1, images.size());
     55            assertEquals("<html>1 image loaded. 0 were found to be GPS tagged.</html>", layer.getInfoComponent());
     56            assertEquals("<html>1 image loaded. 0 were found to be GPS tagged.</html>", layer.getToolTipText());
    6657        }
    6758    }
    6859}
  • test/unit/org/openstreetmap/josm/io/NmeaReaderTest.java

    diff --git a/test/unit/org/openstreetmap/josm/io/NmeaReaderTest.java b/test/unit/org/openstreetmap/josm/io/NmeaReaderTest.java
    index ed3f060..88f6ad7 100644
    a b import java.io.FileInputStream;  
    77import java.text.SimpleDateFormat;
    88import java.util.ArrayList;
    99import java.util.List;
     10import java.util.TimeZone;
    1011
    1112import org.junit.Test;
    1213import org.openstreetmap.josm.data.coor.LatLon;
    public class NmeaReaderTest {  
    3940        assertEquals(30, in.getNumberOfCoordinates());
    4041        assertEquals(0, in.getParserMalformed());
    4142
     43        TimeZone.setDefault(TimeZone.getTimeZone("Europe/Berlin"));
    4244        final List<WayPoint> wayPoints = new ArrayList<>(in.data.tracks.iterator().next().getSegments().iterator().next().getWayPoints());
    4345        assertEquals("2016-01-25T04:05:09.200Z", wayPoints.get(0).get(GpxConstants.PT_TIME));
    4446        assertEquals("2016-01-25T04:05:09.400Z", wayPoints.get(1).get(GpxConstants.PT_TIME));
  • test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java

    diff --git a/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java b/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java
    index 91b7082..a6033d0 100644
    a b package org.openstreetmap.josm.testutils;  
    33
    44import java.io.File;
    55import java.io.IOException;
     6import java.util.TimeZone;
    67
    78import org.junit.rules.DisableOnDebug;
    89import org.junit.rules.TemporaryFolder;
    public class JOSMTestRules implements TestRule {  
    162163
    163164        // Tests are running headless by default.
    164165        System.setProperty("java.awt.headless", "true");
     166        // All tests use the same timezone.
     167        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
     168        // Set log level to info
     169        Main.logLevel = 3;
    165170
    166171        // Set up i18n
    167172        if (i18n != null) {